partially made some requested changes, but other changes still need to be discussed
This commit is contained in:
parent
8a8e4219d2
commit
1c7c00142e
|
@ -210,24 +210,25 @@ function FileSystem(options, callback) {
|
||||||
const statWatchers = new Map();
|
const statWatchers = new Map();
|
||||||
|
|
||||||
this.watchFile = function(filename, options, listener) {
|
this.watchFile = function(filename, options, listener) {
|
||||||
const prevStat, currStat;
|
let prevStat, currStat;
|
||||||
|
|
||||||
if (Path.isNull(filename)) {
|
if (Path.isNull(filename)) {
|
||||||
throw new Error('Path must be a string without null bytes.');
|
throw new Error('Path must be a string without null bytes.');
|
||||||
}
|
}
|
||||||
//Checks to see if there were options passed in and if not, the callback function will be set here
|
// Checks to see if there were options passed in and if not, the callback function will be set here
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
listener = options;
|
listener = options;
|
||||||
options = {};
|
options = {};
|
||||||
}
|
}
|
||||||
//default 5007ms interval, persistent is not used this project
|
// default 5007ms interval, persistent is not used this project
|
||||||
const interval = options.interval || 5007;
|
const interval = options.interval || 5007;
|
||||||
listener = listener || nop;
|
listener = listener || nop;
|
||||||
|
|
||||||
//Stores initial prev value to compare
|
// Stores initial prev value to compare
|
||||||
fs.stat(filename, function(err, stats) { prevStat = stats});
|
fs.stat(filename, function(err, stats) {
|
||||||
|
prevStat = stats;
|
||||||
|
|
||||||
//stores interval return values
|
// Stores interval return values
|
||||||
statWatchers.set(filename, value);
|
statWatchers.set(filename, value);
|
||||||
|
|
||||||
var value = setInterval(function() {
|
var value = setInterval(function() {
|
||||||
|
@ -235,17 +236,18 @@ function FileSystem(options, callback) {
|
||||||
if(err) {
|
if(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
//Store the current stat
|
// Store the current stat
|
||||||
currStat = stats;
|
currStat = stats;
|
||||||
if(prevStat != currStat) {
|
if(Object.toJSON(prevStat) !== Object.toJSON(currStat)) {
|
||||||
listener(prevStat, currStat);
|
listener(prevStat, currStat);
|
||||||
}
|
}
|
||||||
//Set a new prevStat based on previous
|
// Set a new prevStat based on previous
|
||||||
prevStat = currStat;
|
prevStat = currStat;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
interval
|
interval
|
||||||
);
|
);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Deal with various approaches to node ID creation
|
// Deal with various approaches to node ID creation
|
||||||
|
|
Loading…
Reference in New Issue