(dirPath, projectRoot)
| 242 | } |
| 243 | |
| 244 | export function safeRemoveDirectory(dirPath, projectRoot) { |
| 245 | const validation = validateDeletionPath(dirPath, projectRoot) |
| 246 | |
| 247 | if (!validation.valid) { |
| 248 | log('ERROR', '目录删除失败 - 安全检查:') |
| 249 | log('ERROR', ` 原因: ${validation.error}`) |
| 250 | log('ERROR', ` 目标: ${dirPath}`) |
| 251 | log('ERROR', ` 项目根目录: ${projectRoot}`) |
| 252 | return false |
| 253 | } |
| 254 | |
| 255 | if (!fs.existsSync(dirPath)) { |
| 256 | log('INFO', `目录不存在: ${dirPath}`) |
| 257 | return true |
| 258 | } |
| 259 | |
| 260 | try { |
| 261 | fs.rmSync(dirPath, { recursive: true, force: true }) |
| 262 | log('SUCCESS', `目录已删除: ${dirPath}`) |
| 263 | return true |
| 264 | } catch (error) { |
| 265 | log('ERROR', `删除目录失败: ${dirPath}`) |
| 266 | log('ERROR', `错误: ${error.message}`) |
| 267 | return false |
| 268 | } |
| 269 | } |
no test coverage detected