mecano
Version:
Common functions for system deployment.
69 lines (66 loc) • 1.65 kB
JavaScript
// Generated by CoffeeScript 1.11.1
var fs;
module.exports = function(options) {
options.log({
message: "Entering touch",
level: 'DEBUG',
module: 'mecano/lib/touch'
});
if (options.argument != null) {
options.target = options.argument;
}
if (!options.target) {
throw Error("Missing target: " + options.target);
}
this.call(function(_, callback) {
options.log({
message: "Check if target exists \"" + options.target + "\"",
level: 'DEBUG',
module: 'mecano/lib/touch'
});
return fs.exists(options.ssh, options.target, function(err, exists) {
if (!err && !exists) {
options.log({
message: "Destination does not exists",
level: 'INFO',
module: 'mecano/lib/touch'
});
}
return callback(err, !exists);
});
});
this.call({
unless: function() {
return this.status();
},
shy: true
}, function(_, callback) {
if (options.atime == null) {
options.atime = Date.now();
}
if (options.mtime == null) {
options.mtime = Date.now();
}
return fs.futimes(options.ssh, options.target, options.atime, options.mtime, function(err) {
if (!err) {
options.log({
message: "Access and modification times updated",
level: 'DEBUG',
module: 'mecano/lib/touch'
});
}
return callback(err);
});
});
return this.file({
content: '',
target: options.target,
"if": function() {
return this.status();
},
mode: options.mode,
uid: options.uid,
gid: options.gid
});
};
fs = require('ssh2-fs');