Skip to content

Commit

Permalink
[AWS] handling copy function correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
agl29 committed Nov 1, 2023
1 parent ec1a8e7 commit 40a96de
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions desktop/libs/aws/src/aws/s3/s3fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,24 @@ def _copy(self, src, dst, recursive, use_src_basename):
if not src_key.endswith('/'):
cut += 1

for key in src_bucket.list(prefix=src_key):
if not key.name.startswith(src_key):
raise S3FileSystemException(_("Invalid key to transform: %s") % key.name)
dst_name = posixpath.normpath(s3.join(dst_key, key.name[cut:]))

if self.isdir(normpath(self.join(S3A_ROOT, key.bucket.name, key.name))):
dst_name = self._append_separator(dst_name)

# handling files and directories distinctly. When dealing with files, extract the key and copy the file to the specified location.
# Regarding directories, when listing keys with the 'test1' prefix, it was including all directories or files starting with 'test1,'
# such as test1, test123, and test1234. Since we need the test1 directory only, we add '/' after the source key name,
# resulting in 'test1/'.
if src_st.isDir:
src_key = self._append_separator(src_key)
for key in src_bucket.list(prefix=src_key):
if not key.name.startswith(src_key):
raise S3FileSystemException(_("Invalid key to transform: %s") % key.name)
dst_name = posixpath.normpath(s3.join(dst_key, key.name[cut:]))

if self.isdir(normpath(self.join(S3A_ROOT, key.bucket.name, key.name))):
dst_name = self._append_separator(dst_name)

key.copy(dst_bucket, dst_name)
else:
key = self._get_key(src)
dst_name = posixpath.normpath(s3.join(dst_key, src_key[cut:]))
key.copy(dst_bucket, dst_name)

@translate_s3_error
Expand Down

0 comments on commit 40a96de

Please sign in to comment.