Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: align fn root semantics; fix missing root for some services; rm duplicated normalize ops #5035

Merged
merged 9 commits into from
Aug 22, 2024
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
11 changes: 9 additions & 2 deletions core/src/raw/adapters/kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ where
}

/// Configure root within this backend.
pub fn with_root(mut self, root: &str) -> Self {
self.root = normalize_root(root);
pub fn with_root(self, root: &str) -> Self {
self.with_normalized_root(normalize_root(root))
}

/// Configure root within this backend.
///
/// This method assumes root is normalized.
pub(crate) fn with_normalized_root(mut self, root: String) -> Self {
self.root = root;
self
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/atomicserver/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Builder for AtomicserverBuilder {
.with_context("service", Scheme::Atomicserver)
})?,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/azblob/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ impl AzblobBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/services/azdls/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ impl AzdlsBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/services/azfile/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ impl AzfileBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
11 changes: 7 additions & 4 deletions core/src/services/cloudflare_kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ impl CloudflareKvBuilder {

/// Set the root within this backend.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
}
Expand Down Expand Up @@ -175,7 +178,7 @@ impl Builder for CloudflareKvBuilder {
client,
url_prefix,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/cos/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ impl CosBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
11 changes: 7 additions & 4 deletions core/src/services/d1/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ impl D1Builder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_owned());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -231,7 +234,7 @@ impl Builder for D1Builder {
key_field,
value_field,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/dbfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ impl DbfsBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/services/dropbox/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ impl DropboxBuilder {
///
/// Default to `/` if not set.
pub fn root(mut self, root: &str) -> Self {
self.config.root = Some(root.to_string());
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down
11 changes: 7 additions & 4 deletions core/src/services/etcd/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ impl EtcdBuilder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_owned());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -246,7 +249,7 @@ impl Builder for EtcdBuilder {
client,
options,
})
.with_root(root.as_str()))
.with_normalized_root(root))
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/foundationdb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Builder for FoundationdbBuilder {
.as_str(),
);

Ok(FoundationdbBackend::new(Adapter { db, _network }).with_root(&root))
Ok(FoundationdbBackend::new(Adapter { db, _network }).with_normalized_root(root))
}
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/fs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ pub struct FsBuilder {
impl FsBuilder {
/// Set root for backend.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
8 changes: 5 additions & 3 deletions core/src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ impl Debug for GcsBuilder {
impl GcsBuilder {
/// set the working directory root of backend
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
7 changes: 6 additions & 1 deletion core/src/services/gdrive/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ impl Debug for GdriveBuilder {
impl GdriveBuilder {
/// Set root path of GoogleDrive folder.
pub fn root(mut self, root: &str) -> Self {
self.config.root = Some(root.to_string());
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/ghac/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ pub struct GhacBuilder {
impl GhacBuilder {
/// set the working directory root of backend
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
22 changes: 17 additions & 5 deletions core/src/services/gridfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use tokio::sync::OnceCell;

use crate::raw::adapters::kv;
use crate::raw::new_std_io_error;
use crate::raw::Access;
use crate::raw::*;
use crate::*;

/// Config for Grid file system support.
Expand Down Expand Up @@ -114,9 +114,12 @@ impl GridFsBuilder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_owned());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -176,13 +179,22 @@ impl Builder for GridFsBuilder {
};
let chunk_size = self.config.chunk_size.unwrap_or(255);

let root = normalize_root(
self.config
.root
.clone()
.unwrap_or_else(|| "/".to_string())
.as_str(),
);

Ok(GridFsBackend::new(Adapter {
connection_string: conn,
database,
bucket,
chunk_size,
bucket_instance: OnceCell::new(),
}))
})
.with_normalized_root(root))
}
}

Expand Down
9 changes: 6 additions & 3 deletions core/src/services/huggingface/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,12 @@ impl HuggingfaceBuilder {
///
/// All operations will happen under this root.
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down
8 changes: 5 additions & 3 deletions core/src/services/ipfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ impl IpfsBuilder {
/// - `/ipfs/bafybeibozpulxtpv5nhfa2ue3dcjx23ndh3gwr5vwllk7ptoyfwnfjjr4q/` (IPFS with CID v1)
/// - `/ipns/opendal.apache.org/` (IPNS)
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string())
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}
Expand Down
11 changes: 7 additions & 4 deletions core/src/services/libsql/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,12 @@ impl LibsqlBuilder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_string());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -215,7 +218,7 @@ impl Builder for LibsqlBuilder {
key_field,
value_field,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
11 changes: 7 additions & 4 deletions core/src/services/memcached/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ impl MemcachedBuilder {
///
/// default: "/"
pub fn root(mut self, root: &str) -> Self {
if !root.is_empty() {
self.config.root = Some(root.to_owned());
}
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -172,7 +175,7 @@ impl Builder for MemcachedBuilder {
conn,
default_ttl: self.config.default_ttl,
})
.with_root(&root))
.with_normalized_root(root))
}
}

Expand Down
Loading
Loading