MCPcopy Index your code
hub / github.com/MigoXLab/coderio / deleteWorkspace

Method deleteWorkspace

src/utils/workspace.ts:55–96  ·  view source on GitHub ↗

* Delete all files and directories inside the workspace * @param workspace - The workspace structure * @param preserve - Optional list of relative paths (from workspace root) to preserve from deletion

(workspace: WorkspaceStructure, preserve: string[] = [])

Source from the content-addressed store, hash-verified

53 * @param preserve - Optional list of relative paths (from workspace root) to preserve from deletion
54 */
55 deleteWorkspace(workspace: WorkspaceStructure, preserve: string[] = []): void {
56 try {
57 if (!fs.existsSync(workspace.root)) return;
58
59 // Build set of normalized relative paths to preserve
60 const preserveFiles = new Set(preserve.map(p => path.normalize(p)));
61
62 // Collect ancestor directories of preserved files
63 const preserveDirs = new Set<string>();
64 for (const p of preserveFiles) {
65 let dir = path.dirname(p);
66 while (dir !== '.') {
67 preserveDirs.add(dir);
68 dir = path.dirname(dir);
69 }
70 }
71
72 const deleteRecursive = (dirPath: string, relativeTo: string = '') => {
73 const entries = fs.readdirSync(dirPath);
74 for (const entry of entries) {
75 const fullPath = path.join(dirPath, entry);
76 const relPath = relativeTo ? path.join(relativeTo, entry) : entry;
77
78 if (preserveFiles.has(relPath)) {
79 continue; // This file is preserved
80 }
81
82 if (preserveDirs.has(relPath)) {
83 // Directory contains preserved files, recurse into it
84 deleteRecursive(fullPath, relPath);
85 } else {
86 fs.rmSync(fullPath, { recursive: true, force: true });
87 }
88 }
89 };
90
91 deleteRecursive(workspace.root);
92 } catch (error) {
93 const errorMessage = error instanceof Error ? error.message : String(error);
94 logger.printWarnLog(`Failed to delete workspace: ${errorMessage}`);
95 }
96 }
97
98 /**
99 * Resolve the absolute path to the source code directory

Callers 2

design2codeFunction · 0.80
workspace.test.tsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected