Skip to content

Commit

Permalink
fs: make dirent.path writable
Browse files Browse the repository at this point in the history
PR-URL: nodejs#55547
Refs: nodejs#55538
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
aduh95 authored and Ceres6 committed Oct 30, 2024
1 parent 1eefb11 commit 7c11182
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6822,6 +6822,9 @@ deprecated:
- v20.12.0
- v18.20.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/55547
description: The property is no longer read-only.
- version: v23.0.0
pr-url: https://github.com/nodejs/node/pull/51050
description: Accessing this property emits a warning. It is now read-only.
Expand All @@ -6831,7 +6834,7 @@ changes:
* {string}
Alias for `dirent.parentPath`. Read-only.
Alias for `dirent.parentPath`.
### Class: `fs.FSWatcher`
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const {
once,
deprecate,
isWindows,
setOwnProperty,
} = require('internal/util');
const { toPathIfFileURL } = require('internal/url');
const {
Expand Down Expand Up @@ -214,6 +215,9 @@ ObjectDefineProperty(Dirent.prototype, 'path', {
get: deprecate(function() {
return this.parentPath;
}, 'dirent.path is deprecated in favor of dirent.parentPath', 'DEP0178'),
set(value) {
setOwnProperty(this, 'path', value);
},
configurable: true,
enumerable: false,
});
Expand Down
12 changes: 12 additions & 0 deletions test/parallel/test-fs-utils-get-dirents.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ const filename = 'foo';
},
));
}
{
// Reassigning `.path` property should not trigger a warning
const dirent = getDirent(
tmpdir.path,
filename,
UV_DIRENT_UNKNOWN,
);
assert.strictEqual(dirent.name, filename);
dirent.path = 'some other value';
assert.strictEqual(dirent.parentPath, tmpdir.path);
assert.strictEqual(dirent.path, 'some other value');
}
{
// string + Buffer
const filenameBuffer = Buffer.from(filename);
Expand Down

0 comments on commit 7c11182

Please sign in to comment.