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

Function direntForPath

packages/dofs/src/sync/apply.ts:161–185  ·  view source on GitHub ↗
(
  db: Database,
  path: string,
  inode: number,
)

Source from the content-addressed store, hash-verified

159}
160
161function direntForPath(
162 db: Database,
163 path: string,
164 inode: number,
165): { parentInode: number; name: string } {
166 const { parts, path: canonical } = canonicalizePath(path);
167 if (parts.length === 0) {
168 throw new Error(`applyChanges: cannot structurally replace root ${canonical}`);
169 }
170 const name = parts[parts.length - 1];
171 const parentPath = parts.length === 1 ? "/" : `/${parts.slice(0, -1).join("/")}`;
172 const parent = resolveInode(db, parentPath, { followSymlinks: false });
173 if (parent === null || parent.type !== "dir") {
174 throw new Error(`applyChanges: parent missing for structural replacement ${canonical}`);
175 }
176 const child = db.scalar<number>(
177 "SELECT child_inode FROM vfs_dirents WHERE parent_inode = ? AND name = ?",
178 parent.inode,
179 name,
180 );
181 if (child !== inode) {
182 throw new Error(`applyChanges: dirent mismatch for structural replacement ${canonical}`);
183 }
184 return { parentInode: parent.inode, name };
185}
186
187function applyDirectoryEntry(db: Database, entry: Extract<ChangeEntry, { kind: "dir" }>): void {
188 const mode = entry.mode & 0o7777;

Callers 1

removeInodeTreeAtPathFunction · 0.85

Calls 3

canonicalizePathFunction · 0.85
resolveInodeFunction · 0.85
scalarMethod · 0.80

Tested by

no test coverage detected