mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(ischanged) [{name, time}] -> {name: time }
This commit is contained in:
parent
d97b263ccf
commit
ab55aada7b
1 changed files with 17 additions and 33 deletions
|
|
@ -9,42 +9,26 @@
|
|||
Util = main.util,
|
||||
time = main.time,
|
||||
|
||||
CHANGESNAME = JSONDIR + 'changes',
|
||||
CHANGES_JSON = CHANGESNAME + '.json',
|
||||
CHANGES_NAME = JSONDIR + 'changes',
|
||||
CHANGES_JSON = CHANGES_NAME + '.json',
|
||||
|
||||
Times = main.require(CHANGES_NAME) || {};
|
||||
|
||||
Times = main.require(CHANGESNAME) || [];
|
||||
|
||||
exports.isFileChanged = function(name, callback) {
|
||||
var readTime, data,
|
||||
i, n = Times.length;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
data = Times[i];
|
||||
/* if founded row with file name - save hash */
|
||||
if (data.name === name) {
|
||||
readTime = data.time;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var readTime = Times[name];
|
||||
|
||||
time.get(name, function(error, fileTime) {
|
||||
var timeChanged, data;
|
||||
var json, timeChanged;
|
||||
|
||||
if (error)
|
||||
if (error) {
|
||||
Util.log(error);
|
||||
else if (readTime !== fileTime) {
|
||||
timeChanged = true;
|
||||
data = {
|
||||
name: name,
|
||||
time: fileTime
|
||||
};
|
||||
} else if (readTime !== fileTime) {
|
||||
timeChanged = true;
|
||||
Times[name] = fileTime;
|
||||
json = Util.stringifyJSON(Times);
|
||||
|
||||
if (i >= n)
|
||||
Times.push(data);
|
||||
else
|
||||
Times[i] = data;
|
||||
|
||||
writeFile(CHANGES_JSON, Util.stringifyJSON(Times));
|
||||
console.log(json);
|
||||
writeFile(CHANGES_JSON, json);
|
||||
}
|
||||
|
||||
Util.exec(callback, timeChanged);
|
||||
|
|
@ -58,10 +42,10 @@
|
|||
*/
|
||||
function writeFile(name, data) {
|
||||
fs.writeFile(name, data, function(error) {
|
||||
if (error)
|
||||
Util.log(error);
|
||||
else
|
||||
Util.log('file ' + path.basename(name) + ' written...');
|
||||
var baseName = path.basename(name),
|
||||
msg = 'file ' + baseName + ' written...';
|
||||
|
||||
Util.log(error || msg);
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue