mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
fs: allow setting Stat date properties
PR-URL: https://github.com/nodejs/node/pull/52708 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Raz Luvaton <rluvaton@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
40ef9d541e
commit
1aab22e305
|
|
@ -461,12 +461,10 @@ const lazyDateFields = {
|
|||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
const value = dateFromMs(this.atimeMs);
|
||||
ObjectDefineProperty(this, 'atime', { __proto__: null, value });
|
||||
return this.atime;
|
||||
return this.atime = dateFromMs(this.atimeMs);
|
||||
},
|
||||
set(value) {
|
||||
this.atime = value;
|
||||
ObjectDefineProperty(this, 'atime', { __proto__: null, value, writable: true });
|
||||
},
|
||||
},
|
||||
mtime: {
|
||||
|
|
@ -474,12 +472,10 @@ const lazyDateFields = {
|
|||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
const value = dateFromMs(this.mtimeMs);
|
||||
ObjectDefineProperty(this, 'mtime', { __proto__: null, value });
|
||||
return this.mtime;
|
||||
return this.mtime = dateFromMs(this.mtimeMs);
|
||||
},
|
||||
set(value) {
|
||||
this.mtime = value;
|
||||
ObjectDefineProperty(this, 'mtime', { __proto__: null, value, writable: true });
|
||||
},
|
||||
},
|
||||
ctime: {
|
||||
|
|
@ -487,12 +483,10 @@ const lazyDateFields = {
|
|||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
const value = dateFromMs(this.ctimeMs);
|
||||
ObjectDefineProperty(this, 'ctime', { __proto__: null, value });
|
||||
return this.ctime;
|
||||
return this.ctime = dateFromMs(this.ctimeMs);
|
||||
},
|
||||
set(value) {
|
||||
this.ctime = value;
|
||||
ObjectDefineProperty(this, 'ctime', { __proto__: null, value, writable: true });
|
||||
},
|
||||
},
|
||||
birthtime: {
|
||||
|
|
@ -500,12 +494,10 @@ const lazyDateFields = {
|
|||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
const value = dateFromMs(this.birthtimeMs);
|
||||
ObjectDefineProperty(this, 'birthtime', { __proto__: null, value });
|
||||
return this.birthtime;
|
||||
return this.birthtime = dateFromMs(this.birthtimeMs);
|
||||
},
|
||||
set(value) {
|
||||
this.birthtime = value;
|
||||
ObjectDefineProperty(this, 'birthtime', { __proto__: null, value, writable: true });
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -212,3 +212,36 @@ if (!common.isWindows) {
|
|||
verifyStats(bigintStats, numStats, allowableDelta);
|
||||
await handle.close();
|
||||
})().then(common.mustCall());
|
||||
|
||||
{
|
||||
// These two tests have an equivalent in ./test-fs-stat.js
|
||||
|
||||
// BigIntStats Date properties can be set before reading them
|
||||
fs.stat(__filename, { bigint: true }, common.mustSucceed((s) => {
|
||||
s.atime = 2;
|
||||
s.mtime = 3;
|
||||
s.ctime = 4;
|
||||
s.birthtime = 5;
|
||||
|
||||
assert.strictEqual(s.atime, 2);
|
||||
assert.strictEqual(s.mtime, 3);
|
||||
assert.strictEqual(s.ctime, 4);
|
||||
assert.strictEqual(s.birthtime, 5);
|
||||
}));
|
||||
|
||||
// BigIntStats Date properties can be set after reading them
|
||||
fs.stat(__filename, { bigint: true }, common.mustSucceed((s) => {
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
s.atime, s.mtime, s.ctime, s.birthtime;
|
||||
|
||||
s.atime = 2;
|
||||
s.mtime = 3;
|
||||
s.ctime = 4;
|
||||
s.birthtime = 5;
|
||||
|
||||
assert.strictEqual(s.atime, 2);
|
||||
assert.strictEqual(s.mtime, 3);
|
||||
assert.strictEqual(s.ctime, 4);
|
||||
assert.strictEqual(s.birthtime, 5);
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,3 +179,36 @@ fs.lstat(__filename, undefined, common.mustCall());
|
|||
]
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
// These two tests have an equivalent in ./test-fs-stat-bigint.js
|
||||
|
||||
// Stats Date properties can be set before reading them
|
||||
fs.stat(__filename, common.mustSucceed((s) => {
|
||||
s.atime = 2;
|
||||
s.mtime = 3;
|
||||
s.ctime = 4;
|
||||
s.birthtime = 5;
|
||||
|
||||
assert.strictEqual(s.atime, 2);
|
||||
assert.strictEqual(s.mtime, 3);
|
||||
assert.strictEqual(s.ctime, 4);
|
||||
assert.strictEqual(s.birthtime, 5);
|
||||
}));
|
||||
|
||||
// Stats Date properties can be set after reading them
|
||||
fs.stat(__filename, common.mustSucceed((s) => {
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
s.atime, s.mtime, s.ctime, s.birthtime;
|
||||
|
||||
s.atime = 2;
|
||||
s.mtime = 3;
|
||||
s.ctime = 4;
|
||||
s.birthtime = 5;
|
||||
|
||||
assert.strictEqual(s.atime, 2);
|
||||
assert.strictEqual(s.mtime, 3);
|
||||
assert.strictEqual(s.ctime, 4);
|
||||
assert.strictEqual(s.birthtime, 5);
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user