From def28851a5f1950a001b130c0a7960ee63461b27 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Sun, 31 Oct 2021 17:34:01 +0100 Subject: [PATCH] Improve handling of temporary file changes in watch mode --- lib/snapshot-manager.js | 17 ++++++++++------- lib/watcher.js | 15 ++++++++++++++- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/snapshot-manager.js b/lib/snapshot-manager.js index e7a20acdf..e7b907927 100644 --- a/lib/snapshot-manager.js +++ b/lib/snapshot-manager.js @@ -355,10 +355,10 @@ class Manager { const {dir, relFile, snapFile, snapPath, reportPath} = this; if (this.updating && this.newBlocksByTitle.size === 0) { - return [ - ...cleanFile(snapPath), - ...cleanFile(reportPath), - ]; + return { + changedFiles: [cleanFile(snapPath), cleanFile(reportPath)].flat(), + temporaryFiles: [], + }; } if (!this.hasChanges) { @@ -376,11 +376,14 @@ class Manager { fs.mkdirSync(dir, {recursive: true}); - const paths = [snapPath, reportPath]; - const tmpfileCreated = tmpfile => paths.push(tmpfile); + const temporaryFiles = []; + const tmpfileCreated = file => temporaryFiles.push(file); writeFileAtomic.sync(snapPath, buffer, {tmpfileCreated}); writeFileAtomic.sync(reportPath, reportBuffer, {tmpfileCreated}); - return paths; + return { + changedFiles: [snapPath, reportPath], + temporaryFiles, + }; } } diff --git a/lib/watcher.js b/lib/watcher.js index 0780dda22..d730103fd 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -164,6 +164,7 @@ export default class Watcher { this.testDependencies = []; this.trackTestDependencies(api); + this.temporaryFiles = new Set(); this.touchedFiles = new Set(); this.trackTouchedFiles(api); @@ -245,9 +246,13 @@ export default class Watcher { return; } - for (const file of evt.files) { + for (const file of evt.files.changedFiles) { this.touchedFiles.add(file); } + + for (const file of evt.files.temporaryFiles) { + this.temporaryFiles.add(file); + } }); }); } @@ -393,6 +398,14 @@ export default class Watcher { return false; } + // Unlike touched files, temporary files are never cleared. We may see + // adds and unlinks detected separately, so we track the temporary files + // as long as AVA is running. + if (this.temporaryFiles.has(path)) { + debug('Ignoring known temporary file %s', path); + return false; + } + return true; });