Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a check to see if export target folder is empty #6357

Merged
merged 6 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed an issue where `emulators:export` does not check if the target folder is empty. (#6313)
aalej marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions src/emulator/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -971,7 +972,7 @@ export async function exportEmulatorData(exportPath: string, options: any, initi

const prompt = await promptOnce({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional - consider using confirm here instead - it already has some of this logic for handling force/non-interactive baked in

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,
});

Expand Down