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

file.exists() is always true #3764

Closed
yairopro opened this issue Sep 19, 2021 · 4 comments · Fixed by #3647
Closed

file.exists() is always true #3764

yairopro opened this issue Sep 19, 2021 · 4 comments · Fixed by #3647

Comments

@yairopro
Copy link

yairopro commented Sep 19, 2021

[REQUIRED] Environment info

firebase-tools: 9.18.0

Platform: macOS

[REQUIRED] Test case

The storage emulator within an executed script (with exec commande) is inconsistant because the emulator will always return that any file is existant, whatever file name you give him.

[REQUIRED] Steps to reproduce

Execute the following snippet within the emulator (storage emulator needed). The output will always be true.

// firebase emulators:exec test.js

const admin = require('firebase-admin');
admin.initializeApp({ storageBucket: 'default-bucket' });
const bucket = admin.storage().bucket();
const file = bucket.file(`/inexistantFile`);
const [exists] = await file.exists();
console.log('inexistantFile: ', exists); // exists will always be true

[REQUIRED] Expected behavior

The emulator to be consistant. The File.exists()method should returns false when a file was never created or deleted.

[REQUIRED] Actual behavior

The File.exists() method always returns true even for non existing files.

@yairopro yairopro changed the title Storage emulator - exec: admin.storage().bucket() is inconsistent Storage emulator in execution is inconsistent Sep 19, 2021
@abeisgoat abeisgoat changed the title Storage emulator in execution is inconsistent file.exists() is always true Sep 20, 2021
@abeisgoat abeisgoat self-assigned this Sep 20, 2021
@abeisgoat
Copy link
Contributor

This is actually outside the current scope of the emulator as the exists() method is not one we guarantee to be correct atm. We're working on extending Google Cloud API support, so hopefully this will function correctly in the near future.

@yairopro
Copy link
Author

Thanks for this information.
How can I know which storage methods / features are supported by the emulator (guaranteed to be correct )? please

@rhodgkins
Copy link
Contributor

I had similar problems so implemented various missing features of the Storage emulator - its still waiting to be merged :-/
You could try working against this and see if it fixes your problem and try upvoting / commenting on the PR.

@schankam
Copy link

Use it that way: const [fileExist] = await file.exists();

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

Successfully merging a pull request may close this issue.

5 participants