Permalink
Browse files

forever.stat append flag

  • Loading branch information...
kpdecker committed Feb 28, 2011
1 parent dca33d8 commit ab497f4516c04ee7d97f7f1ff5b3fb2e6b7233ed
Showing with 19 additions and 5 deletions.
  1. +19 −5 lib/forever.js
View
@@ -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);
});
});
};

0 comments on commit ab497f4

Please sign in to comment.