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

Method removeEntry

src/generic/key_value_filesystem.ts:1214–1262  ·  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, cb: BFSOneArgCallback)

Source from the content-addressed store, hash-verified

1212 * @todo Update mtime.
1213 */
1214 private removeEntry(p: string, isDir: boolean, cb: BFSOneArgCallback): void {
1215 const tx = this.store.beginTransaction('readwrite'),
1216 parent: string = path.dirname(p), fileName: string = path.basename(p);
1217 // Step 1: Get parent directory's node and directory listing.
1218 this.findINodeAndDirListing(tx, parent, (e?: ApiError | null, parentNode?: Inode, parentListing?: {[name: string]: string}): void => {
1219 if (noErrorTx(e, tx, cb)) {
1220 if (!parentListing![fileName]) {
1221 tx.abort(() => {
1222 cb(ApiError.ENOENT(p));
1223 });
1224 } else {
1225 // Remove from directory listing of parent.
1226 const fileNodeId = parentListing![fileName];
1227 delete parentListing![fileName];
1228 // Step 2: Get file inode.
1229 this.getINode(tx, p, fileNodeId, (e: ApiError, fileNode?: Inode): void => {
1230 if (noErrorTx(e, tx, cb)) {
1231 if (!isDir && fileNode!.isDirectory()) {
1232 tx.abort(() => {
1233 cb(ApiError.EISDIR(p));
1234 });
1235 } else if (isDir && !fileNode!.isDirectory()) {
1236 tx.abort(() => {
1237 cb(ApiError.ENOTDIR(p));
1238 });
1239 } else {
1240 // Step 3: Delete data.
1241 tx.del(fileNode!.id, (e?: ApiError): void => {
1242 if (noErrorTx(e, tx, cb)) {
1243 // Step 4: Delete node.
1244 tx.del(fileNodeId, (e?: ApiError): void => {
1245 if (noErrorTx(e, tx, cb)) {
1246 // Step 5: Update directory listing.
1247 tx.put(parentNode!.id, Buffer.from(JSON.stringify(parentListing)), true, (e: ApiError): void => {
1248 if (noErrorTx(e, tx, cb)) {
1249 tx.commit(cb);
1250 }
1251 });
1252 }
1253 });
1254 }
1255 });
1256 }
1257 }
1258 });
1259 }
1260 }
1261 });
1262 }
1263}

Callers 2

unlinkMethod · 0.95
rmdirMethod · 0.95

Calls 13

getINodeMethod · 0.95
noErrorTxFunction · 0.85
cbFunction · 0.85
ENOENTMethod · 0.80
EISDIRMethod · 0.80
ENOTDIRMethod · 0.80
beginTransactionMethod · 0.65
abortMethod · 0.65
delMethod · 0.65
putMethod · 0.65
commitMethod · 0.65

Tested by

no test coverage detected