Selaa lähdekoodia

[s3] Skip move/copy operation if parent path of source is equal to destination path (#3478)

What changes were proposed in this pull request?
- Whenever someone attempt to copy multiple files on Hue File Browser, they can encounter dataloss if they do not wait for the model pop-up to fully load.

RCA
- Found the root cause and it's because of a bad call to Hue server which is sending wrong destination path.
- When the modal pops up to select the destination path, it tries to list down the content of the directory chosen and that takes some extra seconds but the button to move is clickable still. When someone clicks the 'Move' button but the path has not loaded correctly, it sends the wrong path (either the source path or default user home path) instead of actual destination path with the request.
- This messes up the move operation in the backend where it actually doesn't move stuff to the destination because the path was incorrect or the keys were already present in the wrong path so it skips them, and afterwards cleanup the keys from the source path.

Fix
- Adding guardrail checks to skip the operation when the parent path of source is equal to destination for copy and move operations.

How was this patch tested?
- Tested manually.
Harsh Gupta 2 vuotta sitten
vanhempi
commit
68d48169a5
1 muutettua tiedostoa jossa 20 lisäystä ja 2 poistoa
  1. 20 2
      desktop/libs/aws/src/aws/s3/s3fs.py

+ 20 - 2
desktop/libs/aws/src/aws/s3/s3fs.py

@@ -462,6 +462,10 @@ class S3FileSystem(object):
     if src_st.isDir and dst_st and not dst_st.isDir:
       raise S3FileSystemException("Cannot overwrite non-directory '%s' with directory '%s'" % (dst, src))
 
+    # Skip operation if destination path is same as source path
+    if self._check_key_parent_path(src, dst):
+      raise S3FileSystemException('Destination path is same as the source path, skipping the operation.')
+
     src_bucket, src_key = s3.parse_uri(src)[:2]
     dst_bucket, dst_key = s3.parse_uri(dst)[:2]
 
@@ -492,8 +496,22 @@ class S3FileSystem(object):
   @auth_error_handler
   def rename(self, old, new):
     new = s3.abspath(old, new)
-    self.copy(old, new, recursive=True)
-    self.rmtree(old, skipTrash=True)
+
+    # Skip operation if destination path is same as source path
+    if not self._check_key_parent_path(old, new):
+      self.copy(old, new, recursive=True)
+      self.rmtree(old, skipTrash=True)
+    else:
+      raise S3FileSystemException('Destination path is same as source path, skipping the operation.')
+  
+  @translate_s3_error
+  @auth_error_handler
+  def _check_key_parent_path(self, src, dst):
+    # Return True if parent path of source is same as destination path.
+    if S3FileSystem.parent_path(src) == dst:
+      return True
+    else:
+      return False
 
   @translate_s3_error
   @auth_error_handler