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

Commit

Permalink
fix(index): check for inaccurate filesystem (mtime)
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra authored and michael-ciniawsky committed Nov 15, 2017
1 parent 97b1cff commit f24f723
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,29 @@ function loader(...args) {
const { data } = this;
const dependencies = this.getDependencies().concat(this.loaders.map(l => l.path));
const contextDependencies = this.getContextDependencies();

// Should the file get cached?
let cache = true;

const toDepDetails = (dep, mapCallback) => {
fs.stat(dep, (err, stats) => {
if (err) {
mapCallback(err);
return;
}

const mtime = stats.mtime.getTime();

if (mtime / 1000 >= Math.floor(data.startTime / 1000)) {
// Don't trust mtime.
// File was changed while compiling
// or it could be an inaccurate filesystem.
cache = false;
}

mapCallback(null, {
path: dep,
mtime: stats.mtime.getTime(),
mtime,
});
});
};
Expand All @@ -44,6 +58,10 @@ function loader(...args) {
callback(null, ...args);
return;
}
if (!cache) {
callback(null, ...args);
return;
}
const [deps, contextDeps] = taskResults;
writeFn(data.cacheKey, {
remainingRequest: data.remainingRequest,
Expand Down Expand Up @@ -89,6 +107,7 @@ function pitch(remainingRequest, prevRequest, dataInput) {
});
}, (err) => {
if (err) {
data.startTime = Date.now();
callback();
return;
}
Expand Down

0 comments on commit f24f723

Please sign in to comment.