Skip to content
Merged
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
28 changes: 20 additions & 8 deletions src/aws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ use crate::multipart::{MultipartStore, PartId};
use crate::signer::Signer;
use crate::util::STRICT_ENCODE_SET;
use crate::{
Error, GetOptions, GetResult, ListResult, MultipartId, MultipartUpload, ObjectMeta,
ObjectStore, Path, PutMode, PutMultipartOptions, PutOptions, PutPayload, PutResult, Result,
UploadPart,
CopyMode, CopyOptions, Error, GetOptions, GetResult, ListResult, MultipartId, MultipartUpload,
ObjectMeta, ObjectStore, Path, PutMode, PutMultipartOptions, PutOptions, PutPayload, PutResult,
Result, UploadPart,
};

static TAGS_HEADER: HeaderName = HeaderName::from_static("x-amz-tagging");
Expand Down Expand Up @@ -305,18 +305,26 @@ impl ObjectStore for AmazonS3 {
self.client.list_with_delimiter(prefix).await
}

async fn copy(&self, from: &Path, to: &Path) -> Result<()> {
async fn copy_opts(&self, from: &Path, to: &Path, options: CopyOptions) -> Result<()> {
let CopyOptions {
mode,
extensions: _,
} = options;

match mode {
CopyMode::Overwrite => {
self.client
.copy_request(from, to)
.idempotent(true)
.send()
.await?;
Ok(())
}

async fn copy_if_not_exists(&self, from: &Path, to: &Path) -> Result<()> {
CopyMode::Create => {
let (k, v, status) = match &self.client.config.copy_if_not_exists {
Some(S3CopyIfNotExists::Header(k, v)) => (k, v, StatusCode::PRECONDITION_FAILED),
Some(S3CopyIfNotExists::Header(k, v)) => {
(k, v, StatusCode::PRECONDITION_FAILED)
}
Some(S3CopyIfNotExists::HeaderWithStatus(k, v, status)) => (k, v, *status),
Some(S3CopyIfNotExists::Multipart) => {
let upload_id = self
Expand Down Expand Up @@ -368,7 +376,9 @@ impl ObjectStore for AmazonS3 {

let req = self.client.copy_request(from, to);
match req.header(k, v).send().await {
Err(RequestError::Retry { source, path }) if source.status() == Some(status) => {
Err(RequestError::Retry { source, path })
if source.status() == Some(status) =>
{
Err(Error::AlreadyExists {
source: Box::new(source),
path,
Expand All @@ -379,6 +389,8 @@ impl ObjectStore for AmazonS3 {
}
}
}
}
}

#[derive(Debug)]
struct S3MultiPartUpload {
Expand Down
8 changes: 4 additions & 4 deletions src/aws/precondition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ use crate::config::Parse;

use itertools::Itertools;

/// Configure how to provide [`ObjectStore::copy_if_not_exists`] for [`AmazonS3`].
/// Configure how to provide [`CopyMode::Create`] for [`AmazonS3`].
///
/// [`ObjectStore::copy_if_not_exists`]: crate::ObjectStore::copy_if_not_exists
/// [`CopyMode::Create`]: crate::CopyMode::Create
/// [`AmazonS3`]: super::AmazonS3
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum S3CopyIfNotExists {
/// Some S3-compatible stores, such as Cloudflare R2, support copy if not exists
/// semantics through custom headers.
///
/// If set, [`ObjectStore::copy_if_not_exists`] will perform a normal copy operation
/// If set, [`CopyMode::Create`] will perform a normal copy operation
/// with the provided header pair, and expect the store to fail with `412 Precondition Failed`
/// if the destination file already exists.
///
Expand All @@ -38,7 +38,7 @@ pub enum S3CopyIfNotExists {
/// For example `header: cf-copy-destination-if-none-match: *`, would set
/// the header `cf-copy-destination-if-none-match` to `*`
///
/// [`ObjectStore::copy_if_not_exists`]: crate::ObjectStore::copy_if_not_exists
/// [`CopyMode::Create`]: crate::CopyMode::Create
Header(String, String),
/// The same as [`S3CopyIfNotExists::Header`] but allows custom status code checking, for object stores that return values
/// other than 412.
Expand Down
19 changes: 12 additions & 7 deletions src/azure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
//!
//! Unused blocks will automatically be dropped after 7 days.
use crate::{
GetOptions, GetResult, ListResult, MultipartId, MultipartUpload, ObjectMeta, ObjectStore,
PutMultipartOptions, PutOptions, PutPayload, PutResult, Result, UploadPart,
CopyMode, CopyOptions, GetOptions, GetResult, ListResult, MultipartId, MultipartUpload,
ObjectMeta, ObjectStore, PutMultipartOptions, PutOptions, PutPayload, PutResult, Result,
UploadPart,
multipart::{MultipartStore, PartId},
path::Path,
signer::Signer,
Expand Down Expand Up @@ -151,12 +152,16 @@ impl ObjectStore for MicrosoftAzure {
self.client.list_with_delimiter(prefix).await
}

async fn copy(&self, from: &Path, to: &Path) -> Result<()> {
self.client.copy_request(from, to, true).await
}
async fn copy_opts(&self, from: &Path, to: &Path, options: CopyOptions) -> Result<()> {
let CopyOptions {
mode,
extensions: _,
} = options;

async fn copy_if_not_exists(&self, from: &Path, to: &Path) -> Result<()> {
self.client.copy_request(from, to, false).await
match mode {
CopyMode::Overwrite => self.client.copy_request(from, to, true).await,
CopyMode::Create => self.client.copy_request(from, to, false).await,
}
}
}

Expand Down
12 changes: 4 additions & 8 deletions src/chunked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use futures::stream::BoxStream;

use crate::path::Path;
use crate::{
GetOptions, GetResult, GetResultPayload, ListResult, MultipartUpload, ObjectMeta, ObjectStore,
PutMultipartOptions, PutOptions, PutResult,
CopyOptions, GetOptions, GetResult, GetResultPayload, ListResult, MultipartUpload, ObjectMeta,
ObjectStore, PutMultipartOptions, PutOptions, PutResult,
};
use crate::{PutPayload, Result};

Expand Down Expand Up @@ -166,18 +166,14 @@ impl ObjectStore for ChunkedStore {
self.inner.list_with_delimiter(prefix).await
}

async fn copy(&self, from: &Path, to: &Path) -> Result<()> {
self.inner.copy(from, to).await
async fn copy_opts(&self, from: &Path, to: &Path, options: CopyOptions) -> Result<()> {
self.inner.copy_opts(from, to, options).await
}

async fn rename(&self, from: &Path, to: &Path) -> Result<()> {
self.inner.rename(from, to).await
}

async fn copy_if_not_exists(&self, from: &Path, to: &Path) -> Result<()> {
self.inner.copy_if_not_exists(from, to).await
}

async fn rename_if_not_exists(&self, from: &Path, to: &Path) -> Result<()> {
self.inner.rename_if_not_exists(from, to).await
}
Expand Down
15 changes: 10 additions & 5 deletions src/gcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use std::time::Duration;
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 @@ -218,12 +219,16 @@ impl ObjectStore for GoogleCloudStorage {
self.client.list_with_delimiter(prefix).await
}

async fn copy(&self, from: &Path, to: &Path) -> Result<()> {
self.client.copy_request(from, to, false).await
}
async fn copy_opts(&self, from: &Path, to: &Path, options: CopyOptions) -> Result<()> {
let CopyOptions {
mode,
extensions: _,
} = options;

async fn copy_if_not_exists(&self, from: &Path, to: &Path) -> Result<()> {
self.client.copy_request(from, to, true).await
match mode {
CopyMode::Overwrite => self.client.copy_request(from, to, true).await,
CopyMode::Create => self.client.copy_request(from, to, false).await,
}
}
}

Expand Down
20 changes: 12 additions & 8 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ use crate::client::{HttpConnector, http_connector};
use crate::http::client::Client;
use crate::path::Path;
use crate::{
ClientConfigKey, ClientOptions, GetOptions, GetResult, ListResult, MultipartUpload, ObjectMeta,
ObjectStore, PutMode, PutMultipartOptions, PutOptions, PutPayload, PutResult, Result,
RetryConfig,
ClientConfigKey, ClientOptions, CopyMode, CopyOptions, GetOptions, GetResult, ListResult,
MultipartUpload, ObjectMeta, ObjectStore, PutMode, PutMultipartOptions, PutOptions, PutPayload,
PutResult, Result, RetryConfig,
};

mod client;
Expand Down Expand Up @@ -210,12 +210,16 @@ impl ObjectStore for HttpStore {
})
}

async fn copy(&self, from: &Path, to: &Path) -> Result<()> {
self.client.copy(from, to, true).await
}
async fn copy_opts(&self, from: &Path, to: &Path, options: CopyOptions) -> Result<()> {
let CopyOptions {
mode,
extensions: _,
} = options;

async fn copy_if_not_exists(&self, from: &Path, to: &Path) -> Result<()> {
self.client.copy(from, to, false).await
match mode {
CopyMode::Overwrite => self.client.copy(from, to, true).await,
CopyMode::Create => self.client.copy(from, to, false).await,
}
}
}

Expand Down
Loading