MCPcopy Create free account
hub / github.com/cloudflare/computer / flushEntry

Function flushEntry

packages/computerd/src/fuse/driver.ts:365–388  ·  view source on GitHub ↗
(path: string)

Source from the content-addressed store, hash-verified

363 // Returns errno on failure so callers can surface it to the
364 // kernel; returns 0 on success or when there's nothing to do.
365 const flushEntry = (path: string): number => {
366 const entry = files.get(path);
367 if (entry === undefined || !entry.dirty) return 0;
368 try {
369 const data = entry.buf.subarray(0, entry.size);
370 // Pass the cached mode so writeFile doesn't fall back to its
371 // 0o644 default. Without this, a chmod between create/open and
372 // flush would land on the FUSE-side meta override but never
373 // reach the persisted VFS row, so RPC consumers would see the
374 // wrong mode.
375 const writeOpts = { mode: entry.mode & 0o7777 };
376 if (rangedWriteVfs.writeFileRangesSync !== undefined && entry.dirtyRanges.length > 0) {
377 rangedWriteVfs.writeFileRangesSync(toVfs(path), data, entry.dirtyRanges, writeOpts);
378 } else {
379 vfs.writeFileSync(toVfs(path), data, writeOpts);
380 }
381 entry.dirty = false;
382 entry.dirtyRanges = [];
383 entry.pendingCreate = false;
384 return 0;
385 } catch (error) {
386 return toErrno(error);
387 }
388 };
389
390 const truncatePath = (path: string, size: number, cb: StatusCallback): void => {
391 if (!exists(path)) {

Callers 4

releaseFunction · 0.85
flushFunction · 0.85
fsyncFunction · 0.85
linkFunction · 0.85

Calls 5

toVfsFunction · 0.85
toErrnoFunction · 0.85
writeFileSyncMethod · 0.80
getMethod · 0.65
writeFileRangesSyncMethod · 0.65

Tested by

no test coverage detected