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

Method removeEntry

src/generic/key_value_filesystem.ts:588–624  ·  view source on GitHub ↗

* Remove all traces of the given path from the file system. * @param p The path to remove from the file system. * @param isDir Does the path belong to a directory, or a file? * @todo Update mtime.

(p: string, isDir: boolean)

Source from the content-addressed store, hash-verified

586 * @todo Update mtime.
587 */
588 private removeEntry(p: string, isDir: boolean): void {
589 const tx = this.store.beginTransaction('readwrite'),
590 parent: string = path.dirname(p),
591 parentNode = this.findINode(tx, parent),
592 parentListing = this.getDirListing(tx, parent, parentNode),
593 fileName: string = path.basename(p);
594
595 if (!parentListing[fileName]) {
596 throw ApiError.ENOENT(p);
597 }
598
599 // Remove from directory listing of parent.
600 const fileNodeId = parentListing[fileName];
601 delete parentListing[fileName];
602
603 // Get file inode.
604 const fileNode = this.getINode(tx, p, fileNodeId);
605 if (!isDir && fileNode.isDirectory()) {
606 throw ApiError.EISDIR(p);
607 } else if (isDir && !fileNode.isDirectory()) {
608 throw ApiError.ENOTDIR(p);
609 }
610
611 try {
612 // Delete data.
613 tx.del(fileNode.id);
614 // Delete node.
615 tx.del(fileNodeId);
616 // Update directory listing.
617 tx.put(parentNode.id, Buffer.from(JSON.stringify(parentListing)), true);
618 } catch (e) {
619 tx.abort();
620 throw e;
621 }
622 // Success.
623 tx.commit();
624 }
625}
626
627/**

Callers 2

unlinkSyncMethod · 0.95
rmdirSyncMethod · 0.95

Calls 12

findINodeMethod · 0.95
getDirListingMethod · 0.95
getINodeMethod · 0.95
ENOENTMethod · 0.80
EISDIRMethod · 0.80
ENOTDIRMethod · 0.80
beginTransactionMethod · 0.65
delMethod · 0.65
putMethod · 0.65
abortMethod · 0.65
commitMethod · 0.65
isDirectoryMethod · 0.45

Tested by

no test coverage detected