Skip to content

Commit

Permalink
Handle race condition when file deleted after directory scan.
Browse files Browse the repository at this point in the history
  • Loading branch information
eobrain committed May 30, 2020
1 parent db2558b commit c40dae9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/fs_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const externalRequire = require
const fs = externalRequire('fs')
const path = externalRequire('path')
const tmp = externalRequire('tmp')
// const {pp} = require('../../passprint')
// const { pp } = require('../../passprint')

/** @returns timestamp if it is a file, or zero if it does not exist or is a directory. */
const timestamp = path =>
Expand All @@ -19,13 +19,17 @@ const walkDir = (dir, callback) => {
return
}
const dirPath = path.join(dir, f)
if (fs.statSync(dirPath).isDirectory()) {
walkDir(dirPath, callback)
} else {
const childPath = path.join(dir, f)
if (!fs.statSync(childPath).isDirectory()) {
callback(childPath)
try {
if (fs.statSync(dirPath).isDirectory()) {
walkDir(dirPath, callback)
} else {
const childPath = path.join(dir, f)
if (!fs.statSync(childPath).isDirectory()) {
callback(childPath)
}
}
} catch (e) {
// Expected occasional race condition: f was deleted after readdir call
}
})
}
Expand Down

0 comments on commit c40dae9

Please sign in to comment.