Skip to content

Commit aa6b728

Browse files
authored
fix: Node.js v24+ changed permission access error codes
1 parent a73034e commit aa6b728

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

lib/DirectoryWatcher.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const EXISTANCE_ONLY_TIME_ENTRY = Object.freeze({});
1515
let FS_ACCURACY = 2000;
1616

1717
const IS_OSX = require("os").platform() === "darwin";
18+
const IS_WIN = require("os").platform() === "win32";
19+
1820
const WATCHPACK_POLLING = process.env.WATCHPACK_POLLING;
1921
const FORCE_POLLING =
2022
`${+WATCHPACK_POLLING}` === WATCHPACK_POLLING
@@ -633,7 +635,9 @@ class DirectoryWatcher extends EventEmitter {
633635
err2.code === "ENOENT" ||
634636
err2.code === "EPERM" ||
635637
err2.code === "EACCES" ||
636-
err2.code === "EBUSY"
638+
err2.code === "EBUSY" ||
639+
// TODO https://github.com/libuv/libuv/pull/4566
640+
(err2.code === "EINVAL" && IS_WIN)
637641
) {
638642
this.setMissing(itemPath, initial, "scan (" + err2.code + ")");
639643
} else {

test/Assumption.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ const IS_WIN = require("os").platform() === "win32";
1515
const SUPPORTS_RECURSIVE_WATCHING = IS_OSX || IS_WIN;
1616

1717

18+
function getNodeVersion() {
19+
try {
20+
return parseInt(process.version.split('.')[0].replace('v', ''), 10)
21+
} catch (e) {
22+
return 0;
23+
}
24+
}
25+
26+
const IS_NODE_VERSION_GT_24 = getNodeVersion() >= 24;
27+
28+
1829
describe("Assumption", function() {
1930
this.timeout(10000);
2031
var watcherToClose = null;
@@ -341,6 +352,15 @@ describe("Assumption", function() {
341352
});
342353
}
343354

355+
if (IS_WIN) {
356+
it("should return EINVAL when lstat a directory on Windows", function(done) {
357+
fs.lstat('D:\\System Volume Information', (err) => {
358+
err.code.should.be.equal(IS_NODE_VERSION_GT_24 ? 'EINVAL' : 'EPERM');
359+
done();
360+
});
361+
});
362+
}
363+
344364
[100, 200, 300, 500, 700, 1000].reverse().forEach(function(delay) {
345365
it("should fire events not after start and " + delay + "ms delay", function(
346366
done

0 commit comments

Comments
 (0)