回收站路径支持仓库

This commit is contained in:
purocean
2018-08-06 20:16:08 +08:00
parent 57310c7a55
commit d00ea4fc22
2 changed files with 9 additions and 11 deletions
+5 -11
View File
@@ -39,18 +39,12 @@ const rmRecursiveSync = location => {
const resolvePath = (p, repo = 'main') => {
p = p.replace(/\.\./g, '')
if (repo === 'trash') {
p = path.join(__dirname, '/../trash/', p)
} else {
const basePath = repository.getPath(repo)
if (!basePath) {
throw new Error(`仓库 ${repo} 不存在`)
}
p = path.join(basePath, p)
const basePath = repository.getPath(repo)
if (!basePath) {
throw new Error(`仓库 ${repo} 不存在`)
}
return p
return path.join(basePath, p)
}
const travels = (location, repo, basePath = null) => {
@@ -105,7 +99,7 @@ exports.write = (repo, p, content) => {
exports.rm = (repo, p) => {
if (resolvePath(p) !== resolvePath('', repo)) {
const newPath = resolvePath(p, 'trash') + '.' + (new Date).getTime()
const newPath = path.join(repository.getTrashPath(repo), p.replace(/\.\./g, '')) + '.' + (new Date).getTime()
mkdirPSync(path.dirname(newPath))
+4
View File
@@ -21,3 +21,7 @@ exports.getPath = name => {
return path.join(__dirname, '../', p)
}
exports.getTrashPath = name => {
return path.join(__dirname, '/../trash/', name)
}