MCPcopy
hub / github.com/jvilk/BrowserFS / _findINode

Method _findINode

src/generic/key_value_filesystem.ts:451–474  ·  view source on GitHub ↗

* Helper function for findINode. * @param parent The parent directory of the file we are attempting to find. * @param filename The filename of the inode we are attempting to find, minus * the parent. * @return string The ID of the file's inode in the file system.

(tx: SyncKeyValueROTransaction, parent: string, filename: string)

Source from the content-addressed store, hash-verified

449 * @return string The ID of the file's inode in the file system.
450 */
451 private _findINode(tx: SyncKeyValueROTransaction, parent: string, filename: string): string {
452 const readDirectory = (inode: Inode): string => {
453 // Get the root's directory listing.
454 const dirList = this.getDirListing(tx, parent, inode);
455 // Get the file's ID.
456 if (dirList[filename]) {
457 return dirList[filename];
458 } else {
459 throw ApiError.ENOENT(path.resolve(parent, filename));
460 }
461 };
462 if (parent === '/') {
463 if (filename === '') {
464 // BASE CASE #1: Return the root's ID.
465 return ROOT_NODE_ID;
466 } else {
467 // BASE CASE #2: Find the item in the root ndoe.
468 return readDirectory(this.getINode(tx, parent, ROOT_NODE_ID));
469 }
470 } else {
471 return readDirectory(this.getINode(tx, parent + path.sep + filename,
472 this._findINode(tx, path.dirname(parent), path.basename(parent))));
473 }
474 }
475
476 /**
477 * Finds the Inode of the given path.

Callers 2

_syncSyncMethod · 0.95
findINodeMethod · 0.95

Calls 1

getINodeMethod · 0.95

Tested by

no test coverage detected