turbaszek commented on a change in pull request #11284:
URL: https://github.com/apache/airflow/pull/11284#discussion_r501182178



##########
File path: airflow/providers/google/cloud/transfers/gcs_to_sftp.py
##########
@@ -129,15 +134,25 @@ def execute(self, context):
                 )
 
             prefix, delimiter = self.source_object.split(WILDCARD, 1)
+            prefix_dirname = os.path.dirname(prefix)
+
             objects = gcs_hook.list(self.source_bucket, prefix=prefix, 
delimiter=delimiter)
 
             for source_object in objects:
-                destination_path = os.path.join(self.destination_path, 
source_object)
+                if self.ignore_gcs_path_in_destination:
+                    source_object_basename = os.path.relpath(source_object, 
start=prefix_dirname)
+                    destination_path = os.path.join(self.destination_path, 
source_object_basename)
+                else:
+                    destination_path = os.path.join(self.destination_path, 
source_object)
                 self._copy_single_object(gcs_hook, sftp_hook, source_object, 
destination_path)
 
             self.log.info("Done. Uploaded '%d' files to %s", len(objects), 
self.destination_path)
         else:
-            destination_path = os.path.join(self.destination_path, 
self.source_object)
+            if self.ignore_gcs_path_in_destination:
+                source_object_basename = os.path.basename(self.source_object)
+                destination_path = os.path.join(self.destination_path, 
source_object_basename)
+            else:
+                destination_path = os.path.join(self.destination_path, 
self.source_object)

Review comment:
       How about
   ```python
   def _resolve_destination_path(self, prefix=None):
       if self.ignore_gcs_path_in_destination:
           source_object_basename = os.path.basename(self.source_object, 
start=prefix)
           return os.path.join(self.destination_path, source_object_basename)
       else:
           return os.path.join(self.destination_path, self.source_object)
   ```
   then we can avoid duplication of the code




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to