From 7eefdaf45b359e3e22046104cc061875ccb39a05 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 18 Jan 2024 11:07:51 -0700 Subject: [PATCH] Use redox-path external crate --- Cargo.lock | 8 +- Cargo.toml | 3 +- src/platform/redox/redox-path/Cargo.toml | 8 -- src/platform/redox/redox-path/src/lib.rs | 171 ----------------------- 4 files changed, 6 insertions(+), 184 deletions(-) delete mode 100644 src/platform/redox/redox-path/Cargo.toml delete mode 100644 src/platform/redox/redox-path/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 1c37aeefa4..0aa89491dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" [[package]] name = "cbitset" @@ -200,7 +200,9 @@ dependencies = [ [[package]] name = "redox-path" -version = "0.1.0" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f45c7275fe1467ea17542c01766ae9872fa98aa7fe06ba5ea6595f7a9f0699c6" [[package]] name = "redox_syscall" diff --git a/Cargo.toml b/Cargo.toml index 963a5f137a..37c9fb26c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ members = [ "src/crtn", "src/ld_so", "src/platform/redox/redox-exec", - "src/platform/redox/redox-path", ] exclude = ["tests", "dlmalloc-rs"] @@ -54,7 +53,7 @@ sc = "0.2.3" [target.'cfg(target_os = "redox")'.dependencies] redox_syscall = "0.4" redox-exec = { path = "src/platform/redox/redox-exec" } -redox-path = { path = "src/platform/redox/redox-path" } +redox-path = "0.1" [features] default = ["check_against_libc_crate"] diff --git a/src/platform/redox/redox-path/Cargo.toml b/src/platform/redox/redox-path/Cargo.toml deleted file mode 100644 index 17343a5248..0000000000 --- a/src/platform/redox/redox-path/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "redox-path" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/src/platform/redox/redox-path/src/lib.rs b/src/platform/redox/redox-path/src/lib.rs deleted file mode 100644 index c84761ff1d..0000000000 --- a/src/platform/redox/redox-path/src/lib.rs +++ /dev/null @@ -1,171 +0,0 @@ -#![no_std] - -extern crate alloc; - -use alloc::{borrow::ToOwned, format, string::String, vec::Vec}; - -pub fn split_path<'a>(path: &'a str) -> Option<(&'a str, &'a str)> { - let mut parts = path.splitn(2, ':'); - let scheme = parts.next()?; - let reference = parts.next()?; - Some((scheme, reference)) -} - -/// Make a relative path absolute. -/// -/// Given a cwd of "scheme:/path", this his function will turn "foo" into "scheme:/path/foo". -/// "/foo" will turn into "file:/foo". "bar:/foo" will be used directly, as it is already -/// absolute -pub fn canonicalize_using_cwd<'a>(cwd_opt: Option<&str>, path: &'a str) -> Option { - let (scheme, reference) = match split_path(path) { - Some((scheme, reference)) => (scheme, reference.to_owned()), - None => { - let cwd = cwd_opt?; - let (scheme, reference) = split_path(cwd)?; - if path.starts_with('/') { - (scheme, path.to_owned()) - } else { - let mut reference = reference.to_owned(); - if !reference.ends_with('/') { - reference.push('/'); - } - reference.push_str(path); - (scheme, reference) - } - } - }; - - let mut canonical = { - let parts = reference - .split('/') - .rev() - .scan(0, |nskip, part| { - if part == "." { - Some(None) - } else if part == ".." { - *nskip += 1; - Some(None) - } else if *nskip > 0 { - *nskip -= 1; - Some(None) - } else { - Some(Some(part)) - } - }) - .filter_map(|x| x) - .filter(|x| !x.is_empty()) - .collect::>(); - parts.iter().rev().fold(String::new(), |mut string, &part| { - string.push_str(part); - string.push('/'); - string - }) - }; - canonical.pop(); // remove extra '/' - - Some(format!("{}:{}", scheme, canonical)) -} - -#[cfg(test)] -mod tests { - use super::*; - use alloc::string::ToString; - - // Tests absolute paths without scheme - #[test] - fn test_absolute() { - let cwd_opt = Some("foo:"); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "/"), - Some("foo:".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "/file"), - Some("foo:file".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "/folder/file"), - Some("foo:folder/file".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "/folder/../file"), - Some("foo:file".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "/folder/../.."), - Some("foo:".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "/folder/../../../.."), - Some("foo:".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "/.."), - Some("foo:".to_string()) - ); - } - - // Test relative paths - #[test] - fn test_relative() { - let cwd_opt = Some("foo:"); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "file"), - Some("foo:file".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "folder/file"), - Some("foo:folder/file".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "folder/../file"), - Some("foo:file".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "folder/../.."), - Some("foo:".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "folder/../../../.."), - Some("foo:".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, ".."), - Some("foo:".to_string()) - ); - } - - // Tests paths prefixed with scheme - #[test] - fn test_scheme() { - let cwd_opt = Some("foo:"); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "bar:"), - Some("bar:".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "bar:file"), - Some("bar:file".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "bar:folder/file"), - Some("bar:folder/file".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "bar:folder/../file"), - Some("bar:file".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "bar:folder/../.."), - Some("bar:".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "bar:folder/../../../.."), - Some("bar:".to_string()) - ); - assert_eq!( - canonicalize_using_cwd(cwd_opt, "bar:.."), - Some("bar:".to_string()) - ); - } -}