Skip to content

Commit

Permalink
Enable recursive delete on owner root without needing glob expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
bhperry committed Mar 5, 2024
1 parent 5ce019c commit eb73e68
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions saturnfs/client/saturnfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
UploadChunk,
)
from saturnfs.client.object_storage import ObjectStorageClient
from saturnfs.errors import ExpiredSignature, SaturnError
from saturnfs.errors import ExpiredSignature, PathErrors, SaturnError
from saturnfs.schemas import ObjectStorage, ObjectStoragePrefix
from saturnfs.schemas.download import ObjectStoragePresignedDownload
from saturnfs.schemas.list import ObjectStorageInfo
Expand Down Expand Up @@ -761,7 +761,13 @@ def rm_bulk(self, paths: List[str], callback: Callback = DEFAULT_CALLBACK):
callback.set_size(len(paths))
owner_paths: Dict[str, List[str]] = {}
for path in paths:
remote = ObjectStorage.parse(path)
try:
remote = ObjectStorage.parse(path)
except SaturnError as e:
if e.message == PathErrors.INVALID_REMOTE_FILE and self._is_owner_root(path):
# Recursive delete on owner root path includes the root dir, ignore error
continue
raise e
owner_paths.setdefault(remote.owner_name, [])
owner_paths[remote.owner_name].append(remote.file_path)

Expand Down Expand Up @@ -848,6 +854,10 @@ def validate_cache(self, path: str, size: int, updated_at: datetime):
if info.size != size or info.updated_at != updated_at:
self.invalidate_cache(path)

def _is_owner_root(self, path: str) -> bool:
path = self._strip_protocol(path).strip("/")
return len(path.split("/")) == 2


class SaturnFile(AbstractBufferedFile):
"""
Expand Down

0 comments on commit eb73e68

Please sign in to comment.