diff --git a/Cargo.lock b/Cargo.lock index fae7d804f97..29a74a0335e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5198,7 +5198,6 @@ dependencies = [ "rand 0.9.2", "rstest 0.23.0", "serde", - "shellexpand", "snafu", "tempfile", "test-log", @@ -8165,15 +8164,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "shellexpand" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb" -dependencies = [ - "dirs 6.0.0", -] - [[package]] name = "shlex" version = "1.3.0" diff --git a/Cargo.toml b/Cargo.toml index 67b7e26a8ae..064cd8b2f2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -177,7 +177,6 @@ rustc_version = "0.4" serde = { version = "^1" } serde_json = { version = "1" } semver = "1.0" -shellexpand = "3.0" slatedb = "0.3" snafu = "0.8" strum = "0.26" diff --git a/python/Cargo.lock b/python/Cargo.lock index a7efcab31ec..3c1b7792254 100644 --- a/python/Cargo.lock +++ b/python/Cargo.lock @@ -4279,7 +4279,6 @@ dependencies = [ "prost", "rand 0.9.2", "serde", - "shellexpand", "snafu", "tempfile", "tokio", @@ -5665,7 +5664,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "343d3bd7056eda839b03204e68deff7d1b13aba7af2b2fd16890697274262ee7" dependencies = [ "heck", - "itertools 0.14.0", + "itertools 0.11.0", "log", "multimap", "petgraph", @@ -5684,7 +5683,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b" dependencies = [ "anyhow", - "itertools 0.14.0", + "itertools 0.11.0", "proc-macro2", "quote", "syn 2.0.117", @@ -6765,15 +6764,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "shellexpand" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb" -dependencies = [ - "dirs", -] - [[package]] name = "shlex" version = "1.3.0" diff --git a/rust/lance-io/Cargo.toml b/rust/lance-io/Cargo.toml index 71e9dab1e9f..fd6e0345c2f 100644 --- a/rust/lance-io/Cargo.toml +++ b/rust/lance-io/Cargo.toml @@ -40,7 +40,6 @@ log.workspace = true pin-project.workspace = true prost.workspace = true serde.workspace = true -shellexpand.workspace = true snafu.workspace = true tokio.workspace = true tracing.workspace = true diff --git a/rust/lance-io/src/object_store.rs b/rust/lance-io/src/object_store.rs index e908599c500..626055a2b11 100644 --- a/rust/lance-io/src/object_store.rs +++ b/rust/lance-io/src/object_store.rs @@ -26,7 +26,6 @@ use object_store::Error as ObjectStoreError; use object_store::{path::Path, ObjectMeta, ObjectStore as OSObjectStore}; use providers::local::FileStoreProvider; use providers::memory::MemoryStoreProvider; -use shellexpand::tilde; use snafu::location; use tokio::io::AsyncWriteExt; use url::Url; @@ -337,7 +336,8 @@ pub fn uri_to_url(uri: &str) -> Result { } fn expand_path(str_path: impl AsRef) -> Result { - let expanded = tilde(str_path.as_ref()).to_string(); + let str_path = str_path.as_ref(); + let expanded = expand_tilde_path(str_path).unwrap_or_else(|| str_path.into()); let mut expanded_path = path_abs::PathAbs::new(expanded) .unwrap() @@ -353,6 +353,22 @@ fn expand_path(str_path: impl AsRef) -> Result { Ok(expanded_path) } +fn expand_tilde_path(path: &str) -> Option { + let home_dir = std::env::home_dir()?; + if path == "~" { + return Some(home_dir); + } + if let Some(stripped) = path.strip_prefix("~/") { + return Some(home_dir.join(stripped)); + } + #[cfg(windows)] + if let Some(stripped) = path.strip_prefix("~\\") { + return Some(home_dir.join(stripped)); + } + + None +} + fn local_path_to_url(str_path: &str) -> Result { let expanded_path = expand_path(str_path)?; @@ -967,8 +983,7 @@ mod tests { /// Write test content to file. fn write_to_file(path_str: &str, contents: &str) -> std::io::Result<()> { - let expanded = tilde(path_str).to_string(); - let path = StdPath::new(&expanded); + let path = expand_path(path_str).map_err(std::io::Error::other)?; std::fs::create_dir_all(path.parent().unwrap())?; write(path, contents) }