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>
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
// Flags: --disable-warning=ExperimentalWarning
|
|
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const vfs = require('node:vfs');
|
|
|
|
// Test that writeFileSync updates both mtime and ctime
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.writeFileSync('/file.txt', 'initial');
|
|
|
|
const stat1 = myVfs.statSync('/file.txt');
|
|
const oldCtime = stat1.ctimeMs;
|
|
|
|
myVfs.writeFileSync('/file.txt', 'updated');
|
|
const stat2 = myVfs.statSync('/file.txt');
|
|
assert.ok(stat2.mtimeMs >= oldCtime);
|
|
assert.ok(stat2.ctimeMs >= oldCtime);
|
|
// Ctime and mtime should be the same value (both set from same write)
|
|
assert.strictEqual(stat2.ctimeMs, stat2.mtimeMs);
|
|
}
|
|
|
|
// Test that writeSync via file handle updates ctime
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.writeFileSync('/file.txt', 'initial');
|
|
|
|
const fd = myVfs.openSync('/file.txt', 'r+');
|
|
const buf = Buffer.from('X');
|
|
myVfs.writeSync(fd, buf, 0, 1, 0);
|
|
myVfs.closeSync(fd);
|
|
|
|
const stat = myVfs.statSync('/file.txt');
|
|
assert.strictEqual(stat.ctimeMs, stat.mtimeMs);
|
|
}
|
|
|
|
// Test that truncateSync updates ctime
|
|
{
|
|
const myVfs = vfs.create();
|
|
myVfs.writeFileSync('/file.txt', 'some content');
|
|
|
|
const fd = myVfs.openSync('/file.txt', 'r+');
|
|
myVfs.ftruncateSync(fd, 0);
|
|
myVfs.closeSync(fd);
|
|
|
|
const stat = myVfs.statSync('/file.txt');
|
|
assert.strictEqual(stat.ctimeMs, stat.mtimeMs);
|
|
}
|