* 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)
| 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 | /** |
no test coverage detected