You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2026/05/20 16:21:42 UTC

(arrow-rs-object-store) branch main updated: GCP: fix copy (no) overwrite semantics (#713)

This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs-object-store.git


The following commit(s) were added to refs/heads/main by this push:
     new 994d607  GCP: fix copy (no) overwrite semantics (#713)
994d607 is described below

commit 994d60732c3379bc98982f5c4638996be0ee0d2f
Author: james-rms <ja...@foxglove.dev>
AuthorDate: Thu May 21 02:21:36 2026 +1000

    GCP: fix copy (no) overwrite semantics (#713)
---
 src/gcp/client.rs | 16 ++++++++--------
 src/gcp/mod.rs    |  7 ++-----
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/gcp/client.rs b/src/gcp/client.rs
index 00d3168..4a246d2 100644
--- a/src/gcp/client.rs
+++ b/src/gcp/client.rs
@@ -32,8 +32,8 @@ use crate::multipart::PartId;
 use crate::path::Path;
 use crate::util::hex_encode;
 use crate::{
-    Attribute, Attributes, ClientOptions, GetOptions, MultipartId, PutMode, PutMultipartOptions,
-    PutOptions, PutPayload, PutResult, Result, RetryConfig,
+    Attribute, Attributes, ClientOptions, CopyMode, GetOptions, MultipartId, PutMode,
+    PutMultipartOptions, PutOptions, PutPayload, PutResult, Result, RetryConfig,
 };
 use async_trait::async_trait;
 use base64::Engine;
@@ -566,12 +566,7 @@ impl GoogleCloudStorageClient {
     }
 
     /// Perform a copy request <https://cloud.google.com/storage/docs/xml-api/put-object-copy>
-    pub(crate) async fn copy_request(
-        &self,
-        from: &Path,
-        to: &Path,
-        if_not_exists: bool,
-    ) -> Result<()> {
+    pub(crate) async fn copy_request(&self, from: &Path, to: &Path, mode: CopyMode) -> Result<()> {
         let credential = self.get_credential().await?;
         let url = self.object_url(to);
 
@@ -583,6 +578,11 @@ impl GoogleCloudStorageClient {
             .request(Method::PUT, url)
             .header("x-goog-copy-source", source);
 
+        let if_not_exists = match mode {
+            CopyMode::Create => true,
+            CopyMode::Overwrite => false,
+        };
+
         if if_not_exists {
             builder = builder.header(&VERSION_MATCH, 0);
         }
diff --git a/src/gcp/mod.rs b/src/gcp/mod.rs
index 8d7b26c..51e85ae 100644
--- a/src/gcp/mod.rs
+++ b/src/gcp/mod.rs
@@ -37,10 +37,10 @@
 use std::sync::Arc;
 use std::time::Duration;
 
+use crate::CopyOptions;
 use crate::client::CredentialProvider;
 use crate::gcp::credential::GCSAuthorizer;
 use crate::signer::Signer;
-use crate::{CopyMode, CopyOptions};
 use crate::{
     GetOptions, GetResult, ListResult, MultipartId, MultipartUpload, ObjectMeta, ObjectStore,
     PutMultipartOptions, PutOptions, PutPayload, PutResult, Result, UploadPart, multipart::PartId,
@@ -221,10 +221,7 @@ impl ObjectStore for GoogleCloudStorage {
             extensions: _,
         } = options;
 
-        match mode {
-            CopyMode::Overwrite => self.client.copy_request(from, to, true).await,
-            CopyMode::Create => self.client.copy_request(from, to, false).await,
-        }
+        self.client.copy_request(from, to, mode).await
     }
 }