From d00ea4fc221d5f527d2a00f6ddd89007a3f01a01 Mon Sep 17 00:00:00 2001 From: purocean Date: Mon, 6 Aug 2018 20:16:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=94=B6=E7=AB=99=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/file.js | 16 +++++----------- backend/repository.js | 4 ++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/backend/file.js b/backend/file.js index 5f1a5b0d..a2864d03 100644 --- a/backend/file.js +++ b/backend/file.js @@ -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)) diff --git a/backend/repository.js b/backend/repository.js index dab1f446..9d14c4a5 100644 --- a/backend/repository.js +++ b/backend/repository.js @@ -21,3 +21,7 @@ exports.getPath = name => { return path.join(__dirname, '../', p) } + +exports.getTrashPath = name => { + return path.join(__dirname, '/../trash/', name) +}