MCPcopy Create free account
hub / github.com/VemtoOrg/vemto2 / removeFile

Function removeFile

src/main/RenderableFileQueueHandler.ts:55–83  ·  view source on GitHub ↗
(file: RenderableFile)

Source from the content-addressed store, hash-verified

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()

Callers 1

generateOrRemoveFilesFunction · 0.85

Calls 7

projectPathIsInvalidFunction · 0.85
setFileStatusFunction · 0.85
getRelativeFilePathMethod · 0.80
joinMethod · 0.80
deleteFileMethod · 0.80
logMethod · 0.45
getPathMethod · 0.45

Tested by

no test coverage detected