Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/DirectoryWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ class DirectoryWatcher extends EventEmitter {
});
}

setDirectory(directoryPath, mtime, initial, type) {
setDirectory(directoryPath, birthtime, initial, type) {
if (this.checkIgnore(directoryPath)) return;
if (directoryPath === this.path) {
if (!initial) {
this.forEachWatcher(this.path, w =>
w.emit("change", directoryPath, mtime, type, initial)
w.emit("change", directoryPath, birthtime, type, initial)
);
}
} else {
Expand All @@ -258,14 +258,14 @@ class DirectoryWatcher extends EventEmitter {

let safeTime;
if (initial) {
safeTime = Math.min(now, mtime) + FS_ACCURACY;
safeTime = Math.min(now, birthtime) + FS_ACCURACY;
} else {
safeTime = now;
}

this.forEachWatcher(directoryPath, w => {
if (!initial || w.checkStartTime(safeTime, false)) {
w.emit("change", mtime, type);
w.emit("change", birthtime, type);
}
});
this.forEachWatcher(this.path, w => {
Expand Down Expand Up @@ -437,7 +437,7 @@ class DirectoryWatcher extends EventEmitter {
} else if (stats.isDirectory()) {
this.setDirectory(
filePath,
+stats.mtime || +stats.ctime || 1,
+stats.birthtime || 1,
false,
eventType
);
Expand Down Expand Up @@ -669,7 +669,7 @@ class DirectoryWatcher extends EventEmitter {
if (!initial || !this.directories.has(itemPath))
this.setDirectory(
itemPath,
+stats.mtime || +stats.ctime || 1,
+stats.birthtime || 1,
initial,
"scan (dir)"
);
Expand Down
26 changes: 26 additions & 0 deletions test/Watchpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,32 @@ describe("Watchpack", function() {
});
});

it("should not report changes to a folder watched as file when items are added", function(done) {
var w = new Watchpack({
aggregateTimeout: 100
});
w.on("aggregated", () => {
done(new Error("should not fire"));
});
testHelper.dir("dir");
testHelper.file("dir/a");
testHelper.tick(1000, () => {
testHelper.file("dir/b");
w.watch({
files: [path.join(fixtures, "dir")],
startTime: Date.now()
});
testHelper.tick(1000, () => {
testHelper.file("dir/c");
testHelper.tick(1000, () => {
// no event fired
w.close();
done();
});
});
});
});

it("should report removal of file and directory if it is missing in initial scan", function(done) {
var w = new Watchpack({
aggregateTimeout: 1000
Expand Down