mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Enable node:vfs by default. --no-experimental-vfs disables node:vfs exposure and --vfs-load. Assisted-by: pi Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/66318 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
34 lines
1001 B
JavaScript
34 lines
1001 B
JavaScript
// Flags: --disable-warning=ExperimentalWarning
|
|
'use strict';
|
|
|
|
// fs.fchmod, fs.fchown, fs.futimes, fs.fdatasync, and fs.fsync callbacks
|
|
// short-circuit through VFS as no-ops on virtual fds.
|
|
|
|
const common = require('../common');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const vfs = require('node:vfs');
|
|
|
|
const myVfs = vfs.create();
|
|
myVfs.mkdirSync('/src', { recursive: true });
|
|
myVfs.writeFileSync('/src/hello.txt', 'hello');
|
|
const mountPoint = myVfs.mount();
|
|
|
|
const fd = fs.openSync(path.join(mountPoint, 'src/hello.txt'), 'r+');
|
|
const uid = process.getuid?.() ?? 0;
|
|
const gid = process.getgid?.() ?? 0;
|
|
const now = new Date();
|
|
|
|
fs.fchmod(fd, 0o644, common.mustSucceed(() => {
|
|
fs.fchown(fd, uid, gid, common.mustSucceed(() => {
|
|
fs.futimes(fd, now, now, common.mustSucceed(() => {
|
|
fs.fdatasync(fd, common.mustSucceed(() => {
|
|
fs.fsync(fd, common.mustSucceed(() => {
|
|
fs.closeSync(fd);
|
|
myVfs.unmount();
|
|
}));
|
|
}));
|
|
}));
|
|
}));
|
|
}));
|