Skip to content

Commit

Permalink
Merge pull request #286 from martindurant/direct_info
Browse files Browse the repository at this point in the history
Let info use HEAD if listing is not cached
  • Loading branch information
martindurant authored Feb 25, 2020
2 parents 89ada77 + 597e8be commit 99b7d1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 7 additions & 5 deletions s3fs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ def info(self, path, version_id=None):
raise ValueError("version_id cannot be specified if the "
"filesystem is not version aware")
kwargs['VersionId'] = version_id
if self.version_aware:
bucket, key = self.split_path(path)
if self.version_aware or (key and self._ls_from_cache(path) is None):
try:
bucket, key = self.split_path(path)
out = self._call_s3(self.s3.head_object, kwargs, Bucket=bucket,
Key=key, **self.req_kw)
return {
Expand All @@ -463,7 +463,7 @@ def info(self, path, version_id=None):
'LastModified': out['LastModified'],
'Size': out['ContentLength'],
'size': out['ContentLength'],
'path': '/'.join([bucket, key]),
'name': '/'.join([bucket, key]),
'type': 'file',
'StorageClass': "STANDARD",
'VersionId': out.get('VersionId')
Expand All @@ -472,7 +472,7 @@ def info(self, path, version_id=None):
ee = translate_boto_error(e)
# This could have failed since the thing we are looking for is a prefix.
if isinstance(ee, FileNotFoundError):
return super().info(path)
return super(S3FileSystem, self).info(path)
else:
raise ee
except ParamValidationError as e:
Expand Down Expand Up @@ -913,7 +913,9 @@ def invalidate_cache(self, path=None):
else:
path = self._strip_protocol(path)
self.dircache.pop(path, None)
self.dircache.pop(self._parent(path), None)
while path:
self.dircache.pop(path, None)
path = self._parent(path)

def walk(self, path, maxdepth=None, **kwargs):
if path in ['', '*'] + [f'{p}://' for p in self.protocol]:
Expand Down
6 changes: 5 additions & 1 deletion s3fs/tests/test_s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ def test_multiple_objects(s3):
def test_info(s3):
s3.touch(a)
s3.touch(b)
assert s3.info(a) == s3.ls(a, detail=True)[0]
info = s3.info(a)
linfo = s3.ls(a, detail=True)[0]
assert abs(info.pop('LastModified') - linfo.pop('LastModified')).seconds < 1
info.pop('VersionId')
assert info == linfo
parent = a.rsplit('/', 1)[0]
s3.invalidate_cache() # remove full path from the cache
s3.ls(parent) # fill the cache with parent dir
Expand Down

0 comments on commit 99b7d1d

Please # to comment.