Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions snakemake_storage_plugin_s3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def __post_init__(self):
# (which is invalid for S3 keys).
self.key = posixpath.normpath(parsed.path.lstrip("/"))
self._local_suffix = self._local_suffix_from_key(self.key)
self._is_dir = None

def s3obj(self, subkey: Optional[str] = ""):
if subkey:
Expand Down Expand Up @@ -326,9 +325,20 @@ def retrieve_object(self):
self.s3obj().download_file(self.local_path())

def is_dir(self):
if self._is_dir is None:
self._is_dir = any(self.get_subkeys())
return self._is_dir
if self.local_path().is_dir():
return True

try:
self.s3obj(".snakemake_timestamp").load()
return True
except botocore.exceptions.ClientError as e:
err_code = e.response["Error"]["Code"]
if err_code == "404":
return False
else:
raise e

return False

def get_subkeys(self):
prefix = self.s3obj().key + "/"
Expand All @@ -355,7 +365,6 @@ def store_object(self):
self.provider.s3c.create_bucket(**create_bucket_params)

if self.local_path().is_dir():
self._is_dir = True
for item in self.local_path().rglob("*"):
if item.is_file():
self.s3obj(subkey=item.relative_to(self.local_path())).upload_file(
Expand Down
Loading