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

Function openWriteBufferForCreateSync

packages/dofs/src/fs/writeFile.ts:552–583  ·  view source on GitHub ↗
(
  db: Database,
  path: string,
  options: WriteFileOptions,
  now: () => number,
)

Source from the content-addressed store, hash-verified

550// Throws EEXIST if a path already resolves to a live node or to
551// another pending buffer.
552export function openWriteBufferForCreateSync(
553 db: Database,
554 path: string,
555 options: WriteFileOptions,
556 now: () => number,
557): void {
558 const { path: canonical } = canonicalizePath(path);
559 assertNotReadOnly(db, canonical);
560 if (getPendingWriteBufferByPath(db, canonical) !== undefined) {
561 throw createWorkspaceError("EEXIST", `path exists: ${canonical}`, canonical);
562 }
563 const [parentInode, leafName] = parentAndNameForResolvedPath(db, path);
564 const existing = db.one<{ child_inode: number }>(
565 "SELECT child_inode FROM vfs_dirents WHERE parent_inode = ? AND name = ?",
566 parentInode,
567 leafName,
568 );
569 if (existing !== undefined) {
570 throw createWorkspaceError("EEXIST", `path exists: ${canonical}`, canonical);
571 }
572 const mode = (options.mode ?? 0o644) & 0o7777;
573 const mtime = now();
574 const pendingInode = allocatePendingInode(db);
575 setWriteBuffer(db, pendingInode, {
576 buf: new Uint8Array(0),
577 size: 0,
578 dirty: true,
579 openCount: 1,
580 mode,
581 pending: { parentInode, leafName, canonicalPath: canonical, pendingInode, mtime },
582 });
583}
584
585// Release one open of an inode's write buffer. When the open count
586// reaches zero, commit the buffered bytes to chunk rows and drop

Callers 1

Calls 8

canonicalizePathFunction · 0.85
assertNotReadOnlyFunction · 0.85
allocatePendingInodeFunction · 0.85
setWriteBufferFunction · 0.85
oneMethod · 0.80
createWorkspaceErrorFunction · 0.50

Tested by

no test coverage detected