Skip to content

Commit 429f70c

Browse files
authored
Fix flakiness in test_futimens_rawfs (#22476)
This newly added test was flaky because noderawfs wasn't handling the value of -1 correctly here.
1 parent fcb5161 commit 429f70c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/closure-externs/node-externs.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,18 @@ Buffer.prototype.toString = function(encoding, start, end) {};
104104

105105
Worker.prototype.ref = function() {};
106106
Worker.prototype.unref = function() {};
107+
108+
/**
109+
* @type {number}
110+
*/
111+
fs.Stats.prototype.atimeMs;
112+
113+
/**
114+
* @type {number}
115+
*/
116+
fs.Stats.prototype.mtimeMs;
117+
118+
/**
119+
* @type {number}
120+
*/
121+
fs.Stats.prototype.ctimeMs;

src/library_noderawfs.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,17 @@ addToLibrary({
9191
var stream = FS.getStreamChecked(fd);
9292
fs.ftruncateSync(stream.nfd, len);
9393
},
94-
utime(path, atime, mtime) { fs.utimesSync(path, atime/1000, mtime/1000); },
94+
utime(path, atime, mtime) {
95+
// -1 here for atime or mtime means UTIME_OMIT was passed. Since node
96+
// doesn't support this concept we need to first find the existing
97+
// timestamps in order to preserve them.
98+
if (atime == -1 || mtime == -1) {
99+
var st = fs.statSync(path);
100+
if (atime == -1) atime = st.atimeMs;
101+
if (mtime == -1) mtime = st.mtimeMs;
102+
}
103+
fs.utimesSync(path, atime/1000, mtime/1000);
104+
},
95105
open(path, flags, mode) {
96106
if (typeof flags == "string") {
97107
flags = FS_modeStringToFlags(flags)

0 commit comments

Comments
 (0)