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

Function resolveFileInode

packages/dofs/src/fs/writeFile.ts:391–410  ·  view source on GitHub ↗
(db: Database, path: string)

Source from the content-addressed store, hash-verified

389}
390
391function resolveFileInode(db: Database, path: string): { inode: number; mode: number } {
392 const { path: canonical } = canonicalizePath(path);
393 const node = db.one<{ inode: number; type: "file" | "dir"; mode: number }>(
394 `SELECT n.inode AS inode, n.type AS type, n.mode AS mode
395 FROM vfs_nodes n
396 WHERE n.inode = (
397 SELECT child_inode
398 FROM vfs_dirents
399 WHERE parent_inode = ? AND name = ?
400 )`,
401 ...parentAndNameForResolvedPath(db, path),
402 );
403 if (node === undefined) {
404 throw createWorkspaceError("ENOENT", `no such file: ${canonical}`, canonical);
405 }
406 if (node.type !== "file") {
407 throw createWorkspaceError("EISDIR", `path is a directory: ${canonical}`, canonical);
408 }
409 return { inode: node.inode, mode: node.mode };
410}
411
412function parentAndNameForResolvedPath(db: Database, path: string): [number, string] {
413 const { parts, path: canonical } = canonicalizePath(path);

Callers 4

openWriteBufferSyncFunction · 0.85
releaseWriteBufferSyncFunction · 0.85
writeRangeSyncFunction · 0.85
truncateFileSyncFunction · 0.85

Calls 4

canonicalizePathFunction · 0.85
oneMethod · 0.80
createWorkspaceErrorFunction · 0.50

Tested by

no test coverage detected