-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathinvalidateModifiedFiles.js
More file actions
35 lines (32 loc) · 953 Bytes
/
invalidateModifiedFiles.js
File metadata and controls
35 lines (32 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var fs = require('fs');
var async = require('async');
var CONCURRENCY_LIMIT = 40;
function invalidateModifiedFiles(mtimes, files, invalidate, defer, done) {
var invalidated = [];
var deleted = [];
async.eachLimit(files, CONCURRENCY_LIMIT, function(file, fileDone) {
fs.stat(file, function(err, stat) {
if (err) {
// If the cache doesn't have any modification times it's a stream
if (!mtimes[file] && defer) {
if (defer(file)) {
invalidated.push(file)
}
} else {
deleted.push(file);
}
return fileDone();
}
var mtimeNew = stat.mtime.getTime();
if (!(mtimes[file] && mtimeNew && mtimeNew == mtimes[file])) {
invalidate(file);
invalidated.push(file);
}
mtimes[file] = mtimeNew;
fileDone();
});
}, function() {
done(null, invalidated, deleted);
});
}
module.exports = invalidateModifiedFiles;