From 1dc974245f1f47d4b870e13ddbc9d70877dcb548 Mon Sep 17 00:00:00 2001 From: Rainshaw Date: Wed, 15 Sep 2021 08:14:32 +0800 Subject: [PATCH] fix: sftp error when dir already exists (#4024) when the dir exists, sftp.mkdir() would raise an error and ends the for loop. --- server/modules/storage/sftp/storage.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/modules/storage/sftp/storage.js b/server/modules/storage/sftp/storage.js index e1f99af4..49d5ae1d 100644 --- a/server/modules/storage/sftp/storage.js +++ b/server/modules/storage/sftp/storage.js @@ -155,7 +155,12 @@ module.exports = { const folderPaths = _.dropRight(filePath.split('/')) for (let i = 1; i <= folderPaths.length; i++) { const folderSection = _.take(folderPaths, i).join('/') - await this.sftp.mkdir(path.posix.join(this.config.basePath, folderSection)) + const folderDir = path.posix.join(this.config.basePath, folderSection) + try { + await this.sftp.readdir(folderDir) + } catch (err) { + await this.sftp.mkdir(folderDir) + } } } catch (err) {} }