From 222987ce3b42faf28b12a2c31f73ee23fd0b4326 Mon Sep 17 00:00:00 2001 From: liweitian Date: Sat, 11 Apr 2020 02:08:34 +0800 Subject: [PATCH] fix: bug about deleting empty folder (#2587) * fix bug about deleting empty folder * the folder may already deleted Co-authored-by: Chris Whitten --- .../server/src/models/bot/botProject.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Composer/packages/server/src/models/bot/botProject.ts b/Composer/packages/server/src/models/bot/botProject.ts index 08e908e0ef..ddea852a73 100644 --- a/Composer/packages/server/src/models/bot/botProject.ts +++ b/Composer/packages/server/src/models/bot/botProject.ts @@ -283,13 +283,26 @@ export class BotProject { private _cleanUp = async (relativePath: string) => { const absolutePath = `${this.dir}/${relativePath}`; const dirPath = Path.dirname(absolutePath); - await this._removeEmptyFolder(dirPath); + await this._removeEmptyFolderFromBottomToUp(dirPath); + }; + + private _removeEmptyFolderFromBottomToUp = async (folderPath: string) => { + let currentFolder = folderPath; + //make sure the folder to delete is in current project + while (currentFolder.startsWith(this.dataDir)) { + await this._removeEmptyFolder(currentFolder); + currentFolder = Path.dirname(currentFolder); + } }; private _removeEmptyFolder = async (folderPath: string) => { const files = await this.fileStorage.readDir(folderPath); if (files.length === 0) { - await this.fileStorage.rmDir(folderPath); + try { + await this.fileStorage.rmDir(folderPath); + } catch (e) { + console.log(e); + } } }; @@ -384,7 +397,6 @@ export class BotProject { const absolutePath = `${this.dir}/${relativePath}`; await this.fileStorage.removeFile(absolutePath); - this.files.splice(index, 1); };