MCPcopy Create free account
hub / github.com/chiihero/Microsoft-Rewards-Script / validateDeletionPath

Function validateDeletionPath

scripts/utils.js:215–242  ·  view source on GitHub ↗
(targetPath, projectRoot)

Source from the content-addressed store, hash-verified

213}
214
215export function validateDeletionPath(targetPath, projectRoot) {
216 const normalizedTarget = path.normalize(targetPath)
217 const normalizedRoot = path.normalize(projectRoot)
218
219 if (!normalizedTarget.startsWith(normalizedRoot)) {
220 return {
221 valid: false,
222 error: '路径超出项目根目录范围'
223 }
224 }
225
226 if (normalizedTarget === normalizedRoot) {
227 return {
228 valid: false,
229 error: '不能删除项目根目录'
230 }
231 }
232
233 const pathSegments = normalizedTarget.split(path.sep)
234 if (pathSegments.length < 3) {
235 return {
236 valid: false,
237 error: '路径层级太浅 (安全检查失败)'
238 }
239 }
240
241 return { valid: true, error: null }
242}
243
244export function safeRemoveDirectory(dirPath, projectRoot) {
245 const validation = validateDeletionPath(dirPath, projectRoot)

Callers 1

safeRemoveDirectoryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected