Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: make dirent.path writable #55547

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 additions & 0 deletions test/parallel/test-fs-utils-get-dirents.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --expose-internals

Check failure on line 1 in test/parallel/test-fs-utils-get-dirents.js

View workflow job for this annotation

GitHub Actions / test-linux

--- stderr --- (node:146139) internal/test/binding: These APIs are for internal testing only. Do not use them. (Use `node --trace-warnings ...` to show where the warning was created) node:assert:90 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected + Buffer(46) [Uint8Array] [ + 47, + 104, + 111, + 109, + 101, + 47, + 114, + 117, + 110, + 110, + 101, + 114, + 47, + 119, + 111, + 114, + 107, + 47, + 110, + 111, + 100, + 101, + 47, + 110, + 111, + 100, + 101, + 47, + 116, + 101, + 115, + 116, + 47, + 46, + 116, + 109, + 112, + 46, + 49, + 48, + 50, + 50, + 47, + 102, + 111, + 111 + ] - '/home/runner/work/node/node/test/.tmp.1022' at /home/runner/work/node/node/test/parallel/test-fs-utils-get-dirents.js:92:14 at /home/runner/work/node/node/test/common/index.js:491:15 at node:internal/fs/utils:317:9 at FSReqCallback.oncomplete (node:fs:199:5) { generatedMessage: true, code: 'ERR_ASSERTION', actual: Buffer(46) [Uint8Array] [ 47, 104, 111, 109, 101, 47, 114, 117, 110, 110, 101, 114, 47, 119, 111, 114, 107, 47, 110, 111, 100, 101, 47, 110, 111, 100, 101, 47, 116, 101, 115, 116, 47, 46, 116, 109, 112, 46, 49, 48, 50, 50, 47, 102, 111, 111 ], expected: '/home/runner/work/node/node/test/.tmp.1022', operator: 'strictEqual' } Node.js v24.0.0-pre Command: out/Release/node --expose-internals --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./tools/github_reporter/index.js --test-reporter-destination=stdout /home/runner/work/node/node/test/parallel/test-fs-utils-get-dirents.js

Check failure on line 1 in test/parallel/test-fs-utils-get-dirents.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- (node:68824) internal/test/binding: These APIs are for internal testing only. Do not use them. (Use `node --trace-warnings ...` to show where the warning was created) node:assert:90 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected + Buffer(47) [Uint8Array] [ + 47, + 85, + 115, + 101, + 114, + 115, + 47, + 114, + 117, + 110, + 110, + 101, + 114, + 47, + 119, + 111, + 114, + 107, + 47, + 110, + 111, + 100, + 101, + 47, + 110, + 111, + 100, + 101, + 47, + 116, + 101, + 115, + 116, + 47, + 46, + 116, + 109, + 112, + 46, + 49, + 48, + 50, + 48, + 47, + 102, + 111, + 111 + ] - '/Users/runner/work/node/node/test/.tmp.1020' at /Users/runner/work/node/node/test/parallel/test-fs-utils-get-dirents.js:92:14 at /Users/runner/work/node/node/test/common/index.js:491:15 at node:internal/fs/utils:317:9 at FSReqCallback.oncomplete (node:fs:199:5) { generatedMessage: true, code: 'ERR_ASSERTION', actual: Buffer(47) [Uint8Array] [ 47, 85, 115, 101, 114, 115, 47, 114, 117, 110, 110, 101, 114, 47, 119, 111, 114, 107, 47, 110, 111, 100, 101, 47, 110, 111, 100, 101, 47, 116, 101, 115, 116, 47, 46, 116, 109, 112, 46, 49, 48, 50, 48, 47, 102, 111, 111 ], expected: '/Users/runner/work/node/node/test/.tmp.1020', operator: 'strictEqual' } Node.js v24.0.0-pre Command: out/Release/node --expose-internals --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./tools/github_reporter/index.js --test-reporter-destination=stdout /Users/runner/work/node/node/test/parallel/test-fs-utils-get-dirents.js
'use strict';

const common = require('../common');
Expand Down Expand Up @@ -78,6 +78,22 @@
},
));
}
{
// Reassigning `.path` property should not trigger a warning
const filenameBuffer = Buffer.from(filename);
getDirent(
tmpdir.path,
filenameBuffer,
UV_DIRENT_UNKNOWN,
common.mustCall((err, dirent) => {
assert.strictEqual(err, null);
assert.strictEqual(dirent.name, filenameBuffer);
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
Loading