mecano
Version:
Common functions for system deployment.
61 lines (57 loc) • 1.5 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var each, ssh2fs;
module.exports = function(options, callback) {
var modified;
modified = false;
if (options.target == null) {
return callback(Error("Missing target: " + options.target));
}
if (!Array.isArray(options.target)) {
options.target = [options.target];
}
if (options.interval == null) {
options.interval = 2000;
}
options.log({
message: "Entering wait for file",
level: 'DEBUG',
module: 'mecano/wait/exist'
});
modified = false;
return each(options.target).call((function(_this) {
return function(target, next) {
var count, run;
count = 0;
run = function() {
count++;
options.log({
message: "Attempt #" + count,
level: 'INFO',
module: 'mecano/wait/exist'
});
return ssh2fs.stat(options.ssh, target, function(err, stat) {
if (err && err.code !== 'ENOENT') {
return next(err);
}
if (err) {
return setTimeout(run, options.interval);
}
options.log({
message: "Finish wait for file",
level: 'INFO',
module: 'mecano/wait/exist'
});
if (count > 1) {
modified = true;
}
return next();
});
};
return run();
};
})(this)).then(function(err) {
return callback(err, modified);
});
};
each = require('each');
ssh2fs = require('ssh2-fs');