( db: Database, path: string, inode: number, )
| 159 | } |
| 160 | |
| 161 | function 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 | |
| 187 | function applyDirectoryEntry(db: Database, entry: Extract<ChangeEntry, { kind: "dir" }>): void { |
| 188 | const mode = entry.mode & 0o7777; |
no test coverage detected