Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
msmitherdc authored Aug 29, 2024
1 parent 3de9f86 commit 03c5d34
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions cloudpathlib/s3/s3client.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,14 @@ def _move_file(self, src: S3Path, dst: S3Path, remove_src: bool = True) -> S3Pat
)

if remove_src:
self._set_metadata_cache(src, None)
self._set_metadata_cache(src, None, None, None, None)
self._remove(src)
return dst

def _remove(self, cloud_path: S3Path, missing_ok: bool = True) -> None:
file_or_dir = self._is_file_or_dir(cloud_path=cloud_path)
if file_or_dir == "file":
self._set_metadata_cache(cloud_path, None)
self._set_metadata_cache(cloud_path, None, None, None, None)
resp = self.s3.Object(cloud_path.bucket, cloud_path.key).delete(
**self.boto3_list_extra_args
)
Expand All @@ -372,7 +372,7 @@ def _remove(self, cloud_path: S3Path, missing_ok: bool = True) -> None:
path for path, is_dir in self._list_dir(cloud_path, recursive=True) if not is_dir
]
for path in files:
self._set_metadata_cache(path, None)
self._set_metadata_cache(path, None, None, None, None)

if resp[0].get("ResponseMetadata").get("HTTPStatusCode") not in (204, 200):
raise CloudPathException(
Expand Down Expand Up @@ -400,17 +400,20 @@ def _upload_file(self, local_path: Union[str, os.PathLike], cloud_path: S3Path)
obj.upload_file(str(local_path), Config=self.boto3_transfer_config, ExtraArgs=extra_args)
return cloud_path

def _set_metadata_cache(self, cloud_path: S3Path, is_file_or_dir: Optional[str]) -> None:
def _set_metadata_cache(self, cloud_path: S3Path, is_file_or_dir: Optional[str],
etag: Optional[str], size: Optional[int], lastmodified: Optional[str]) -> None:
if is_file_or_dir is None:
self._metadata_cache[cloud_path] = PathMetadata(is_file_or_dir=is_file_or_dir)
self._metadata_cache[cloud_path] = PathMetadata(is_file_or_dir=is_file_or_dir,
etag=etag, size=size, last_modified=lastmodified)
# If a file/dir is now known to not exist, its parent directories may no longer exist
# either, since cloud directories only exist if they have a file in them. Since their
# state is no longer known we remove them from the cache.
for parent in cloud_path.parents:
if parent in self._metadata_cache:
del self._metadata_cache[parent]
else:
self._metadata_cache[cloud_path] = PathMetadata(is_file_or_dir=is_file_or_dir)
self._metadata_cache[cloud_path] = PathMetadata(is_file_or_dir=is_file_or_dir,
etag=etag, size=size, last_modified=lastmodified)

def clear_metadata_cache(self) -> None:
self._metadata_cache.clear()
Expand Down

0 comments on commit 03c5d34

Please sign in to comment.