Skip to content

Commit 99b7d1d

Browse files
authored
Merge pull request #286 from martindurant/direct_info
Let info use HEAD if listing is not cached
2 parents 89ada77 + 597e8be commit 99b7d1d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

s3fs/core.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ def info(self, path, version_id=None):
452452
raise ValueError("version_id cannot be specified if the "
453453
"filesystem is not version aware")
454454
kwargs['VersionId'] = version_id
455-
if self.version_aware:
455+
bucket, key = self.split_path(path)
456+
if self.version_aware or (key and self._ls_from_cache(path) is None):
456457
try:
457-
bucket, key = self.split_path(path)
458458
out = self._call_s3(self.s3.head_object, kwargs, Bucket=bucket,
459459
Key=key, **self.req_kw)
460460
return {
@@ -463,7 +463,7 @@ def info(self, path, version_id=None):
463463
'LastModified': out['LastModified'],
464464
'Size': out['ContentLength'],
465465
'size': out['ContentLength'],
466-
'path': '/'.join([bucket, key]),
466+
'name': '/'.join([bucket, key]),
467467
'type': 'file',
468468
'StorageClass': "STANDARD",
469469
'VersionId': out.get('VersionId')
@@ -472,7 +472,7 @@ def info(self, path, version_id=None):
472472
ee = translate_boto_error(e)
473473
# This could have failed since the thing we are looking for is a prefix.
474474
if isinstance(ee, FileNotFoundError):
475-
return super().info(path)
475+
return super(S3FileSystem, self).info(path)
476476
else:
477477
raise ee
478478
except ParamValidationError as e:
@@ -913,7 +913,9 @@ def invalidate_cache(self, path=None):
913913
else:
914914
path = self._strip_protocol(path)
915915
self.dircache.pop(path, None)
916-
self.dircache.pop(self._parent(path), None)
916+
while path:
917+
self.dircache.pop(path, None)
918+
path = self._parent(path)
917919

918920
def walk(self, path, maxdepth=None, **kwargs):
919921
if path in ['', '*'] + [f'{p}://' for p in self.protocol]:

s3fs/tests/test_s3fs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,11 @@ def test_multiple_objects(s3):
188188
def test_info(s3):
189189
s3.touch(a)
190190
s3.touch(b)
191-
assert s3.info(a) == s3.ls(a, detail=True)[0]
191+
info = s3.info(a)
192+
linfo = s3.ls(a, detail=True)[0]
193+
assert abs(info.pop('LastModified') - linfo.pop('LastModified')).seconds < 1
194+
info.pop('VersionId')
195+
assert info == linfo
192196
parent = a.rsplit('/', 1)[0]
193197
s3.invalidate_cache() # remove full path from the cache
194198
s3.ls(parent) # fill the cache with parent dir

0 commit comments

Comments
 (0)