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

S3fs doesn't check again if file exists #851

Open
yaelperl1234 opened this issue Feb 28, 2024 · 4 comments
Open

S3fs doesn't check again if file exists #851

yaelperl1234 opened this issue Feb 28, 2024 · 4 comments

Comments

@yaelperl1234
Copy link

In this code snippet, I check if s3 path exists, then create it by subprocess of aws cli, and then check it again.


import s3fs
import subprocess

s3fs_obj = s3fs.S3FileSystem()

src = 's3://bucket/src'
dst = 's3://bucket/dst'
print(s3fs_obj.exists(dst))
es, out = subprocess.getstatusoutput(f'aws s3 cp {src} {dst} ')

print(es)
print(s3fs_obj.exists(dst))

The results are:


False
0
False

And if I try to open the "dst" path, it fails on "FileNotFoundError".

@martindurant
Copy link
Member

This is expected and a necessary optimisation, since listing lookups on s3 are relatively expensive. You can always use invalidate_cache or one of the refresh=True arguments, or don't use the "dircache" at all.

@martindurant
Copy link
Member

Arguments controlling the directories cache:

        Parameters
        ----------
        use_listings_cache: bool
            If False, this cache never returns items, but always reports KeyError,
            and setting items has no effect
        listings_expiry_time: int or float (optional)
            Time in seconds that a listing is considered valid. If None,
            listings do not expire.
        max_paths: int (optional)
            The number of most recent listings that are considered valid; 'recent'
            refers to when the entry was set.

@yaelperl1234
Copy link
Author

yaelperl1234 commented Feb 29, 2024

Thank you @martindurant !
But how does it explain the "FileNotFoundError? "open" is a GET request, not list.

@martindurant
Copy link
Member

But how does it explain the "FileNotFoundError? "open" is a GET request, not list.

Open needs file information (size, etag, etc), so it also uses the cache. Not sure, but cat/get probably will work fine.

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

No branches or pull requests

2 participants