(file: RenderableFile)
| 53 | } |
| 54 | |
| 55 | const removeFile = async (file: RenderableFile) => { |
| 56 | console.log("Will remove file: ", file.getRelativeFilePath()) |
| 57 | |
| 58 | try { |
| 59 | if (projectPathIsInvalid()) { |
| 60 | throw new Error("Project path is invalid or attempt to access a restricted directory") |
| 61 | } |
| 62 | |
| 63 | const resolvedProjectPath = path.resolve(project.getPath()), |
| 64 | filePath = path.resolve( |
| 65 | path.join(resolvedProjectPath, file.getRelativeFilePath()) |
| 66 | ) |
| 67 | |
| 68 | console.log("Removing file: ", filePath) |
| 69 | |
| 70 | // Ensure the file is within the project directory after resolving any symbolic links |
| 71 | if (!filePath.startsWith(resolvedProjectPath)) { |
| 72 | throw new Error("Attempt to access a file outside the project directory") |
| 73 | } |
| 74 | |
| 75 | FileSystem.deleteFile(filePath) |
| 76 | |
| 77 | setFileStatus(file, RenderableFileStatus.REMOVED) |
| 78 | } catch (error) { |
| 79 | console.log("Error removing file: ", file.getRelativeFilePath()) |
| 80 | |
| 81 | throw error |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | const projectPathIsInvalid = () => { |
| 86 | const projectPath = project.getPath() |
no test coverage detected