Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/gcp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down
7 changes: 2 additions & 5 deletions src/gcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
}

Expand Down