Skip to content

Commit

Permalink
fix: fix bug when checking existence of non-existing items
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneskoester committed Sep 28, 2023
1 parent f4e4af0 commit 383face
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions snakemake_storage_plugin_s3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def exists(self) -> bool:
self.s3obj().load()
except botocore.exceptions.ClientError as e:
if e.response["Error"]["Code"] == "404":
if self.is_dir():
if self.bucket_exists() and self.is_dir():
return True
return False
else:
Expand Down Expand Up @@ -290,7 +290,7 @@ def get_subkeys(self):
def store_object(self):
# Ensure that the object is stored at the location specified by
# self.local_path().
if not self.bucket_exists(self.bucket):
if not self.bucket_exists():
self.provider.s3c.create_bucket(Bucket=self.bucket)

if self.local_path().is_dir():
Expand Down Expand Up @@ -330,9 +330,9 @@ def list_candidate_matches(self) -> Iterable[str]:
"supported."
)

def bucket_exists(self, bucket_name):
def bucket_exists(self):
try:
self.provider.s3c.meta.client.head_bucket(Bucket=bucket_name)
self.provider.s3c.meta.client.head_bucket(Bucket=self.bucket)
return True
except Exception:
return False
6 changes: 6 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional, Type
import uuid
from snakemake_interface_storage_plugins.tests import TestStorageBase
from snakemake_interface_storage_plugins.storage_provider import StorageProviderBase
from snakemake_interface_storage_plugins.settings import StorageProviderSettingsBase
Expand All @@ -13,6 +14,11 @@ class TestStorageNoSettings(TestStorageBase):
def get_query(self) -> str:
return "s3://snakemake-test-bucket/test-file.txt"

def get_query_not_existing(self) -> str:
bucket = uuid.uuid4().hex
key = uuid.uuid4().hex
return f"s3://{bucket}/{key}"

def get_storage_provider_cls(self) -> Type[StorageProviderBase]:
# Return the StorageProvider class of this plugin
return StorageProvider
Expand Down

0 comments on commit 383face

Please sign in to comment.