This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new f7ac9c12d refactor: Split service fs out of core (#6970)
f7ac9c12d is described below
commit f7ac9c12d2582bbbc82e53a725e5e5affd009aaf
Author: Jintao Zhang <[email protected]>
AuthorDate: Mon Dec 15 17:37:43 2025 +0800
refactor: Split service fs out of core (#6970)
* refactor: Split service fs out of core
Signed-off-by: Jintao Zhang <[email protected]>
* fix local_fs test
Added services-fs to the dev-dependencies in
integrations/object_store/Cargo.toml
so that the local_fs behavior test for the object_store integration can use
the fs service.
Signed-off-by: Jintao Zhang <[email protected]>
* fix test cases
Signed-off-by: Jintao Zhang <[email protected]>
* fix: remove extra blank lines in services/mod.rs
---------
Signed-off-by: Jintao Zhang <[email protected]>
---
core/Cargo.lock | 13 +++++++
core/Cargo.toml | 3 +-
core/core/Cargo.toml | 2 --
core/core/src/layers/dtrace.rs | 10 +++---
core/core/src/services/mod.rs | 5 ---
core/core/src/types/builder.rs | 6 ++--
core/core/src/types/operator/builder.rs | 32 ++++++-----------
core/services/fs/Cargo.toml | 40 ++++++++++++++++++++++
.../src/services/fs => services/fs/src}/backend.rs | 4 +--
.../src/services/fs => services/fs/src}/config.rs | 8 ++---
.../src/services/fs => services/fs/src}/core.rs | 4 +--
.../src/services/fs => services/fs/src}/deleter.rs | 4 +--
.../src/services/fs => services/fs/src}/docs.md | 6 ++--
.../src/services/fs => services/fs/src}/error.rs | 4 +--
.../services/fs/mod.rs => services/fs/src/lib.rs} | 12 ++++---
.../src/services/fs => services/fs/src}/lister.rs | 8 ++---
.../src/services/fs => services/fs/src}/reader.rs | 4 +--
.../src/services/fs => services/fs/src}/writer.rs | 6 ++--
core/src/lib.rs | 2 ++
integrations/object_store/Cargo.toml | 1 +
20 files changed, 108 insertions(+), 66 deletions(-)
diff --git a/core/Cargo.lock b/core/Cargo.lock
index c72ae28a1..4707f7277 100644
--- a/core/Cargo.lock
+++ b/core/Cargo.lock
@@ -5502,6 +5502,7 @@ dependencies = [
"opendal-service-azdls",
"opendal-service-azfile",
"opendal-service-cloudflare-kv",
+ "opendal-service-fs",
"opendal-service-ftp",
"opendal-service-gcs",
"opendal-service-ghac",
@@ -5904,6 +5905,18 @@ dependencies = [
"serde_json",
]
+[[package]]
+name = "opendal-service-fs"
+version = "0.55.0"
+dependencies = [
+ "bytes",
+ "ctor",
+ "log",
+ "opendal-core",
+ "serde",
+ "tokio",
+]
+
[[package]]
name = "opendal-service-ftp"
version = "0.55.0"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 1719ef729..00c18ea96 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -116,7 +116,7 @@ services-dbfs = ["opendal-core/services-dbfs"]
services-dropbox = ["opendal-core/services-dropbox"]
services-etcd = ["opendal-core/services-etcd"]
services-foundationdb = ["opendal-core/services-foundationdb"]
-services-fs = ["opendal-core/services-fs"]
+services-fs = ["dep:opendal-service-fs"]
services-ftp = ["dep:opendal-service-ftp"]
services-gcs = ["dep:opendal-service-gcs"]
services-gdrive = ["opendal-core/services-gdrive"]
@@ -214,6 +214,7 @@ opendal-service-hdfs-native = { path =
"services/hdfs-native", version = "0.55.0
opendal-service-ipfs = { path = "services/ipfs", version = "0.55.0", optional
= true, default-features = false }
opendal-service-moka = { path = "services/moka", version = "0.55.0", optional
= true, default-features = false }
opendal-service-mysql = { path = "services/mysql", version = "0.55.0",
optional = true, default-features = false }
+opendal-service-fs = { path = "services/fs", version = "0.55.0", optional =
true, default-features = false }
opendal-service-obs = { path = "services/obs", version = "0.55.0", optional =
true, default-features = false }
opendal-service-oss = { path = "services/oss", version = "0.55.0", optional =
true, default-features = false }
opendal-service-postgresql = { path = "services/postgresql", version =
"0.55.0", optional = true, default-features = false }
diff --git a/core/core/Cargo.toml b/core/core/Cargo.toml
index 567444bfb..1e149abde 100644
--- a/core/core/Cargo.toml
+++ b/core/core/Cargo.toml
@@ -55,7 +55,6 @@ tests = [
"dep:rand",
"dep:sha2",
"dep:dotenvy",
- "services-fs",
"services-http",
"services-memory",
"internal-tokio-rt",
@@ -89,7 +88,6 @@ services-dbfs = []
services-dropbox = []
services-etcd = ["dep:etcd-client", "dep:fastpool"]
services-foundationdb = ["dep:foundationdb"]
-services-fs = ["tokio/fs", "internal-tokio-rt"]
services-gdrive = ["internal-path-cache"]
services-github = []
services-gridfs = ["dep:mongodb", "dep:mongodb-internal-macros"]
diff --git a/core/core/src/layers/dtrace.rs b/core/core/src/layers/dtrace.rs
index 9041e24a8..ec82519a1 100644
--- a/core/core/src/layers/dtrace.rs
+++ b/core/core/src/layers/dtrace.rs
@@ -72,11 +72,11 @@ use crate::*;
///
/// Example:
///
-/// ```no_run
-/// # use opendal_core::layers::DtraceLayer;
-/// # use opendal_core::services;
-/// # use opendal_core::Operator;
-/// # use opendal_core::Result;
+/// ```ignore
+/// # use opendal::layers::DtraceLayer;
+/// # use opendal::services;
+/// # use opendal::Operator;
+/// # use opendal::Result;
///
/// # #[tokio::main]
/// # async fn main() -> Result<()> {
diff --git a/core/core/src/services/mod.rs b/core/core/src/services/mod.rs
index 17b3bc053..68e2a7b86 100644
--- a/core/core/src/services/mod.rs
+++ b/core/core/src/services/mod.rs
@@ -69,11 +69,6 @@ mod foundationdb;
#[cfg(feature = "services-foundationdb")]
pub use self::foundationdb::*;
-#[cfg(feature = "services-fs")]
-mod fs;
-#[cfg(feature = "services-fs")]
-pub use fs::*;
-
#[cfg(feature = "services-gdrive")]
mod gdrive;
#[cfg(feature = "services-gdrive")]
diff --git a/core/core/src/types/builder.rs b/core/core/src/types/builder.rs
index df4933b3d..1405dd898 100644
--- a/core/core/src/types/builder.rs
+++ b/core/core/src/types/builder.rs
@@ -37,11 +37,11 @@ use crate::*;
///
/// ```
/// # use anyhow::Result;
-/// use opendal_core::services::Fs;
+/// use opendal_core::services::Memory;
/// use opendal_core::Operator;
/// async fn test() -> Result<()> {
-/// // Create fs backend builder.
-/// let mut builder = Fs::default().root("/tmp");
+/// // Create memory backend builder.
+/// let builder = Memory::default();
///
/// // Build an `Operator` to start operating the storage.
/// let op: Operator = Operator::new(builder)?.finish();
diff --git a/core/core/src/types/operator/builder.rs
b/core/core/src/types/operator/builder.rs
index 305429650..e90253d06 100644
--- a/core/core/src/types/operator/builder.rs
+++ b/core/core/src/types/operator/builder.rs
@@ -28,11 +28,11 @@ use crate::*;
///
/// ```
/// # use anyhow::Result;
-/// use opendal_core::services::Fs;
+/// use opendal_core::services::Memory;
/// use opendal_core::Operator;
/// async fn test() -> Result<()> {
-/// // Create fs backend builder.
-/// let builder = Fs::default().root("/tmp");
+/// // Create memory backend builder.
+/// let builder = Memory::default();
///
/// // Build an `Operator` to start operating the storage.
/// let op: Operator = Operator::new(builder)?.finish();
@@ -52,11 +52,11 @@ impl Operator {
///
/// ```
/// # use anyhow::Result;
- /// use opendal_core::services::Fs;
+ /// use opendal_core::services::Memory;
/// use opendal_core::Operator;
/// async fn test() -> Result<()> {
- /// // Create fs backend builder.
- /// let builder = Fs::default().root("/tmp");
+ /// // Create memory backend builder.
+ /// let builder = Memory::default();
///
/// // Build an `Operator` to start operating the storage.
/// let op: Operator = Operator::new(builder)?.finish();
@@ -107,18 +107,13 @@ impl Operator {
/// # use anyhow::Result;
/// use std::collections::HashMap;
///
- /// use opendal_core::services::Fs;
+ /// use opendal_core::services::Memory;
/// use opendal_core::Operator;
/// async fn test() -> Result<()> {
- /// let map = HashMap::from([
- /// // Set the root for fs, all operations will happen under this
root.
- /// //
- /// // NOTE: the root must be absolute path.
- /// ("root".to_string(), "/tmp".to_string()),
- /// ]);
+ /// let map = HashMap::new();
///
/// // Build an `Operator` to start operating the storage.
- /// let op: Operator = Operator::from_iter::<Fs>(map)?.finish();
+ /// let op: Operator = Operator::from_iter::<Memory>(map)?.finish();
///
/// Ok(())
/// }
@@ -166,15 +161,10 @@ impl Operator {
/// use opendal_core::services;
///
/// async fn test() -> Result<()> {
- /// let map = [
- /// // Set the root for fs, all operations will happen under this
root.
- /// //
- /// // NOTE: the root must be absolute path.
- /// ("root".to_string(), "/tmp".to_string()),
- /// ];
+ /// let map: Vec<(String, String)> = vec![];
///
/// // Build an `Operator` to start operating the storage.
- /// let op: Operator = Operator::via_iter(services::FS_SCHEME, map)?;
+ /// let op: Operator = Operator::via_iter(services::MEMORY_SCHEME,
map)?;
///
/// Ok(())
/// }
diff --git a/core/services/fs/Cargo.toml b/core/services/fs/Cargo.toml
new file mode 100644
index 000000000..99d472389
--- /dev/null
+++ b/core/services/fs/Cargo.toml
@@ -0,0 +1,40 @@
+# 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.
+
+[package]
+description = "Apache OpenDAL Fs service implementation"
+name = "opendal-service-fs"
+
+authors = { workspace = true }
+edition = { workspace = true }
+homepage = { workspace = true }
+license = { workspace = true }
+repository = { workspace = true }
+rust-version = { workspace = true }
+version = { workspace = true }
+
+[package.metadata.docs.rs]
+all-features = true
+
+[dependencies]
+opendal-core = { path = "../../core", version = "0.55.0", default-features =
false, features = ["internal-tokio-rt"] }
+
+bytes = { workspace = true }
+ctor = { workspace = true }
+log = { workspace = true }
+serde = { workspace = true, features = ["derive"] }
+tokio = { workspace = true, features = ["fs", "rt-multi-thread"] }
diff --git a/core/core/src/services/fs/backend.rs
b/core/services/fs/src/backend.rs
similarity index 99%
rename from core/core/src/services/fs/backend.rs
rename to core/services/fs/src/backend.rs
index 923ce2cda..4a0f38a80 100644
--- a/core/core/src/services/fs/backend.rs
+++ b/core/services/fs/src/backend.rs
@@ -28,8 +28,8 @@ use super::lister::FsLister;
use super::reader::FsReader;
use super::writer::FsWriter;
use super::writer::FsWriters;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
/// POSIX file system support.
#[doc = include_str!("docs.md")]
diff --git a/core/core/src/services/fs/config.rs
b/core/services/fs/src/config.rs
similarity index 90%
rename from core/core/src/services/fs/config.rs
rename to core/services/fs/src/config.rs
index d9212d5d2..56cc441e2 100644
--- a/core/core/src/services/fs/config.rs
+++ b/core/services/fs/src/config.rs
@@ -32,10 +32,10 @@ pub struct FsConfig {
pub atomic_write_dir: Option<String>,
}
-impl crate::Configurator for FsConfig {
+impl opendal_core::Configurator for FsConfig {
type Builder = FsBuilder;
- fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
+ fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self>
{
let mut map = uri.options().clone();
if let Some(root) = uri.root().filter(|v| !v.is_empty()) {
@@ -54,8 +54,8 @@ impl crate::Configurator for FsConfig {
#[cfg(test)]
mod tests {
use super::*;
- use crate::Configurator;
- use crate::types::OperatorUri;
+ use opendal_core::Configurator;
+ use opendal_core::OperatorUri;
#[test]
fn from_uri_extracts_root() {
diff --git a/core/core/src/services/fs/core.rs b/core/services/fs/src/core.rs
similarity index 99%
rename from core/core/src/services/fs/core.rs
rename to core/services/fs/src/core.rs
index e7d08670f..0d512e1fd 100644
--- a/core/core/src/services/fs/core.rs
+++ b/core/services/fs/src/core.rs
@@ -21,8 +21,8 @@ use std::path::PathBuf;
use std::sync::Arc;
use super::error::*;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
#[derive(Debug)]
pub struct FsCore {
diff --git a/core/core/src/services/fs/deleter.rs
b/core/services/fs/src/deleter.rs
similarity index 97%
rename from core/core/src/services/fs/deleter.rs
rename to core/services/fs/src/deleter.rs
index bf8eeecd6..351fde662 100644
--- a/core/core/src/services/fs/deleter.rs
+++ b/core/services/fs/src/deleter.rs
@@ -18,8 +18,8 @@
use std::sync::Arc;
use super::core::*;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
pub struct FsDeleter {
core: Arc<FsCore>,
diff --git a/core/core/src/services/fs/docs.md b/core/services/fs/src/docs.md
similarity index 91%
rename from core/core/src/services/fs/docs.md
rename to core/services/fs/src/docs.md
index 568e6772e..f427bc1a2 100644
--- a/core/core/src/services/fs/docs.md
+++ b/core/services/fs/src/docs.md
@@ -23,12 +23,12 @@ You can refer to [`FsBuilder`]'s docs for more information
### Via Builder
-```rust,no_run
+```rust,ignore
use std::sync::Arc;
use anyhow::Result;
-use opendal_core::services::Fs;
-use opendal_core::Operator;
+use opendal::services::Fs;
+use opendal::Operator;
#[tokio::main]
async fn main() -> Result<()> {
diff --git a/core/core/src/services/fs/error.rs b/core/services/fs/src/error.rs
similarity index 96%
rename from core/core/src/services/fs/error.rs
rename to core/services/fs/src/error.rs
index b22599752..9c55b9199 100644
--- a/core/core/src/services/fs/error.rs
+++ b/core/services/fs/src/error.rs
@@ -15,8 +15,8 @@
// specific language governing permissions and limitations
// under the License.
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
/// Parse error response into Error.
pub(super) fn parse_error(e: std::io::Error) -> Error {
diff --git a/core/core/src/services/fs/mod.rs b/core/services/fs/src/lib.rs
similarity index 85%
rename from core/core/src/services/fs/mod.rs
rename to core/services/fs/src/lib.rs
index 96b064718..06477c9e4 100644
--- a/core/core/src/services/fs/mod.rs
+++ b/core/services/fs/src/lib.rs
@@ -15,10 +15,9 @@
// specific language governing permissions and limitations
// under the License.
-/// Default scheme for fs service.
-pub const FS_SCHEME: &str = "fs";
-
-use crate::types::DEFAULT_OPERATOR_REGISTRY;
+#![cfg_attr(docsrs, feature(doc_cfg))]
+//! Fs service implementation for Apache OpenDAL.
+#![deny(missing_docs)]
mod backend;
mod config;
@@ -32,7 +31,10 @@ mod writer;
pub use backend::FsBuilder as Fs;
pub use config::FsConfig;
+/// Default scheme for fs service.
+pub const FS_SCHEME: &str = "fs";
+
#[ctor::ctor]
fn register_fs_service() {
- DEFAULT_OPERATOR_REGISTRY.register::<Fs>(FS_SCHEME);
+ opendal_core::DEFAULT_OPERATOR_REGISTRY.register::<Fs>(FS_SCHEME);
}
diff --git a/core/core/src/services/fs/lister.rs
b/core/services/fs/src/lister.rs
similarity index 95%
rename from core/core/src/services/fs/lister.rs
rename to core/services/fs/src/lister.rs
index b478de212..d2ccdbb4b 100644
--- a/core/core/src/services/fs/lister.rs
+++ b/core/services/fs/src/lister.rs
@@ -18,10 +18,10 @@
use std::path::Path;
use std::path::PathBuf;
-use crate::EntryMode;
-use crate::Metadata;
-use crate::Result;
-use crate::raw::*;
+use opendal_core::EntryMode;
+use opendal_core::Metadata;
+use opendal_core::Result;
+use opendal_core::raw::*;
pub struct FsLister<P> {
root: PathBuf,
diff --git a/core/core/src/services/fs/reader.rs
b/core/services/fs/src/reader.rs
similarity index 98%
rename from core/core/src/services/fs/reader.rs
rename to core/services/fs/src/reader.rs
index 3bcca401e..4b0fbebbe 100644
--- a/core/core/src/services/fs/reader.rs
+++ b/core/services/fs/src/reader.rs
@@ -21,8 +21,8 @@ use tokio::io::AsyncReadExt;
use tokio::io::ReadBuf;
use super::core::*;
-use crate::raw::*;
-use crate::*;
+use opendal_core::raw::*;
+use opendal_core::*;
pub struct FsReader<F> {
core: Arc<FsCore>,
diff --git a/core/core/src/services/fs/writer.rs
b/core/services/fs/src/writer.rs
similarity index 98%
rename from core/core/src/services/fs/writer.rs
rename to core/services/fs/src/writer.rs
index 7e58e047f..4316ff329 100644
--- a/core/core/src/services/fs/writer.rs
+++ b/core/services/fs/src/writer.rs
@@ -23,9 +23,9 @@ use std::sync::Arc;
use bytes::Buf;
use tokio::io::AsyncWriteExt;
-use crate::raw::*;
-use crate::services::fs::core::FsCore;
-use crate::*;
+use super::core::FsCore;
+use opendal_core::raw::*;
+use opendal_core::*;
pub type FsWriters = TwoWays<FsWriter, oio::PositionWriter<FsWriter>>;
diff --git a/core/src/lib.rs b/core/src/lib.rs
index 710110424..eeb22d932 100644
--- a/core/src/lib.rs
+++ b/core/src/lib.rs
@@ -39,6 +39,8 @@ pub mod services {
pub use opendal_service_azfile::*;
#[cfg(feature = "services-cloudflare-kv")]
pub use opendal_service_cloudflare_kv::*;
+ #[cfg(feature = "services-fs")]
+ pub use opendal_service_fs::*;
#[cfg(feature = "services-ftp")]
pub use opendal_service_ftp::*;
#[cfg(feature = "services-gcs")]
diff --git a/integrations/object_store/Cargo.toml
b/integrations/object_store/Cargo.toml
index fefaad2e7..48589632f 100644
--- a/integrations/object_store/Cargo.toml
+++ b/integrations/object_store/Cargo.toml
@@ -53,6 +53,7 @@ anyhow = "1.0.86"
datafusion = "51.0.0"
libtest-mimic = "0.8.1"
opendal = { version = "0.55.0", path = "../../core", features = [
+ "services-fs",
"services-memory",
"services-s3",
"tests",