Skip to content
Closed
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: 1 addition & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ geo-traits = "0.3.0"
geo-types = "0.7.16"
http = "1.1.0"
humantime = "2.2.0"
home = "0.5.12"
hyperloglogplus = { version = "0.4.1", features = ["const-loop"] }
itertools = "0.13"
jieba-rs = { version = "0.8.1", default-features = false }
Expand Down Expand Up @@ -177,7 +178,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"
Expand Down
2 changes: 1 addition & 1 deletion rust/lance-io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ bytes.workspace = true
chrono.workspace = true
deepsize.workspace = true
futures.workspace = true
home.workspace = true
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
Expand Down
25 changes: 22 additions & 3 deletions rust/lance-io/src/object_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use chrono::{DateTime, Utc};
use deepsize::DeepSizeOf;
use futures::{future, stream::BoxStream, StreamExt, TryStreamExt};
use futures::{FutureExt, Stream};
use home::home_dir;
use lance_core::error::LanceOptionExt;
use lance_core::utils::parse::str_is_truthy;
use list_retry::ListRetryStream;
Expand All @@ -26,7 +27,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;
Expand Down Expand Up @@ -337,7 +337,7 @@ pub fn uri_to_url(uri: &str) -> Result<Url> {
}

fn expand_path(str_path: impl AsRef<str>) -> Result<std::path::PathBuf> {
let expanded = tilde(str_path.as_ref()).to_string();
let expanded = expand_tilde(str_path.as_ref());

let mut expanded_path = path_abs::PathAbs::new(expanded)
.unwrap()
Expand All @@ -353,6 +353,25 @@ fn expand_path(str_path: impl AsRef<str>) -> Result<std::path::PathBuf> {
Ok(expanded_path)
}

fn expand_tilde(path: &str) -> String {
if let Some(stripped) = path.strip_prefix('~') {
if stripped.is_empty() || stripped.starts_with('/') || stripped.starts_with('\\') {
if let Some(home) = home_dir() {
let mut expanded = home;
if !stripped.is_empty() {
let suffix = stripped.trim_start_matches(&['/', '\\'][..]);
if !suffix.is_empty() {
expanded.push(suffix);
}
}
return expanded.to_string_lossy().into_owned();
}
}
}

path.to_string()
}

fn local_path_to_url(str_path: &str) -> Result<Url> {
let expanded_path = expand_path(str_path)?;

Expand Down Expand Up @@ -967,7 +986,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 expanded = expand_tilde(path_str);
let path = StdPath::new(&expanded);
std::fs::create_dir_all(path.parent().unwrap())?;
write(path, contents)
Expand Down
Loading