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

Helping prevention of accidental directory exclusion when using the --export-on-exit option #4127

Conversation

Muritavo
Copy link
Contributor

@Muritavo Muritavo commented Feb 3, 2022

Description

Adding condition to prevent the user from setting the --export-on-exit option to the CWD, inflicting in directory exclusion after stopping the emulators

Scenarios Tested

The firebase emulators:start command should fail now if the --export-on-exit is set to the CWD or parent directories

Commands tested:

  • Current dir (SHOULD FAIL): firebase emulators:start --export-on-exit ./

  • Current dir parent (SHOULD FAIL): firebase emulators:start --export-on-exit ../

  • Implicit --export-on-exit via setting the --import flag (SHOULD FAIL): firebase emulators:start --import ./ --export-on-exit

  • A sub directory (SHOULD PASS): firebase emulators:start --export-on-exit ./dump-db

  • Implicit --export-on-exit sub directory (SHOULD PASS): firebase emulators:start --import ./dump-db --export-on-exit

Sample Commands

Should not allow:

firebase emulators:start --export-on-exit ./

One that should allow:

firebase emulators:start --export-on-exit ./dump-db

…der to the CWD, inflicting in directory exclusion after stopping the emulators
@yuchenshi
Copy link
Member

Thanks for the PR! Getting someone to take a look

Copy link
Member

@yuchenshi yuchenshi left a comment

Choose a reason for hiding this comment

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

Overall I think is a good stop-gap solution and I'm happy to merge this once the comments are addressed. (It would be even better though if we can find a way to export without nuking the target directory, but that is a longer term solution.)

src/emulator/commandUtils.ts Outdated Show resolved Hide resolved
src/emulator/commandUtils.ts Outdated Show resolved Hide resolved
Fixed a cenario where the user could ingress a pattern of cwd and it would fail incorrectly
@Muritavo
Copy link
Contributor Author

Muritavo commented Feb 9, 2022

Overall I think is a good stop-gap solution and I'm happy to merge this once the comments are addressed. (It would be even better though if we can find a way to export without nuking the target directory, but that is a longer term solution.)

Yup, I just built this PR in like 1 hour to reduce the chances for people to accidentally exclude their projects by runnning the command without prior understanding. I almost lost 2 weeks of work because of this. If someone would try with their root user folder the destruction would be massive.

If I get the time, I will try to dive into the core of firebase persistency to fix this in a definitive manner and possibly rollback this PR.

Thanks for pointing out which PR (supposedly) introduced the issue, that will save up some time :)

@yuchenshi yuchenshi merged commit 8a874e1 into firebase:master Feb 15, 2022
yuchenshi added a commit that referenced this pull request Feb 15, 2022
@yuchenshi
Copy link
Member

Thanks again for your contribution! This PR is now merged and will be included in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants