(tree: TreeFolder, file: { pathname: string })
| 215 | * Remove the given file from the tree list. |
| 216 | */ |
| 217 | export const unlinkFile = (tree: TreeFolder, file: { pathname: string }): void => { |
| 218 | const { pathname } = file |
| 219 | const dirname = window.path.dirname(pathname) |
| 220 | const subDirectories = getSubdirectoriesFromRoot(tree.pathname, dirname) |
| 221 | |
| 222 | let currentFolder: TreeFolder = tree |
| 223 | let currentSubFolders: TreeFolder[] = tree.folders |
| 224 | for (const directoryName of subDirectories) { |
| 225 | const childFolder = currentSubFolders.find((f) => f.name === directoryName) |
| 226 | if (!childFolder) return |
| 227 | currentFolder = childFolder |
| 228 | currentSubFolders = childFolder.folders |
| 229 | } |
| 230 | |
| 231 | const index = currentFolder.files.findIndex((f) => f.pathname === pathname) |
| 232 | if (index !== -1) { |
| 233 | currentFolder.files.splice(index, 1) |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Remove the given directory from the tree list. |
no test coverage detected