Skip to content

Commit 4a0bdde

Browse files
authored
object_store: Add enabled-by-default "fs" feature (apache#6636)
1 parent fbee05f commit 4a0bdde

File tree

8 files changed

+28
-10
lines changed

8 files changed

+28
-10
lines changed

.github/workflows/object_store.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ jobs:
5454
# targets.
5555
- name: Run clippy with default features
5656
run: cargo clippy -- -D warnings
57+
- name: Run clippy without default features
58+
run: cargo clippy --no-default-features -- -D warnings
59+
- name: Run clippy with fs features
60+
run: cargo clippy --no-default-features --features fs -- -D warnings
5761
- name: Run clippy with aws feature
5862
run: cargo clippy --features aws -- -D warnings
5963
- name: Run clippy with gcp feature

object_store/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ percent-encoding = "2.1"
4141
snafu = { version = "0.8", default-features = false, features = ["std", "rust_1_61"] }
4242
tracing = { version = "0.1" }
4343
url = "2.2"
44-
walkdir = "2"
44+
walkdir = { version = "2", optional = true }
4545

4646
# Cloud storage support
4747
base64 = { version = "0.22", default-features = false, features = ["std"], optional = true }
@@ -61,8 +61,10 @@ httparse = { version = "1.8.0", default-features = false, features = ["std"], op
6161
nix = { version = "0.29.0", features = ["fs"] }
6262

6363
[features]
64+
default = ["fs"]
6465
cloud = ["serde", "serde_json", "quick-xml", "hyper", "reqwest", "reqwest/json", "reqwest/stream", "chrono/serde", "base64", "rand", "ring"]
6566
azure = ["cloud", "httparse"]
67+
fs = ["walkdir"]
6668
gcp = ["cloud", "rustls-pemfile"]
6769
aws = ["cloud", "md-5"]
6870
http = ["cloud"]

object_store/src/chunked.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ impl ObjectStore for ChunkedStore {
8686
async fn get_opts(&self, location: &Path, options: GetOptions) -> Result<GetResult> {
8787
let r = self.inner.get_opts(location, options).await?;
8888
let stream = match r.payload {
89+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
8990
GetResultPayload::File(file, path) => {
9091
crate::local::chunked_stream(file, path, r.range.clone(), self.chunk_size)
9192
}
@@ -178,7 +179,9 @@ impl ObjectStore for ChunkedStore {
178179
mod tests {
179180
use futures::StreamExt;
180181

182+
#[cfg(feature = "fs")]
181183
use crate::integration::*;
184+
#[cfg(feature = "fs")]
182185
use crate::local::LocalFileSystem;
183186
use crate::memory::InMemory;
184187
use crate::path::Path;
@@ -209,6 +212,7 @@ mod tests {
209212
}
210213
}
211214

215+
#[cfg(feature = "fs")]
212216
#[tokio::test]
213217
async fn test_chunked() {
214218
let temporary = tempfile::tempdir().unwrap();

object_store/src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@
6666
//! By default, this crate provides the following implementations:
6767
//!
6868
//! * Memory: [`InMemory`](memory::InMemory)
69-
//! * Local filesystem: [`LocalFileSystem`](local::LocalFileSystem)
7069
//!
7170
//! Feature flags are used to enable support for other implementations:
7271
//!
72+
#![cfg_attr(
73+
feature = "fs",
74+
doc = "* Local filesystem: [`LocalFileSystem`](local::LocalFileSystem)"
75+
)]
7376
#![cfg_attr(
7477
feature = "gcp",
7578
doc = "* [`gcp`]: [Google Cloud Storage](https://cloud.google.com/storage/) support. See [`GoogleCloudStorageBuilder`](gcp::GoogleCloudStorageBuilder)"
@@ -513,7 +516,7 @@ pub mod gcp;
513516
#[cfg(feature = "http")]
514517
pub mod http;
515518
pub mod limit;
516-
#[cfg(not(target_arch = "wasm32"))]
519+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
517520
pub mod local;
518521
pub mod memory;
519522
pub mod path;
@@ -557,15 +560,15 @@ pub use upload::*;
557560
pub use util::{coalesce_ranges, collect_bytes, GetRange, OBJECT_STORE_COALESCE_DEFAULT};
558561

559562
use crate::path::Path;
560-
#[cfg(not(target_arch = "wasm32"))]
563+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
561564
use crate::util::maybe_spawn_blocking;
562565
use async_trait::async_trait;
563566
use bytes::Bytes;
564567
use chrono::{DateTime, Utc};
565568
use futures::{stream::BoxStream, StreamExt, TryStreamExt};
566569
use snafu::Snafu;
567570
use std::fmt::{Debug, Formatter};
568-
#[cfg(not(target_arch = "wasm32"))]
571+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
569572
use std::io::{Read, Seek, SeekFrom};
570573
use std::ops::Range;
571574
use std::sync::Arc;
@@ -1028,6 +1031,7 @@ pub struct GetResult {
10281031
/// be able to optimise the case of a file already present on local disk
10291032
pub enum GetResultPayload {
10301033
/// The file, path
1034+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
10311035
File(std::fs::File, std::path::PathBuf),
10321036
/// An opaque stream of bytes
10331037
Stream(BoxStream<'static, Result<Bytes>>),
@@ -1036,6 +1040,7 @@ pub enum GetResultPayload {
10361040
impl Debug for GetResultPayload {
10371041
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
10381042
match self {
1043+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
10391044
Self::File(_, _) => write!(f, "GetResultPayload(File)"),
10401045
Self::Stream(_) => write!(f, "GetResultPayload(Stream)"),
10411046
}
@@ -1047,7 +1052,7 @@ impl GetResult {
10471052
pub async fn bytes(self) -> Result<Bytes> {
10481053
let len = self.range.end - self.range.start;
10491054
match self.payload {
1050-
#[cfg(not(target_arch = "wasm32"))]
1055+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
10511056
GetResultPayload::File(mut file, path) => {
10521057
maybe_spawn_blocking(move || {
10531058
file.seek(SeekFrom::Start(self.range.start as _))
@@ -1087,7 +1092,7 @@ impl GetResult {
10871092
/// no additional complexity or overheads
10881093
pub fn into_stream(self) -> BoxStream<'static, Result<Bytes>> {
10891094
match self.payload {
1090-
#[cfg(not(target_arch = "wasm32"))]
1095+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
10911096
GetResultPayload::File(file, path) => {
10921097
const CHUNK_SIZE: usize = 8 * 1024;
10931098
local::chunked_stream(file, path, self.range, CHUNK_SIZE)

object_store/src/limit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ impl<T: ObjectStore> ObjectStore for LimitStore<T> {
199199

200200
fn permit_get_result(r: GetResult, permit: OwnedSemaphorePermit) -> GetResult {
201201
let payload = match r.payload {
202+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
202203
v @ GetResultPayload::File(_, _) => v,
203204
GetResultPayload::Stream(s) => {
204205
GetResultPayload::Stream(PermitWrapper::new(s, permit).boxed())

object_store/src/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#[cfg(not(target_arch = "wasm32"))]
18+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
1919
use crate::local::LocalFileSystem;
2020
use crate::memory::InMemory;
2121
use crate::path::Path;
@@ -179,7 +179,7 @@ where
179179
let path = Path::parse(path)?;
180180

181181
let store = match scheme {
182-
#[cfg(not(target_arch = "wasm32"))]
182+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
183183
ObjectStoreScheme::Local => Box::new(LocalFileSystem::new()) as _,
184184
ObjectStoreScheme::Memory => Box::new(InMemory::new()) as _,
185185
#[cfg(feature = "aws")]

object_store/src/throttle.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,10 @@ fn usize_to_u32_saturate(x: usize) -> u32 {
307307
}
308308

309309
fn throttle_get(result: GetResult, wait_get_per_byte: Duration) -> GetResult {
310+
#[allow(clippy::infallible_destructuring_match)]
310311
let s = match result.payload {
311312
GetResultPayload::Stream(s) => s,
313+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
312314
GetResultPayload::File(_, _) => unimplemented!(),
313315
};
314316

object_store/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ where
7575
}
7676
}
7777

78-
#[cfg(not(target_arch = "wasm32"))]
78+
#[cfg(all(feature = "fs", not(target_arch = "wasm32")))]
7979
/// Takes a function and spawns it to a tokio blocking pool if available
8080
pub(crate) async fn maybe_spawn_blocking<F, T>(f: F) -> Result<T>
8181
where

0 commit comments

Comments
 (0)