Skip to content

Commit

Permalink
Fix s3 download for folders
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankrb committed Nov 15, 2024
1 parent 809d847 commit b4af4c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/anemoi/utils/remote/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def copy(self, source, target, **kwargs):
raise NotImplementedError

def get_temporary_target(self, target, pattern):
if pattern is None:
return target
dirname, basename = os.path.split(target)
return pattern.format(dirname=dirname, basename=basename)

Expand Down Expand Up @@ -199,13 +201,13 @@ def __init__(
target = os.path.basename(source)

temporary_target = {
False: "{dirname}/{basename}",
False: None,
True: "{dirname}-downloading/{basename}",
"-tmp/*": "{dirname}-tmp/{basename}",
"*-tmp": "{dirname}/{basename}-tmp",
"tmp-*": "{dirname}/tmp-{basename}",
}.get(temporary_target, temporary_target)
assert isinstance(temporary_target, str), (type(temporary_target), temporary_target)
assert temporary_target is None or isinstance(temporary_target, str), (type(temporary_target), temporary_target)

self.source = source
self.target = target
Expand Down
3 changes: 3 additions & 0 deletions src/anemoi/utils/remote/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def _transfer_file(self, source, target, overwrite, resume, verbosity, threads,
_, _, bucket, key = source.split("/", 3)
s3 = s3_client(bucket)

if key.endswith("/"):
return 0

try:
response = s3.head_object(Bucket=bucket, Key=key)
except s3.exceptions.ClientError as e:
Expand Down

0 comments on commit b4af4c2

Please sign in to comment.