Skip to content

Commit

Permalink
fix: bug about deleting empty folder (#2587)
Browse files Browse the repository at this point in the history
* fix bug about deleting empty folder

* the folder may already deleted

Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
  • Loading branch information
liweitian and cwhitten authored Apr 10, 2020
1 parent 4f1ae4f commit 222987c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Composer/packages/server/src/models/bot/botProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};

Expand Down Expand Up @@ -384,7 +397,6 @@ export class BotProject {

const absolutePath = `${this.dir}/${relativePath}`;
await this.fileStorage.removeFile(absolutePath);

this.files.splice(index, 1);
};

Expand Down

0 comments on commit 222987c

Please sign in to comment.