diff --git a/test/common/tmpdir.js b/test/common/tmpdir.js index ca82e7bca0e7b3..c66756e21b47f2 100644 --- a/test/common/tmpdir.js +++ b/test/common/tmpdir.js @@ -108,18 +108,32 @@ function refresh(opts = {}) { firstRefresh = false; // Clean only when a test uses refresh. This allows for child processes to // use the tmpdir and only the parent will clean on exit. - process.on('exit', () => { - try { - // Change dit to avoid possible EBUSY - if (isMainThread) - process.chdir(testRoot); - rimrafSync(tmpPath, { spawn: false }); - } catch (e) { - console.error('Can\'t clean tmpdir:', tmpPath); - console.error('Files blocking:', fs.readdirSync(tmpPath)); - throw e; - } - }); + process.on('exit', onexit); + } +} + +function onexit() { + // Change directory to avoid possible EBUSY + if (isMainThread) + process.chdir(testRoot); + + try { + rimrafSync(tmpPath, { spawn: false }); + } catch (e) { + console.error('Can\'t clean tmpdir:', tmpPath); + + const files = fs.readdirSync(tmpPath); + console.error('Files blocking:', files); + + if (files.some((f) => f.startsWith('.nfs'))) { + // Warn about NFS "silly rename" + console.error('Note: ".nfs*" might be files that were open and ' + + 'unlinked but not closed.'); + console.error('See http://nfs.sourceforge.net/#faq_d2 for details.'); + } + + console.error(); + throw e; } }