Skip to content
This repository was archived by the owner on Oct 27, 2020. It is now read-only.

Commit f24f723

Browse files
sokramichael-ciniawsky
authored andcommitted
fix(index): check for inaccurate filesystem (mtime)
1 parent 97b1cff commit f24f723

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,29 @@ function loader(...args) {
2323
const { data } = this;
2424
const dependencies = this.getDependencies().concat(this.loaders.map(l => l.path));
2525
const contextDependencies = this.getContextDependencies();
26+
27+
// Should the file get cached?
28+
let cache = true;
29+
2630
const toDepDetails = (dep, mapCallback) => {
2731
fs.stat(dep, (err, stats) => {
2832
if (err) {
2933
mapCallback(err);
3034
return;
3135
}
36+
37+
const mtime = stats.mtime.getTime();
38+
39+
if (mtime / 1000 >= Math.floor(data.startTime / 1000)) {
40+
// Don't trust mtime.
41+
// File was changed while compiling
42+
// or it could be an inaccurate filesystem.
43+
cache = false;
44+
}
45+
3246
mapCallback(null, {
3347
path: dep,
34-
mtime: stats.mtime.getTime(),
48+
mtime,
3549
});
3650
});
3751
};
@@ -44,6 +58,10 @@ function loader(...args) {
4458
callback(null, ...args);
4559
return;
4660
}
61+
if (!cache) {
62+
callback(null, ...args);
63+
return;
64+
}
4765
const [deps, contextDeps] = taskResults;
4866
writeFn(data.cacheKey, {
4967
remainingRequest: data.remainingRequest,
@@ -89,6 +107,7 @@ function pitch(remainingRequest, prevRequest, dataInput) {
89107
});
90108
}, (err) => {
91109
if (err) {
110+
data.startTime = Date.now();
92111
callback();
93112
return;
94113
}

0 commit comments

Comments
 (0)