Skip to content

Commit

Permalink
forever.stat append flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kpdecker committed Feb 28, 2011
1 parent dca33d8 commit ab497f4
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,31 @@ forever.load();
//
// ### function stat (logFile, script, callback)
// #### @logFile {string} Path to the log file for this script
// #### @logAppend {boolean} Optional. True Prevent failure if the log file exists.
// #### @script {string} Path to the target script.
// #### @callback {function} Continuation to pass control back to
// Ensures that the logFile doesn't exist and that
// the target script does exist before executing callback.
//
forever.stat = function (logFile, script, callback) {
fs.stat(logFile, function (err, stats) {
if (!err) return callback(new Error('log file ' + logFile + ' exists.'));
fs.stat(script, function (err, stats) {
if (err) return callback(new Error('script ' + script + ' does not exist.'));
callback(null);
var logAppend,
realCallback = callback;
if (arguments.length === 4) {
logAppend = callback;
realCallback = arguments[3];
}

fs.stat(script, function (err, stats) {
if (err) return realCallback(new Error('script ' + script + ' does not exist.'));

if (logAppend) {
realCallback(null);
return;
}

fs.stat(logFile, function (err, stats) {
if (!err) return realCallback(new Error('log file ' + logFile + ' exists.'));
realCallback(null);
});
});
};
Expand Down

0 comments on commit ab497f4

Please sign in to comment.