From 98929088d341a58996116f07ed7083032cb9a504 Mon Sep 17 00:00:00 2001 From: aalej Date: Tue, 12 Sep 2023 23:56:53 +0800 Subject: [PATCH 1/4] check if export target folder is empty --- CHANGELOG.md | 1 + src/emulator/controller.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 390546cce3c..f8ef6a5fe91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ - Removed nano precision in timestamp used in Firestore emulator (#5893) - Fixed a bug where query behaves differently from production. - Fixed an issue where very long command outputs would be cut off. (#3286) +- Fixed an issue where `emulators:export` does not check if the target folder is empty. (#6313) diff --git a/src/emulator/controller.ts b/src/emulator/controller.ts index 1950cb0b346..9bc4f3edbb6 100644 --- a/src/emulator/controller.ts +++ b/src/emulator/controller.ts @@ -961,7 +961,8 @@ export async function exportEmulatorData(exportPath: string, options: any, initi // Check if there is already an export there and prompt the user about deleting it const existingMetadata = HubExport.readMetadata(exportAbsPath); - if (existingMetadata && !(options.force || options.exportOnExit)) { + const isExportDirEmpty = fs.readdirSync(exportAbsPath).length === 0; + if ((existingMetadata || !isExportDirEmpty) && !(options.force || options.exportOnExit)) { if (options.noninteractive) { throw new FirebaseError( "Export already exists in the target directory, re-run with --force to overwrite.", @@ -971,7 +972,7 @@ export async function exportEmulatorData(exportPath: string, options: any, initi const prompt = await promptOnce({ type: "confirm", - message: `The directory ${exportAbsPath} already contains export data. Exporting again to the same directory will overwrite all data. Do you want to continue?`, + message: `The directory ${exportAbsPath} is not empty. Existing files in this directory will be overwritten. Do you want to continue?`, default: false, }); From d37926e020cee70015ef27eddd42c931292a1d0e Mon Sep 17 00:00:00 2001 From: aalej Date: Fri, 15 Sep 2023 01:04:51 +0800 Subject: [PATCH 2/4] Updated CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a95dc93a824..43627f75fa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1 @@ -- Fixed an issue where `emulators:export` does not check if the target folder is empty. (#6313) \ No newline at end of file +- Fixed an issue where `emulators:export` does not check if the target folder is empty. (#6313) From 8842ef37d9933efba7070ac7143b2707800ec6e6 Mon Sep 17 00:00:00 2001 From: aalej Date: Fri, 15 Sep 2023 19:48:54 +0800 Subject: [PATCH 3/4] Update CHANGELOG.md Co-authored-by: joehan --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43627f75fa2..ad9c56c6f3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1 @@ -- Fixed an issue where `emulators:export` does not check if the target folder is empty. (#6313) +- Fixed an issue where `emulators:export` did not check if the target folder is empty. (#6313) From 8d9dc7a98d9416c943d03e6954863ce03690b553 Mon Sep 17 00:00:00 2001 From: aalej Date: Tue, 19 Sep 2023 22:33:15 +0800 Subject: [PATCH 4/4] Changed promptOnce to confirm --- src/emulator/controller.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/emulator/controller.ts b/src/emulator/controller.ts index 9bc4f3edbb6..1f2d2ba827f 100644 --- a/src/emulator/controller.ts +++ b/src/emulator/controller.ts @@ -34,7 +34,7 @@ import { LoggingEmulator } from "./loggingEmulator"; import * as dbRulesConfig from "../database/rulesConfig"; import { EmulatorLogger } from "./emulatorLogger"; import { EmulatorHubClient } from "./hubClient"; -import { promptOnce } from "../prompt"; +import { confirm } from "../prompt"; import { FLAG_EXPORT_ON_EXIT_NAME, JAVA_DEPRECATION_WARNING, @@ -970,9 +970,10 @@ export async function exportEmulatorData(exportPath: string, options: any, initi ); } - const prompt = await promptOnce({ - type: "confirm", + const prompt = await confirm({ message: `The directory ${exportAbsPath} is not empty. Existing files in this directory will be overwritten. Do you want to continue?`, + nonInteractive: options.nonInteractive, + force: options.force, default: false, });