Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/internal/vfs/file_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ class VirtualFileSystem {

async lchmod(filePath, mode) {
const providerPath = toProviderPath(filePath);
provider.chmodSync(providerPath, mode);
provider.lchmodSync(providerPath, mode);
},

watch(filePath, options) {
Expand Down
7 changes: 7 additions & 0 deletions lib/internal/vfs/providers/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,13 @@ class MemoryProvider extends VirtualProvider {
entry.ctime = DateNow();
}

lchmodSync(path, mode) {
const entry = this.#getEntry(path, 'chmod', false);
// Preserve file type bits, update permission bits
entry.mode = (entry.mode & ~0o7777) | (mode & 0o7777);
entry.ctime = DateNow();
}

chownSync(path, uid, gid) {
const entry = this.#getEntry(path, 'chown', true);
if (uid >= 0) entry.uid = uid;
Expand Down
11 changes: 11 additions & 0 deletions lib/internal/vfs/providers/real.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const { VirtualProvider } = require('internal/vfs/provider');
const { VirtualFileHandle } = require('internal/vfs/file_handle');
const { getValidatedPath } = require('internal/fs/utils');
const { setOwnProperty } = require('internal/util');
const {
ERR_METHOD_NOT_IMPLEMENTED,
} = require('internal/errors').codes;
const {
createEACCES,
createEBADF,
Expand Down Expand Up @@ -517,6 +520,14 @@ class RealFSProvider extends VirtualProvider {
return fs.promises.access(realPath, mode);
}

lchmodSync(vfsPath, mode) {
if (fs.lchmodSync === undefined) {
throw new ERR_METHOD_NOT_IMPLEMENTED('lchmodSync');
}
const realPath = this.#resolvePath(vfsPath, false);
fs.lchmodSync(realPath, mode);
}

copyFileSync(srcVfsPath, destVfsPath, mode) {
const srcRealPath = this.#resolvePath(srcVfsPath);
const destRealPath = this.#resolvePath(destVfsPath);
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-vfs-fs-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ const vfs = require('node:vfs');
await fsp.utimes(p('src/hello.txt'), now, now);
await fsp.lutimes(p('src/hello.txt'), now, now);

await fsp.lchmod(p('src/plnk.txt'), 0o700);
assert.strictEqual(
(await fsp.lstat(p('src/hello.txt'))).mode & 0o777,
0o644,
);
assert.strictEqual(
(await fsp.lstat(p('src/plnk.txt'))).mode & 0o777,
0o700,
);

// FileHandle via fsp.open
const handle = await fsp.open(p('src/hello.txt'), 'r');
assert.strictEqual(await handle.readFile('utf8'), 'hello');
Expand Down
Loading