potiuk commented on code in PR #64966:
URL: https://github.com/apache/airflow/pull/64966#discussion_r3143750768


##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/transfers/gcs_to_wasb.py:
##########
@@ -0,0 +1,258 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""This module contains Google Cloud Storage to Azure Blob Storage operator."""
+
+from __future__ import annotations
+
+import os
+from collections.abc import Sequence
+from typing import TYPE_CHECKING
+
+from packaging.version import Version
+
+from airflow.providers.common.compat.sdk import BaseOperator
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+try:
+    from airflow.providers.google.cloud.hooks.gcs import GCSHook
+except ModuleNotFoundError as e:
+    from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
+
+    raise AirflowOptionalProviderFeatureException(e)
+
+if TYPE_CHECKING:
+    from airflow.providers.openlineage.extractors import OperatorLineage
+    from airflow.sdk import Context
+
+
+class GCSToAzureBlobStorageOperator(BaseOperator):
+    """
+    Synchronizes objects from a Google Cloud Storage bucket to Azure Blob 
Storage.
+
+    .. note::
+        When ``flatten_structure=True``, it takes precedence over 
``keep_directory_structure``.
+        For example, with ``flatten_structure=True``, 
``folder/subfolder/file.txt`` becomes
+        ``file.txt`` regardless of the ``keep_directory_structure`` setting.
+
+        Objects whose names end with ``/`` (GCS console folder markers) and 
keys that become an
+        empty destination path after ``flatten_structure`` are skipped.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:GCSToAzureBlobStorageOperator`
+
+    :param gcs_bucket: The GCS bucket to list objects from. (templated)
+    :param prefix: Prefix to filter object names under the bucket. (templated)
+    :param gcp_conn_id: Airflow connection ID for Google Cloud.
+    :param google_impersonation_chain: Optional impersonation chain for GCP 
credentials.
+    :param gcp_user_project: Requester-pays billing project for GCS requests, 
if required.
+    :param match_glob: Optional glob filter for object names (requires
+        ``apache-airflow-providers-google>=10.3.0``).
+    :param container_name: Azure Blob container to upload into. (templated)
+    :param blob_prefix: Base blob path for uploaded objects. (templated)
+    :param wasb_conn_id: Airflow connection ID for Azure Blob Storage.
+    :param replace: If ``True``, overwrite existing blobs (``overwrite=True`` 
on upload) and
+        upload all listed objects. If ``False``, skip objects that already 
exist under
+        ``blob_prefix`` with the same relative path and pass 
``overwrite=False`` on upload.
+    :param keep_directory_structure: When ``False`` and ``prefix`` is set (and
+        ``flatten_structure`` is ``False``), append ``prefix`` to 
``blob_prefix``.
+    :param flatten_structure: If ``True``, upload each object using only its 
file name
+        under ``blob_prefix``. Takes precedence over 
``keep_directory_structure``.
+    :param create_container: If ``True``, create the container when missing 
before upload.
+    """
+
+    template_fields: Sequence[str] = (
+        "gcs_bucket",
+        "prefix",
+        "blob_prefix",
+        "container_name",
+        "google_impersonation_chain",
+        "gcp_user_project",
+        "match_glob",
+    )
+    ui_color = "#f0eee4"
+
+    def __init__(
+        self,
+        *,
+        gcs_bucket: str,
+        container_name: str,
+        blob_prefix: str = "",
+        prefix: str | None = None,
+        gcp_conn_id: str = "google_cloud_default",
+        google_impersonation_chain: str | Sequence[str] | None = None,
+        wasb_conn_id: str = "wasb_default",
+        replace: bool = False,
+        keep_directory_structure: bool = True,
+        flatten_structure: bool = False,
+        match_glob: str | None = None,
+        gcp_user_project: str | None = None,
+        create_container: bool = False,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.gcs_bucket = gcs_bucket
+        self.prefix = prefix
+        self.gcp_conn_id = gcp_conn_id
+        self.google_impersonation_chain = google_impersonation_chain
+        self.container_name = container_name
+        self.blob_prefix = blob_prefix
+        self.wasb_conn_id = wasb_conn_id
+        self.replace = replace
+        self.keep_directory_structure = keep_directory_structure
+        self.flatten_structure = flatten_structure
+        self.gcp_user_project = gcp_user_project
+        self.create_container = create_container
+
+        if self.flatten_structure and self.keep_directory_structure:
+            self.log.warning("flatten_structure=True takes precedence over 
keep_directory_structure=True")
+
+        try:
+            from airflow.providers.google import __version__ as 
_GOOGLE_PROVIDER_VERSION
+
+            if Version(Version(_GOOGLE_PROVIDER_VERSION).base_version) >= 
Version("10.3.0"):
+                self.__is_match_glob_supported = True
+            else:
+                self.__is_match_glob_supported = False
+        except ImportError:
+            self.__is_match_glob_supported = False
+        if not self.__is_match_glob_supported and match_glob:
+            raise ValueError("The 'match_glob' parameter requires 
'apache-airflow-providers-google>=10.3.0'.")
+        self.match_glob = match_glob
+
+    def _transform_file_path(self, file_path: str) -> str:
+        """
+        Transform the GCS file path according to the specified options.
+
+        :param file_path: The original GCS file path
+        :return: The transformed file path for Azure Blob destination
+        """
+        if self.flatten_structure:
+            return os.path.basename(file_path)
+        return file_path
+
+    @staticmethod
+    def _should_skip_gcs_object(name: str) -> bool:
+        """
+        Return True if this object name should not be copied.
+
+        The GCS console creates zero-byte "folder" markers whose keys end with 
``/``.
+        Those yield an empty basename when ``flatten_structure=True`` and odd 
blob paths
+        on Azure when copied as-is.
+        """
+        if not name or not name.strip():
+            return True
+        return name.endswith("/")
+
+    def execute(self, context: Context) -> list[str]:
+        gcs_hook = GCSHook(
+            gcp_conn_id=self.gcp_conn_id,
+            impersonation_chain=self.google_impersonation_chain,
+        )
+        wasb_hook = WasbHook(wasb_conn_id=self.wasb_conn_id)
+
+        self.log.info(
+            "Getting list of the files. Bucket: %s; Prefix: %s",
+            self.gcs_bucket,
+            self.prefix,
+        )
+
+        list_kwargs: dict = {
+            "bucket_name": self.gcs_bucket,
+            "prefix": self.prefix,
+            "user_project": self.gcp_user_project,
+        }
+        if self.__is_match_glob_supported:
+            list_kwargs["match_glob"] = self.match_glob
+
+        gcs_files = gcs_hook.list(**list_kwargs)  # type: ignore[call-arg]
+
+        gcs_files = [
+            f for f in gcs_files if not self._should_skip_gcs_object(f) and 
self._transform_file_path(f)
+        ]
+
+        if not self.keep_directory_structure and self.prefix and not 
self.flatten_structure:
+            self.blob_prefix = os.path.join(self.blob_prefix, self.prefix)
+
+        if not self.replace:
+            existing_blobs = wasb_hook.get_blobs_list_recursive(
+                container_name=self.container_name,
+                prefix=self.blob_prefix or None,
+            )
+            existing_blobs = existing_blobs or []
+            if self.blob_prefix:
+                prefix_str = self.blob_prefix.rstrip("/") + "/"
+                existing_blobs = [b.replace(prefix_str, "", 1) for b in 
existing_blobs]

Review Comment:
   `str.replace` finds the first occurrence anywhere, not just at the leading 
edge — for `blob_prefix="data"` and a returned blob `archive/data/x.txt` it 
would mis-strip the middle `data/`. In practice 
`get_blobs_list_recursive(prefix=blob_prefix)` only returns blobs starting with 
`blob_prefix`, so the bug rarely fires, but `removeprefix` is unambiguous:
   
   ```suggestion
                   existing_blobs = [b.removeprefix(prefix_str) for b in 
existing_blobs]
   ```



##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/transfers/gcs_to_wasb.py:
##########
@@ -0,0 +1,258 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""This module contains Google Cloud Storage to Azure Blob Storage operator."""
+
+from __future__ import annotations
+
+import os
+from collections.abc import Sequence
+from typing import TYPE_CHECKING
+
+from packaging.version import Version
+
+from airflow.providers.common.compat.sdk import BaseOperator
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+try:
+    from airflow.providers.google.cloud.hooks.gcs import GCSHook
+except ModuleNotFoundError as e:
+    from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
+
+    raise AirflowOptionalProviderFeatureException(e)
+
+if TYPE_CHECKING:
+    from airflow.providers.openlineage.extractors import OperatorLineage
+    from airflow.sdk import Context
+
+
+class GCSToAzureBlobStorageOperator(BaseOperator):
+    """
+    Synchronizes objects from a Google Cloud Storage bucket to Azure Blob 
Storage.
+
+    .. note::
+        When ``flatten_structure=True``, it takes precedence over 
``keep_directory_structure``.
+        For example, with ``flatten_structure=True``, 
``folder/subfolder/file.txt`` becomes
+        ``file.txt`` regardless of the ``keep_directory_structure`` setting.
+
+        Objects whose names end with ``/`` (GCS console folder markers) and 
keys that become an
+        empty destination path after ``flatten_structure`` are skipped.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:GCSToAzureBlobStorageOperator`
+
+    :param gcs_bucket: The GCS bucket to list objects from. (templated)
+    :param prefix: Prefix to filter object names under the bucket. (templated)
+    :param gcp_conn_id: Airflow connection ID for Google Cloud.
+    :param google_impersonation_chain: Optional impersonation chain for GCP 
credentials.
+    :param gcp_user_project: Requester-pays billing project for GCS requests, 
if required.
+    :param match_glob: Optional glob filter for object names (requires
+        ``apache-airflow-providers-google>=10.3.0``).
+    :param container_name: Azure Blob container to upload into. (templated)
+    :param blob_prefix: Base blob path for uploaded objects. (templated)
+    :param wasb_conn_id: Airflow connection ID for Azure Blob Storage.
+    :param replace: If ``True``, overwrite existing blobs (``overwrite=True`` 
on upload) and
+        upload all listed objects. If ``False``, skip objects that already 
exist under
+        ``blob_prefix`` with the same relative path and pass 
``overwrite=False`` on upload.
+    :param keep_directory_structure: When ``False`` and ``prefix`` is set (and
+        ``flatten_structure`` is ``False``), append ``prefix`` to 
``blob_prefix``.
+    :param flatten_structure: If ``True``, upload each object using only its 
file name
+        under ``blob_prefix``. Takes precedence over 
``keep_directory_structure``.
+    :param create_container: If ``True``, create the container when missing 
before upload.
+    """
+
+    template_fields: Sequence[str] = (
+        "gcs_bucket",
+        "prefix",
+        "blob_prefix",
+        "container_name",
+        "google_impersonation_chain",
+        "gcp_user_project",
+        "match_glob",
+    )
+    ui_color = "#f0eee4"
+
+    def __init__(
+        self,
+        *,
+        gcs_bucket: str,
+        container_name: str,
+        blob_prefix: str = "",
+        prefix: str | None = None,
+        gcp_conn_id: str = "google_cloud_default",
+        google_impersonation_chain: str | Sequence[str] | None = None,
+        wasb_conn_id: str = "wasb_default",
+        replace: bool = False,
+        keep_directory_structure: bool = True,
+        flatten_structure: bool = False,
+        match_glob: str | None = None,
+        gcp_user_project: str | None = None,
+        create_container: bool = False,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.gcs_bucket = gcs_bucket
+        self.prefix = prefix
+        self.gcp_conn_id = gcp_conn_id
+        self.google_impersonation_chain = google_impersonation_chain
+        self.container_name = container_name
+        self.blob_prefix = blob_prefix
+        self.wasb_conn_id = wasb_conn_id
+        self.replace = replace
+        self.keep_directory_structure = keep_directory_structure
+        self.flatten_structure = flatten_structure
+        self.gcp_user_project = gcp_user_project
+        self.create_container = create_container
+
+        if self.flatten_structure and self.keep_directory_structure:
+            self.log.warning("flatten_structure=True takes precedence over 
keep_directory_structure=True")
+
+        try:
+            from airflow.providers.google import __version__ as 
_GOOGLE_PROVIDER_VERSION
+
+            if Version(Version(_GOOGLE_PROVIDER_VERSION).base_version) >= 
Version("10.3.0"):
+                self.__is_match_glob_supported = True
+            else:
+                self.__is_match_glob_supported = False
+        except ImportError:
+            self.__is_match_glob_supported = False
+        if not self.__is_match_glob_supported and match_glob:
+            raise ValueError("The 'match_glob' parameter requires 
'apache-airflow-providers-google>=10.3.0'.")
+        self.match_glob = match_glob
+
+    def _transform_file_path(self, file_path: str) -> str:
+        """
+        Transform the GCS file path according to the specified options.
+
+        :param file_path: The original GCS file path
+        :return: The transformed file path for Azure Blob destination
+        """
+        if self.flatten_structure:
+            return os.path.basename(file_path)
+        return file_path
+
+    @staticmethod
+    def _should_skip_gcs_object(name: str) -> bool:
+        """
+        Return True if this object name should not be copied.
+
+        The GCS console creates zero-byte "folder" markers whose keys end with 
``/``.
+        Those yield an empty basename when ``flatten_structure=True`` and odd 
blob paths
+        on Azure when copied as-is.
+        """
+        if not name or not name.strip():
+            return True
+        return name.endswith("/")
+
+    def execute(self, context: Context) -> list[str]:
+        gcs_hook = GCSHook(
+            gcp_conn_id=self.gcp_conn_id,
+            impersonation_chain=self.google_impersonation_chain,
+        )
+        wasb_hook = WasbHook(wasb_conn_id=self.wasb_conn_id)
+
+        self.log.info(
+            "Getting list of the files. Bucket: %s; Prefix: %s",
+            self.gcs_bucket,
+            self.prefix,
+        )
+
+        list_kwargs: dict = {
+            "bucket_name": self.gcs_bucket,
+            "prefix": self.prefix,
+            "user_project": self.gcp_user_project,
+        }
+        if self.__is_match_glob_supported:
+            list_kwargs["match_glob"] = self.match_glob
+
+        gcs_files = gcs_hook.list(**list_kwargs)  # type: ignore[call-arg]
+
+        gcs_files = [
+            f for f in gcs_files if not self._should_skip_gcs_object(f) and 
self._transform_file_path(f)
+        ]
+
+        if not self.keep_directory_structure and self.prefix and not 
self.flatten_structure:
+            self.blob_prefix = os.path.join(self.blob_prefix, self.prefix)
+
+        if not self.replace:
+            existing_blobs = wasb_hook.get_blobs_list_recursive(
+                container_name=self.container_name,
+                prefix=self.blob_prefix or None,
+            )
+            existing_blobs = existing_blobs or []
+            if self.blob_prefix:
+                prefix_str = self.blob_prefix.rstrip("/") + "/"
+                existing_blobs = [b.replace(prefix_str, "", 1) for b in 
existing_blobs]
+
+            existing_blobs_set = set(existing_blobs)
+            filtered_files = []
+            seen_transformed = set()
+
+            for file in gcs_files:
+                transformed = self._transform_file_path(file)
+                if transformed not in existing_blobs_set and transformed not 
in seen_transformed:
+                    filtered_files.append(file)
+                    seen_transformed.add(transformed)
+                elif transformed in seen_transformed:
+                    self.log.warning(
+                        "Skipping duplicate file %s (transforms to %s)",
+                        file,
+                        transformed,
+                    )
+
+            gcs_files = filtered_files
+
+        uploaded_blobs: list[str] = []
+        if gcs_files:
+            for file in gcs_files:
+                with gcs_hook.provide_file(
+                    object_name=file, bucket_name=str(self.gcs_bucket), 
user_project=self.gcp_user_project
+                ) as local_tmp_file:
+                    transformed_path = self._transform_file_path(file)
+                    dest_blob = os.path.join(self.blob_prefix, 
transformed_path)

Review Comment:
   Azure blob names are always `/`-separated, but `os.path.join` uses `\` on 
Windows. The unit tests work around this by `.replace("\\", "/")`-normalizing 
every assertion (see `_norm_paths`, `_expected_blob_paths`, and 
`str(kw["blob_name"]).replace("\\", "/")` in `test_flatten_structure`) — that's 
pinning the broken Windows behavior rather than asserting correct output.
   
   Fix: add `import posixpath` at the top of the file and use 
`posixpath.join(...)` here (and at line 190 if you keep a join there). Then 
drop the `\\`-normalization helpers in the tests so they assert exact strings.



##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/transfers/gcs_to_wasb.py:
##########
@@ -0,0 +1,258 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""This module contains Google Cloud Storage to Azure Blob Storage operator."""
+
+from __future__ import annotations
+
+import os
+from collections.abc import Sequence
+from typing import TYPE_CHECKING
+
+from packaging.version import Version
+
+from airflow.providers.common.compat.sdk import BaseOperator
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+try:
+    from airflow.providers.google.cloud.hooks.gcs import GCSHook
+except ModuleNotFoundError as e:
+    from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
+
+    raise AirflowOptionalProviderFeatureException(e)
+
+if TYPE_CHECKING:
+    from airflow.providers.openlineage.extractors import OperatorLineage
+    from airflow.sdk import Context
+
+
+class GCSToAzureBlobStorageOperator(BaseOperator):
+    """
+    Synchronizes objects from a Google Cloud Storage bucket to Azure Blob 
Storage.
+
+    .. note::
+        When ``flatten_structure=True``, it takes precedence over 
``keep_directory_structure``.
+        For example, with ``flatten_structure=True``, 
``folder/subfolder/file.txt`` becomes
+        ``file.txt`` regardless of the ``keep_directory_structure`` setting.
+
+        Objects whose names end with ``/`` (GCS console folder markers) and 
keys that become an
+        empty destination path after ``flatten_structure`` are skipped.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:GCSToAzureBlobStorageOperator`
+
+    :param gcs_bucket: The GCS bucket to list objects from. (templated)
+    :param prefix: Prefix to filter object names under the bucket. (templated)
+    :param gcp_conn_id: Airflow connection ID for Google Cloud.
+    :param google_impersonation_chain: Optional impersonation chain for GCP 
credentials.
+    :param gcp_user_project: Requester-pays billing project for GCS requests, 
if required.
+    :param match_glob: Optional glob filter for object names (requires
+        ``apache-airflow-providers-google>=10.3.0``).
+    :param container_name: Azure Blob container to upload into. (templated)
+    :param blob_prefix: Base blob path for uploaded objects. (templated)
+    :param wasb_conn_id: Airflow connection ID for Azure Blob Storage.
+    :param replace: If ``True``, overwrite existing blobs (``overwrite=True`` 
on upload) and
+        upload all listed objects. If ``False``, skip objects that already 
exist under
+        ``blob_prefix`` with the same relative path and pass 
``overwrite=False`` on upload.
+    :param keep_directory_structure: When ``False`` and ``prefix`` is set (and
+        ``flatten_structure`` is ``False``), append ``prefix`` to 
``blob_prefix``.
+    :param flatten_structure: If ``True``, upload each object using only its 
file name
+        under ``blob_prefix``. Takes precedence over 
``keep_directory_structure``.
+    :param create_container: If ``True``, create the container when missing 
before upload.
+    """
+
+    template_fields: Sequence[str] = (
+        "gcs_bucket",
+        "prefix",
+        "blob_prefix",
+        "container_name",
+        "google_impersonation_chain",
+        "gcp_user_project",
+        "match_glob",
+    )
+    ui_color = "#f0eee4"
+
+    def __init__(
+        self,
+        *,
+        gcs_bucket: str,
+        container_name: str,
+        blob_prefix: str = "",
+        prefix: str | None = None,
+        gcp_conn_id: str = "google_cloud_default",
+        google_impersonation_chain: str | Sequence[str] | None = None,
+        wasb_conn_id: str = "wasb_default",
+        replace: bool = False,
+        keep_directory_structure: bool = True,
+        flatten_structure: bool = False,
+        match_glob: str | None = None,
+        gcp_user_project: str | None = None,
+        create_container: bool = False,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.gcs_bucket = gcs_bucket
+        self.prefix = prefix
+        self.gcp_conn_id = gcp_conn_id
+        self.google_impersonation_chain = google_impersonation_chain
+        self.container_name = container_name
+        self.blob_prefix = blob_prefix
+        self.wasb_conn_id = wasb_conn_id
+        self.replace = replace
+        self.keep_directory_structure = keep_directory_structure
+        self.flatten_structure = flatten_structure
+        self.gcp_user_project = gcp_user_project
+        self.create_container = create_container
+
+        if self.flatten_structure and self.keep_directory_structure:
+            self.log.warning("flatten_structure=True takes precedence over 
keep_directory_structure=True")
+
+        try:
+            from airflow.providers.google import __version__ as 
_GOOGLE_PROVIDER_VERSION
+
+            if Version(Version(_GOOGLE_PROVIDER_VERSION).base_version) >= 
Version("10.3.0"):
+                self.__is_match_glob_supported = True
+            else:
+                self.__is_match_glob_supported = False
+        except ImportError:
+            self.__is_match_glob_supported = False
+        if not self.__is_match_glob_supported and match_glob:
+            raise ValueError("The 'match_glob' parameter requires 
'apache-airflow-providers-google>=10.3.0'.")
+        self.match_glob = match_glob
+
+    def _transform_file_path(self, file_path: str) -> str:
+        """
+        Transform the GCS file path according to the specified options.
+
+        :param file_path: The original GCS file path
+        :return: The transformed file path for Azure Blob destination
+        """
+        if self.flatten_structure:
+            return os.path.basename(file_path)
+        return file_path
+
+    @staticmethod
+    def _should_skip_gcs_object(name: str) -> bool:
+        """
+        Return True if this object name should not be copied.
+
+        The GCS console creates zero-byte "folder" markers whose keys end with 
``/``.
+        Those yield an empty basename when ``flatten_structure=True`` and odd 
blob paths
+        on Azure when copied as-is.
+        """
+        if not name or not name.strip():
+            return True
+        return name.endswith("/")
+
+    def execute(self, context: Context) -> list[str]:
+        gcs_hook = GCSHook(
+            gcp_conn_id=self.gcp_conn_id,
+            impersonation_chain=self.google_impersonation_chain,
+        )
+        wasb_hook = WasbHook(wasb_conn_id=self.wasb_conn_id)
+
+        self.log.info(
+            "Getting list of the files. Bucket: %s; Prefix: %s",
+            self.gcs_bucket,
+            self.prefix,
+        )
+
+        list_kwargs: dict = {
+            "bucket_name": self.gcs_bucket,
+            "prefix": self.prefix,
+            "user_project": self.gcp_user_project,
+        }
+        if self.__is_match_glob_supported:
+            list_kwargs["match_glob"] = self.match_glob
+
+        gcs_files = gcs_hook.list(**list_kwargs)  # type: ignore[call-arg]
+
+        gcs_files = [
+            f for f in gcs_files if not self._should_skip_gcs_object(f) and 
self._transform_file_path(f)
+        ]
+
+        if not self.keep_directory_structure and self.prefix and not 
self.flatten_structure:
+            self.blob_prefix = os.path.join(self.blob_prefix, self.prefix)
+
+        if not self.replace:
+            existing_blobs = wasb_hook.get_blobs_list_recursive(
+                container_name=self.container_name,
+                prefix=self.blob_prefix or None,
+            )
+            existing_blobs = existing_blobs or []
+            if self.blob_prefix:
+                prefix_str = self.blob_prefix.rstrip("/") + "/"
+                existing_blobs = [b.replace(prefix_str, "", 1) for b in 
existing_blobs]
+
+            existing_blobs_set = set(existing_blobs)
+            filtered_files = []
+            seen_transformed = set()
+
+            for file in gcs_files:
+                transformed = self._transform_file_path(file)
+                if transformed not in existing_blobs_set and transformed not 
in seen_transformed:
+                    filtered_files.append(file)
+                    seen_transformed.add(transformed)
+                elif transformed in seen_transformed:
+                    self.log.warning(
+                        "Skipping duplicate file %s (transforms to %s)",
+                        file,
+                        transformed,
+                    )

Review Comment:
   The `seen_transformed` dedup only runs when `replace=False`. With 
`replace=True` and `flatten_structure=True`, two GCS objects that collapse to 
the same name (`a/file.txt` + `b/file.txt` → `file.txt`) both upload and the 
second silently overwrites the first — no warning logged. Either dedup 
unconditionally or emit the duplicate warning in both branches. A unit test for 
the collision case under `replace=True` would catch this.



##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/transfers/gcs_to_wasb.py:
##########
@@ -0,0 +1,258 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""This module contains Google Cloud Storage to Azure Blob Storage operator."""
+
+from __future__ import annotations
+
+import os
+from collections.abc import Sequence
+from typing import TYPE_CHECKING
+
+from packaging.version import Version
+
+from airflow.providers.common.compat.sdk import BaseOperator
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+try:
+    from airflow.providers.google.cloud.hooks.gcs import GCSHook
+except ModuleNotFoundError as e:
+    from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
+
+    raise AirflowOptionalProviderFeatureException(e)
+
+if TYPE_CHECKING:
+    from airflow.providers.openlineage.extractors import OperatorLineage
+    from airflow.sdk import Context
+
+
+class GCSToAzureBlobStorageOperator(BaseOperator):
+    """
+    Synchronizes objects from a Google Cloud Storage bucket to Azure Blob 
Storage.
+
+    .. note::
+        When ``flatten_structure=True``, it takes precedence over 
``keep_directory_structure``.
+        For example, with ``flatten_structure=True``, 
``folder/subfolder/file.txt`` becomes
+        ``file.txt`` regardless of the ``keep_directory_structure`` setting.
+
+        Objects whose names end with ``/`` (GCS console folder markers) and 
keys that become an
+        empty destination path after ``flatten_structure`` are skipped.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:GCSToAzureBlobStorageOperator`
+
+    :param gcs_bucket: The GCS bucket to list objects from. (templated)
+    :param prefix: Prefix to filter object names under the bucket. (templated)
+    :param gcp_conn_id: Airflow connection ID for Google Cloud.
+    :param google_impersonation_chain: Optional impersonation chain for GCP 
credentials.
+    :param gcp_user_project: Requester-pays billing project for GCS requests, 
if required.
+    :param match_glob: Optional glob filter for object names (requires
+        ``apache-airflow-providers-google>=10.3.0``).
+    :param container_name: Azure Blob container to upload into. (templated)
+    :param blob_prefix: Base blob path for uploaded objects. (templated)
+    :param wasb_conn_id: Airflow connection ID for Azure Blob Storage.
+    :param replace: If ``True``, overwrite existing blobs (``overwrite=True`` 
on upload) and
+        upload all listed objects. If ``False``, skip objects that already 
exist under
+        ``blob_prefix`` with the same relative path and pass 
``overwrite=False`` on upload.
+    :param keep_directory_structure: When ``False`` and ``prefix`` is set (and
+        ``flatten_structure`` is ``False``), append ``prefix`` to 
``blob_prefix``.
+    :param flatten_structure: If ``True``, upload each object using only its 
file name
+        under ``blob_prefix``. Takes precedence over 
``keep_directory_structure``.
+    :param create_container: If ``True``, create the container when missing 
before upload.
+    """
+
+    template_fields: Sequence[str] = (
+        "gcs_bucket",
+        "prefix",
+        "blob_prefix",
+        "container_name",
+        "google_impersonation_chain",
+        "gcp_user_project",
+        "match_glob",
+    )
+    ui_color = "#f0eee4"
+
+    def __init__(
+        self,
+        *,
+        gcs_bucket: str,
+        container_name: str,
+        blob_prefix: str = "",
+        prefix: str | None = None,
+        gcp_conn_id: str = "google_cloud_default",
+        google_impersonation_chain: str | Sequence[str] | None = None,
+        wasb_conn_id: str = "wasb_default",
+        replace: bool = False,
+        keep_directory_structure: bool = True,
+        flatten_structure: bool = False,
+        match_glob: str | None = None,
+        gcp_user_project: str | None = None,
+        create_container: bool = False,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.gcs_bucket = gcs_bucket
+        self.prefix = prefix
+        self.gcp_conn_id = gcp_conn_id
+        self.google_impersonation_chain = google_impersonation_chain
+        self.container_name = container_name
+        self.blob_prefix = blob_prefix
+        self.wasb_conn_id = wasb_conn_id
+        self.replace = replace
+        self.keep_directory_structure = keep_directory_structure
+        self.flatten_structure = flatten_structure
+        self.gcp_user_project = gcp_user_project
+        self.create_container = create_container
+
+        if self.flatten_structure and self.keep_directory_structure:
+            self.log.warning("flatten_structure=True takes precedence over 
keep_directory_structure=True")
+
+        try:
+            from airflow.providers.google import __version__ as 
_GOOGLE_PROVIDER_VERSION
+
+            if Version(Version(_GOOGLE_PROVIDER_VERSION).base_version) >= 
Version("10.3.0"):
+                self.__is_match_glob_supported = True
+            else:
+                self.__is_match_glob_supported = False
+        except ImportError:
+            self.__is_match_glob_supported = False
+        if not self.__is_match_glob_supported and match_glob:
+            raise ValueError("The 'match_glob' parameter requires 
'apache-airflow-providers-google>=10.3.0'.")
+        self.match_glob = match_glob
+
+    def _transform_file_path(self, file_path: str) -> str:
+        """
+        Transform the GCS file path according to the specified options.
+
+        :param file_path: The original GCS file path
+        :return: The transformed file path for Azure Blob destination
+        """
+        if self.flatten_structure:
+            return os.path.basename(file_path)
+        return file_path
+
+    @staticmethod
+    def _should_skip_gcs_object(name: str) -> bool:
+        """
+        Return True if this object name should not be copied.
+
+        The GCS console creates zero-byte "folder" markers whose keys end with 
``/``.
+        Those yield an empty basename when ``flatten_structure=True`` and odd 
blob paths
+        on Azure when copied as-is.
+        """
+        if not name or not name.strip():
+            return True
+        return name.endswith("/")
+
+    def execute(self, context: Context) -> list[str]:
+        gcs_hook = GCSHook(
+            gcp_conn_id=self.gcp_conn_id,
+            impersonation_chain=self.google_impersonation_chain,
+        )
+        wasb_hook = WasbHook(wasb_conn_id=self.wasb_conn_id)
+
+        self.log.info(
+            "Getting list of the files. Bucket: %s; Prefix: %s",
+            self.gcs_bucket,
+            self.prefix,
+        )
+
+        list_kwargs: dict = {
+            "bucket_name": self.gcs_bucket,
+            "prefix": self.prefix,
+            "user_project": self.gcp_user_project,
+        }
+        if self.__is_match_glob_supported:
+            list_kwargs["match_glob"] = self.match_glob
+
+        gcs_files = gcs_hook.list(**list_kwargs)  # type: ignore[call-arg]
+
+        gcs_files = [
+            f for f in gcs_files if not self._should_skip_gcs_object(f) and 
self._transform_file_path(f)

Review Comment:
   Question: the `and self._transform_file_path(f)` clause looks like a 
belt-and-braces guard against an empty result. The only way 
`_transform_file_path` returns falsy is when `flatten_structure=True` and 
`os.path.basename(f)` is empty — but that requires `f.endswith("/")`, which 
`_should_skip_gcs_object` already filters out. Either drop the redundant clause 
or add a comment naming the case it defends against.



##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/transfers/gcs_to_wasb.py:
##########
@@ -0,0 +1,258 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""This module contains Google Cloud Storage to Azure Blob Storage operator."""
+
+from __future__ import annotations
+
+import os
+from collections.abc import Sequence
+from typing import TYPE_CHECKING
+
+from packaging.version import Version
+
+from airflow.providers.common.compat.sdk import BaseOperator
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+try:
+    from airflow.providers.google.cloud.hooks.gcs import GCSHook
+except ModuleNotFoundError as e:
+    from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
+
+    raise AirflowOptionalProviderFeatureException(e)
+
+if TYPE_CHECKING:
+    from airflow.providers.openlineage.extractors import OperatorLineage
+    from airflow.sdk import Context
+
+
+class GCSToAzureBlobStorageOperator(BaseOperator):
+    """
+    Synchronizes objects from a Google Cloud Storage bucket to Azure Blob 
Storage.
+
+    .. note::
+        When ``flatten_structure=True``, it takes precedence over 
``keep_directory_structure``.
+        For example, with ``flatten_structure=True``, 
``folder/subfolder/file.txt`` becomes
+        ``file.txt`` regardless of the ``keep_directory_structure`` setting.
+
+        Objects whose names end with ``/`` (GCS console folder markers) and 
keys that become an
+        empty destination path after ``flatten_structure`` are skipped.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:GCSToAzureBlobStorageOperator`
+
+    :param gcs_bucket: The GCS bucket to list objects from. (templated)
+    :param prefix: Prefix to filter object names under the bucket. (templated)
+    :param gcp_conn_id: Airflow connection ID for Google Cloud.
+    :param google_impersonation_chain: Optional impersonation chain for GCP 
credentials.
+    :param gcp_user_project: Requester-pays billing project for GCS requests, 
if required.
+    :param match_glob: Optional glob filter for object names (requires
+        ``apache-airflow-providers-google>=10.3.0``).
+    :param container_name: Azure Blob container to upload into. (templated)
+    :param blob_prefix: Base blob path for uploaded objects. (templated)
+    :param wasb_conn_id: Airflow connection ID for Azure Blob Storage.
+    :param replace: If ``True``, overwrite existing blobs (``overwrite=True`` 
on upload) and
+        upload all listed objects. If ``False``, skip objects that already 
exist under
+        ``blob_prefix`` with the same relative path and pass 
``overwrite=False`` on upload.
+    :param keep_directory_structure: When ``False`` and ``prefix`` is set (and
+        ``flatten_structure`` is ``False``), append ``prefix`` to 
``blob_prefix``.
+    :param flatten_structure: If ``True``, upload each object using only its 
file name
+        under ``blob_prefix``. Takes precedence over 
``keep_directory_structure``.
+    :param create_container: If ``True``, create the container when missing 
before upload.
+    """
+
+    template_fields: Sequence[str] = (
+        "gcs_bucket",
+        "prefix",
+        "blob_prefix",
+        "container_name",
+        "google_impersonation_chain",
+        "gcp_user_project",
+        "match_glob",
+    )
+    ui_color = "#f0eee4"
+
+    def __init__(
+        self,
+        *,
+        gcs_bucket: str,
+        container_name: str,
+        blob_prefix: str = "",
+        prefix: str | None = None,
+        gcp_conn_id: str = "google_cloud_default",
+        google_impersonation_chain: str | Sequence[str] | None = None,
+        wasb_conn_id: str = "wasb_default",
+        replace: bool = False,
+        keep_directory_structure: bool = True,
+        flatten_structure: bool = False,
+        match_glob: str | None = None,
+        gcp_user_project: str | None = None,
+        create_container: bool = False,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.gcs_bucket = gcs_bucket
+        self.prefix = prefix
+        self.gcp_conn_id = gcp_conn_id
+        self.google_impersonation_chain = google_impersonation_chain
+        self.container_name = container_name
+        self.blob_prefix = blob_prefix
+        self.wasb_conn_id = wasb_conn_id
+        self.replace = replace
+        self.keep_directory_structure = keep_directory_structure
+        self.flatten_structure = flatten_structure
+        self.gcp_user_project = gcp_user_project
+        self.create_container = create_container
+
+        if self.flatten_structure and self.keep_directory_structure:
+            self.log.warning("flatten_structure=True takes precedence over 
keep_directory_structure=True")
+
+        try:
+            from airflow.providers.google import __version__ as 
_GOOGLE_PROVIDER_VERSION
+
+            if Version(Version(_GOOGLE_PROVIDER_VERSION).base_version) >= 
Version("10.3.0"):

Review Comment:
   `Version(Version(...).base_version)` is redundant — `packaging.Version` 
already orders pre-release tags correctly, so the inner 
`Version().base_version` round-trip can be dropped:
   
   ```suggestion
               if Version(_GOOGLE_PROVIDER_VERSION) >= Version("10.3.0"):
   ```



##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/transfers/gcs_to_wasb.py:
##########
@@ -0,0 +1,258 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""This module contains Google Cloud Storage to Azure Blob Storage operator."""
+
+from __future__ import annotations
+
+import os
+from collections.abc import Sequence
+from typing import TYPE_CHECKING
+
+from packaging.version import Version
+
+from airflow.providers.common.compat.sdk import BaseOperator
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+try:
+    from airflow.providers.google.cloud.hooks.gcs import GCSHook
+except ModuleNotFoundError as e:
+    from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
+
+    raise AirflowOptionalProviderFeatureException(e)
+
+if TYPE_CHECKING:
+    from airflow.providers.openlineage.extractors import OperatorLineage
+    from airflow.sdk import Context
+
+
+class GCSToAzureBlobStorageOperator(BaseOperator):
+    """
+    Synchronizes objects from a Google Cloud Storage bucket to Azure Blob 
Storage.
+
+    .. note::
+        When ``flatten_structure=True``, it takes precedence over 
``keep_directory_structure``.
+        For example, with ``flatten_structure=True``, 
``folder/subfolder/file.txt`` becomes
+        ``file.txt`` regardless of the ``keep_directory_structure`` setting.
+
+        Objects whose names end with ``/`` (GCS console folder markers) and 
keys that become an
+        empty destination path after ``flatten_structure`` are skipped.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:GCSToAzureBlobStorageOperator`
+
+    :param gcs_bucket: The GCS bucket to list objects from. (templated)
+    :param prefix: Prefix to filter object names under the bucket. (templated)
+    :param gcp_conn_id: Airflow connection ID for Google Cloud.
+    :param google_impersonation_chain: Optional impersonation chain for GCP 
credentials.
+    :param gcp_user_project: Requester-pays billing project for GCS requests, 
if required.
+    :param match_glob: Optional glob filter for object names (requires
+        ``apache-airflow-providers-google>=10.3.0``).
+    :param container_name: Azure Blob container to upload into. (templated)
+    :param blob_prefix: Base blob path for uploaded objects. (templated)
+    :param wasb_conn_id: Airflow connection ID for Azure Blob Storage.
+    :param replace: If ``True``, overwrite existing blobs (``overwrite=True`` 
on upload) and
+        upload all listed objects. If ``False``, skip objects that already 
exist under
+        ``blob_prefix`` with the same relative path and pass 
``overwrite=False`` on upload.
+    :param keep_directory_structure: When ``False`` and ``prefix`` is set (and
+        ``flatten_structure`` is ``False``), append ``prefix`` to 
``blob_prefix``.
+    :param flatten_structure: If ``True``, upload each object using only its 
file name
+        under ``blob_prefix``. Takes precedence over 
``keep_directory_structure``.
+    :param create_container: If ``True``, create the container when missing 
before upload.
+    """
+
+    template_fields: Sequence[str] = (
+        "gcs_bucket",
+        "prefix",
+        "blob_prefix",
+        "container_name",
+        "google_impersonation_chain",
+        "gcp_user_project",
+        "match_glob",
+    )
+    ui_color = "#f0eee4"
+
+    def __init__(
+        self,
+        *,
+        gcs_bucket: str,
+        container_name: str,
+        blob_prefix: str = "",
+        prefix: str | None = None,
+        gcp_conn_id: str = "google_cloud_default",
+        google_impersonation_chain: str | Sequence[str] | None = None,
+        wasb_conn_id: str = "wasb_default",
+        replace: bool = False,
+        keep_directory_structure: bool = True,
+        flatten_structure: bool = False,
+        match_glob: str | None = None,
+        gcp_user_project: str | None = None,
+        create_container: bool = False,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.gcs_bucket = gcs_bucket
+        self.prefix = prefix
+        self.gcp_conn_id = gcp_conn_id
+        self.google_impersonation_chain = google_impersonation_chain
+        self.container_name = container_name
+        self.blob_prefix = blob_prefix
+        self.wasb_conn_id = wasb_conn_id
+        self.replace = replace
+        self.keep_directory_structure = keep_directory_structure
+        self.flatten_structure = flatten_structure
+        self.gcp_user_project = gcp_user_project
+        self.create_container = create_container
+
+        if self.flatten_structure and self.keep_directory_structure:
+            self.log.warning("flatten_structure=True takes precedence over 
keep_directory_structure=True")
+
+        try:
+            from airflow.providers.google import __version__ as 
_GOOGLE_PROVIDER_VERSION
+
+            if Version(Version(_GOOGLE_PROVIDER_VERSION).base_version) >= 
Version("10.3.0"):
+                self.__is_match_glob_supported = True
+            else:
+                self.__is_match_glob_supported = False
+        except ImportError:
+            self.__is_match_glob_supported = False

Review Comment:
   `self.__is_match_glob_supported` (two leading underscores) triggers Python 
name-mangling — at compile time the attribute becomes 
`self._GCSToAzureBlobStorageOperator__is_match_glob_supported`. Inside this 
class everything works, but it makes subclassing surprising and breaks the 
project convention of single-underscore for internal attrs.
   
   Recommend renaming to `self._is_match_glob_supported` here **and** at the 
read-site in `execute()` (currently line 180: `if 
self.__is_match_glob_supported:`).



##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/transfers/gcs_to_wasb.py:
##########
@@ -0,0 +1,258 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""This module contains Google Cloud Storage to Azure Blob Storage operator."""
+
+from __future__ import annotations
+
+import os
+from collections.abc import Sequence
+from typing import TYPE_CHECKING
+
+from packaging.version import Version
+
+from airflow.providers.common.compat.sdk import BaseOperator
+from airflow.providers.microsoft.azure.hooks.wasb import WasbHook
+
+try:
+    from airflow.providers.google.cloud.hooks.gcs import GCSHook
+except ModuleNotFoundError as e:
+    from airflow.providers.common.compat.sdk import 
AirflowOptionalProviderFeatureException
+
+    raise AirflowOptionalProviderFeatureException(e)
+
+if TYPE_CHECKING:
+    from airflow.providers.openlineage.extractors import OperatorLineage
+    from airflow.sdk import Context
+
+
+class GCSToAzureBlobStorageOperator(BaseOperator):
+    """
+    Synchronizes objects from a Google Cloud Storage bucket to Azure Blob 
Storage.
+
+    .. note::
+        When ``flatten_structure=True``, it takes precedence over 
``keep_directory_structure``.
+        For example, with ``flatten_structure=True``, 
``folder/subfolder/file.txt`` becomes
+        ``file.txt`` regardless of the ``keep_directory_structure`` setting.
+
+        Objects whose names end with ``/`` (GCS console folder markers) and 
keys that become an
+        empty destination path after ``flatten_structure`` are skipped.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:GCSToAzureBlobStorageOperator`
+
+    :param gcs_bucket: The GCS bucket to list objects from. (templated)
+    :param prefix: Prefix to filter object names under the bucket. (templated)
+    :param gcp_conn_id: Airflow connection ID for Google Cloud.
+    :param google_impersonation_chain: Optional impersonation chain for GCP 
credentials.
+    :param gcp_user_project: Requester-pays billing project for GCS requests, 
if required.
+    :param match_glob: Optional glob filter for object names (requires
+        ``apache-airflow-providers-google>=10.3.0``).
+    :param container_name: Azure Blob container to upload into. (templated)
+    :param blob_prefix: Base blob path for uploaded objects. (templated)
+    :param wasb_conn_id: Airflow connection ID for Azure Blob Storage.
+    :param replace: If ``True``, overwrite existing blobs (``overwrite=True`` 
on upload) and
+        upload all listed objects. If ``False``, skip objects that already 
exist under
+        ``blob_prefix`` with the same relative path and pass 
``overwrite=False`` on upload.
+    :param keep_directory_structure: When ``False`` and ``prefix`` is set (and
+        ``flatten_structure`` is ``False``), append ``prefix`` to 
``blob_prefix``.
+    :param flatten_structure: If ``True``, upload each object using only its 
file name
+        under ``blob_prefix``. Takes precedence over 
``keep_directory_structure``.
+    :param create_container: If ``True``, create the container when missing 
before upload.
+    """
+
+    template_fields: Sequence[str] = (
+        "gcs_bucket",
+        "prefix",
+        "blob_prefix",
+        "container_name",
+        "google_impersonation_chain",
+        "gcp_user_project",
+        "match_glob",
+    )
+    ui_color = "#f0eee4"
+
+    def __init__(
+        self,
+        *,
+        gcs_bucket: str,
+        container_name: str,
+        blob_prefix: str = "",
+        prefix: str | None = None,
+        gcp_conn_id: str = "google_cloud_default",
+        google_impersonation_chain: str | Sequence[str] | None = None,
+        wasb_conn_id: str = "wasb_default",
+        replace: bool = False,
+        keep_directory_structure: bool = True,
+        flatten_structure: bool = False,
+        match_glob: str | None = None,
+        gcp_user_project: str | None = None,
+        create_container: bool = False,
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.gcs_bucket = gcs_bucket
+        self.prefix = prefix
+        self.gcp_conn_id = gcp_conn_id
+        self.google_impersonation_chain = google_impersonation_chain
+        self.container_name = container_name
+        self.blob_prefix = blob_prefix
+        self.wasb_conn_id = wasb_conn_id
+        self.replace = replace
+        self.keep_directory_structure = keep_directory_structure
+        self.flatten_structure = flatten_structure
+        self.gcp_user_project = gcp_user_project
+        self.create_container = create_container
+
+        if self.flatten_structure and self.keep_directory_structure:
+            self.log.warning("flatten_structure=True takes precedence over 
keep_directory_structure=True")
+
+        try:
+            from airflow.providers.google import __version__ as 
_GOOGLE_PROVIDER_VERSION
+
+            if Version(Version(_GOOGLE_PROVIDER_VERSION).base_version) >= 
Version("10.3.0"):
+                self.__is_match_glob_supported = True
+            else:
+                self.__is_match_glob_supported = False
+        except ImportError:
+            self.__is_match_glob_supported = False
+        if not self.__is_match_glob_supported and match_glob:
+            raise ValueError("The 'match_glob' parameter requires 
'apache-airflow-providers-google>=10.3.0'.")
+        self.match_glob = match_glob
+
+    def _transform_file_path(self, file_path: str) -> str:
+        """
+        Transform the GCS file path according to the specified options.
+
+        :param file_path: The original GCS file path
+        :return: The transformed file path for Azure Blob destination
+        """
+        if self.flatten_structure:
+            return os.path.basename(file_path)
+        return file_path
+
+    @staticmethod
+    def _should_skip_gcs_object(name: str) -> bool:
+        """
+        Return True if this object name should not be copied.
+
+        The GCS console creates zero-byte "folder" markers whose keys end with 
``/``.
+        Those yield an empty basename when ``flatten_structure=True`` and odd 
blob paths
+        on Azure when copied as-is.
+        """
+        if not name or not name.strip():
+            return True
+        return name.endswith("/")
+
+    def execute(self, context: Context) -> list[str]:
+        gcs_hook = GCSHook(
+            gcp_conn_id=self.gcp_conn_id,
+            impersonation_chain=self.google_impersonation_chain,
+        )
+        wasb_hook = WasbHook(wasb_conn_id=self.wasb_conn_id)
+
+        self.log.info(
+            "Getting list of the files. Bucket: %s; Prefix: %s",
+            self.gcs_bucket,
+            self.prefix,
+        )
+
+        list_kwargs: dict = {
+            "bucket_name": self.gcs_bucket,
+            "prefix": self.prefix,
+            "user_project": self.gcp_user_project,
+        }
+        if self.__is_match_glob_supported:
+            list_kwargs["match_glob"] = self.match_glob
+
+        gcs_files = gcs_hook.list(**list_kwargs)  # type: ignore[call-arg]
+
+        gcs_files = [
+            f for f in gcs_files if not self._should_skip_gcs_object(f) and 
self._transform_file_path(f)
+        ]
+
+        if not self.keep_directory_structure and self.prefix and not 
self.flatten_structure:
+            self.blob_prefix = os.path.join(self.blob_prefix, self.prefix)

Review Comment:
   **Mutation of `self.blob_prefix` will break on retry.** On a second 
`execute()` call (task retry, deferred restart, etc.) `self.blob_prefix` 
already contains `self.prefix`, so the second attempt builds paths like 
`dest/prefix/data/data/file.txt`.
   
   Fix is to thread a local variable through the rest of `execute()`:
   
   ```python
   blob_prefix = self.blob_prefix
   if not self.keep_directory_structure and self.prefix and not 
self.flatten_structure:
       blob_prefix = os.path.join(blob_prefix, self.prefix)
   ```
   
   Then use `blob_prefix` (not `self.blob_prefix`) for the 
`get_blobs_list_recursive` call (line 196), the `prefix_str` derivation (line 
199), and the `dest_blob` construction (line 227). Worth adding a unit test 
that calls `execute()` twice on the same operator instance to pin this.



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to