Skip to content

Commit

Permalink
Add callbacks to fs.close
Browse files Browse the repository at this point in the history
This also fixes an issue that using fd = 0 is not closed in case
Windows is used and a `EPERM` error is triggered.
  • Loading branch information
BridgeAR committed Feb 24, 2018
1 parent a95a1f8 commit df88ff0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions lib/fsevents-handler.js
Expand Up @@ -213,9 +213,15 @@ function(watchPath, realPath, transform, globFilter) {
}
function checkFd() {
fs.open(path, 'r', function(error, fd) {
if (fd) fs.close(fd);
error && error.code !== 'EACCES' ?
handleEvent('unlink') : addOrChange();
if (error) {
error.code !== 'EACCES' ?
handleEvent('unlink') : addOrChange();
} else {
fs.close(fd, function(err) {
err && err.code !== 'EACCES' ?
handleEvent('unlink') : addOrChange();
});
}
});
}
// correct for wrong events emitted
Expand Down
5 changes: 3 additions & 2 deletions lib/nodefs-handler.js
Expand Up @@ -90,8 +90,9 @@ function setFsWatchListener(path, fullPath, options, handlers) {
// Workaround for https://github.com/joyent/node/issues/4337
if (process.platform === 'win32' && error.code === 'EPERM') {
fs.open(path, 'r', function(err, fd) {
if (fd) fs.close(fd);
if (!err) broadcastErr(error);
if (!err) fs.close(fd, function(err) {
if (!err) broadcastErr(error);
});
});
} else {
broadcastErr(error);
Expand Down

0 comments on commit df88ff0

Please sign in to comment.