Skip to content

Commit 85b3eb8

Browse files
committed
Keep an open file dirty until its flush succeeds.
1 parent 49c2c1b commit 85b3eb8

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎src/natives/io.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,14 @@ export function fileOf(t: JThread, fd: number): OpenFile {
193193
export function flush(t: JThread, f: OpenFile) {
194194
if (f.dirty && f.writable && f.path) {
195195
const data = f.data.slice(0, f.size);
196+
let ok = t.vm.fs.write(f.path, data);
196197
// an open file keeps its write access when the file's mode changes, as an fd does
197198
let mode = 0;
198-
if (!t.vm.fs.write(f.path, data) && t.vm.fs.chmod(f.path, (m) => (mode = m) | 0o200)) {
199-
t.vm.fs.write(f.path, data);
199+
if (!ok && t.vm.fs.chmod(f.path, (m) => (mode = m) | 0o200)) {
200+
ok = t.vm.fs.write(f.path, data);
200201
t.vm.fs.chmod(f.path, () => mode);
201202
}
202-
f.dirty = false;
203+
if (ok) f.dirty = false;
203204
}
204205
}
205206

0 commit comments

Comments
 (0)