mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
feat: rewrite remove function and add remove test
This commit is contained in:
1 parent
887bbf5c1b
commit
190a5abf3c
3 files changed
+58
-36
No files matched your search
@@ -52,6 +52,26 @@ export default class FileNode extends File {
|
||||
}
|
||||
}
|
||||
|
||||
removeChild(fileToRemove) {
|
||||
const file = new FileNode(fileToRemove)
|
||||
const parentPath = dirname(file.path)
|
||||
|
||||
if (parentPath === this.path) {
|
||||
// Direct child of this node
|
||||
this.children = this.children.filter((child) => child.path !== file.path)
|
||||
} else {
|
||||
// Recursively call removeChild on the correct child node
|
||||
const childNode = this.children.find((child) => child.contains(file))
|
||||
if (childNode) {
|
||||
childNode.removeChild(file)
|
||||
} else {
|
||||
throw new FileNotExistsError(
|
||||
`File ${file.path} does not exist in the tree: ${this.toString()}`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
merge(fileNode) {
|
||||
// Merge the children of the provided file node into this node
|
||||
// If a child already exists, merge the children of that child
|
||||
|
||||
Reference in new issue
Block a user