Skip to content

Commit

Permalink
fix: download sample app to same folder will overwrite (#1060)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuihuiWu-Microsoft authored and LongOddCode committed May 20, 2021
1 parent 198143a commit 33944c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/fx-core/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ class CoreImpl implements Core {
if (answer === "Download") {
const url = samples.data as string;
const sampleId = samples.id;

const sampleAppPath = path.join(folder, sampleId);
if (
(await fs.pathExists(sampleAppPath)) &&
(await fs.readdir(sampleAppPath)).length > 0
) {
return err(
new UserError(
error.CoreErrorNames.ProjectFolderExist,
`Path ${sampleAppPath} alreay exists. Select a different folder.`,
error.CoreSource
)
);
}

const progress = this.ctx.dialog.createProgressBar("Fetch sample app", 2);
progress.start();
try {
Expand Down
12 changes: 11 additions & 1 deletion packages/vscode-extension/src/controls/webviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ export class WebviewPanel {
title: "Select folder to download the sample app",
});
if (folder !== undefined) {
const sampleAppPath = path.join(folder[0].fsPath, msg.data.appFolder);
if (
(await fs.pathExists(sampleAppPath)) &&
(await fs.readdir(sampleAppPath)).length > 0
) {
vscode.window.showErrorMessage(
`Path ${sampleAppPath} alreay exists. Select a different folder.`
);
return;
}
const dialogManager = DialogManager.getInstance();
const progress = dialogManager.createProgressBar("Fetch sample app", 2);
progress.start();
Expand All @@ -102,7 +112,7 @@ export class WebviewPanel {
);
vscode.commands.executeCommand(
"vscode.openFolder",
vscode.Uri.file(path.join(folder[0].fsPath, msg.data.appFolder))
vscode.Uri.file(sampleAppPath)
);
} else {
vscode.window.showErrorMessage("Failed to download sample app");
Expand Down

0 comments on commit 33944c0

Please sign in to comment.