From db6097733c1fbdefc85cd3768ac3c9316dfb6756 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Tue, 8 Jul 2025 03:28:19 -0400 Subject: [PATCH] Use redox_path in canonicalize_using_cwd_internal `redox_path` handles most of the logic anyway. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/platform/redox/path.rs | 27 ++++++++------------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c6b092310f..83d70890c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -432,9 +432,9 @@ dependencies = [ [[package]] name = "redox-path" -version = "0.2.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64072665120942deff5fd5425d6c1811b854f4939e7f1c01ce755f64432bbea7" +checksum = "436d45c2b6a5b159d43da708e62b25be3a4a3d5550d654b72216ade4c4bfd717" [[package]] name = "redox-rt" diff --git a/Cargo.toml b/Cargo.toml index 29a8b1d49b..239f8f16f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ sc = "0.2.3" [target.'cfg(target_os = "redox")'.dependencies] redox_syscall = "0.5.13" redox-rt = { path = "redox-rt" } -redox-path = "0.2" +redox-path = "0.3" redox_event = { git = "https://gitlab.redox-os.org/redox-os/event.git", default-features = false, features = [ "redox_syscall", ] } diff --git a/src/platform/redox/path.rs b/src/platform/redox/path.rs index 9d6739a463..467adef5d0 100644 --- a/src/platform/redox/path.rs +++ b/src/platform/redox/path.rs @@ -5,7 +5,7 @@ use syscall::{data::Stat, error::*, flag::*}; use super::{libcscheme, FdGuard}; use crate::sync::Mutex; -pub use redox_path::canonicalize_using_cwd; +pub use redox_path::{canonicalize_using_cwd, canonicalize_using_scheme, RedoxPath}; // TODO: Define in syscall const PATH_MAX: usize = 4096; @@ -77,27 +77,16 @@ pub fn set_default_scheme(scheme: &str) -> Result<()> { fn canonicalize_with_cwd_internal(cwd: Option<&str>, path: &str) -> Result { let path = canonicalize_using_cwd(cwd, path).ok_or(Error::new(ENOENT))?; - let standard_scheme = path == "/scheme" || path.starts_with("/scheme/"); - let legacy_scheme = path - .split("/") - .next() - .map(|c| c.contains(":")) - .unwrap_or(false); - - Ok(if standard_scheme || legacy_scheme { - path + if RedoxPath::from_absolute(&path) + .map(|rpath| rpath.is_legacy() || path.starts_with("/scheme/")) + .unwrap_or_default() + { + Ok(path) } else { let mut default_scheme_guard = DEFAULT_SCHEME.lock(); let default_scheme = default_scheme_guard.get_or_insert_with(|| Box::from("file")); - let mut result = format!("/scheme/{}{}", default_scheme, path); - - // Trim trailing / to keep path canonical. - if result.as_bytes().last() == Some(&b'/') { - result.pop(); - } - - result - }) + canonicalize_using_scheme(default_scheme, &path).ok_or(Error::new(ENOENT)) + } } pub fn canonicalize(path: &str) -> Result {