MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / deleteOldUserDataDirIfSafe

Function deleteOldUserDataDirIfSafe

packages/node-runtime/src/data-dir-switch.ts:284–297  ·  view source on GitHub ↗
(
  dirPath: string,
  currentDir: string,
  removeDir?: (dir: string) => void
)

Source from the content-addressed store, hash-verified

282
283// 只删除确认仍是 ChatLab 用户数据目录的旧路径,避免误删用户选择的普通目录。
284export function deleteOldUserDataDirIfSafe(
285 dirPath: string,
286 currentDir: string,
287 removeDir?: (dir: string) => void
288): boolean {
289 if (path.resolve(dirPath) === path.resolve(currentDir)) return false
290 if (!isPathSafe(dirPath)) return false
291 if (!fs.existsSync(dirPath)) return false
292 if (!isExistingUserDataDir(dirPath)) return false
293
294 const remove = removeDir ?? ((dir: string) => fs.rmSync(dir, { recursive: true, force: true }))
295 remove(dirPath)
296 return true
297}
298
299function writePendingNodeDataDirMigration(systemDir: string, pending: PendingDataDirMigration): void {
300 const filePath = getPendingMigrationPath(systemDir)

Callers 1

markPendingDeleteDirFunction · 0.85

Calls 2

isExistingUserDataDirFunction · 0.85
isPathSafeFunction · 0.70

Tested by

no test coverage detected