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

Command "firebase emulators:export ." deleted all my files without any warning #3962

Closed
gitslav opened this issue Dec 19, 2021 · 7 comments
Closed

Comments

@gitslav
Copy link

gitslav commented Dec 19, 2021

[REQUIRED] Environment info

firebase-tools: 9.19.0

Platform: macOS

[REQUIRED] Test case

[REQUIRED] Steps to reproduce

  1. In directory A create a symlink B to directory C (imagine all our projects are located here)
  2. cd B
  3. cd D (one of our projects)
  4. run "firebase emulators:export ."

[REQUIRED] Expected behavior

  1. Important project files are still existing in current folder.
  2. Set of entity export files is created in current folder.

[REQUIRED] Actual behavior

  1. All important project files are deleted
  2. Set of entity export files are not created in current folder
  3. Error "Export request failed, see emulator logs for more information." is shown

Screenshot 2021-12-19 at 10 52 40

Edit:
After trying to reproduce the issue I found that I used a symlink while navigating to the final directory.

const exportAbsPath = path.resolve(exportPath);

This does not resolve/respect symlinks and is probably where the issue starts from.

@abeisgoat
Copy link
Contributor

Hmm, thanks for raising this, the CLI should really prompt you if you're attempting to export to a directory which already has files in it. We'll put this as a feature request.

@gitslav
Copy link
Author

gitslav commented Jan 10, 2022

@abeisgoat the CLI does prompt you if the path does not contain a symbolic link.
If it does contain a symbolic link the use of "path.resolve" function (shown above) breaks the flow and leads to a bug where the files are deleted.
A proper way to implement this should probably be by using "fs.realpath" function as it is resolving properly ., .. and symbolic links.

@DiegoGonzalezCruz
Copy link

OMG I can't believe I'm not the only person...

@gitslav
Copy link
Author

gitslav commented May 16, 2022

It's a really nasty bug. Not sure why @abeisgoat added a feature request label 😃

@yuchenshi
Copy link
Member

Just to add a bit of context, we've fixed the most common and dangerous case of wiping your project directory in #4127 so please update to the latest CLI version. However, the detection is imperfect that it doesn't handle symlinks, which we can tackle next (as @gitslav suggested).

There's also a possibility for one to specify some other directory that is not within the project but contains other files, which we're still trying to figure out the best behavior. Prompting is a good idea, but it may break many test scripts and use cases that overwrites previous exports. Besides, it doesn't really work with --export-on-exit when the process is exiting and cannot wait on interactive input. Ideas welcome here.

@Elias070
Copy link

Lost half of all progress because of this bug... please fix, or atleast add warning in documentation

@colerogers
Copy link
Contributor

Closing this out since we have #3092 as the proper place for discussion

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

No branches or pull requests

7 participants