diff --git a/CHANGELOG.md b/CHANGELOG.md index e6e144b702a..f80b20b3933 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1,2 @@ +- Fixed an issue where `emulators:export` did not check if the target folder is empty. (#6313) - Fix "Could not find the next executable" on Next.js deployments (#6372) diff --git a/src/emulator/controller.ts b/src/emulator/controller.ts index 1950cb0b346..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, @@ -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.", @@ -969,9 +970,10 @@ 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?`, + 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, });