use new path formatting and conversion code

This commit is contained in:
Ron Williams
2024-03-01 06:24:13 -08:00
parent e7cf569a1f
commit 5156ebd179
4 changed files with 22 additions and 42 deletions
Generated
+2 -2
View File
@@ -262,9 +262,9 @@ checksum = "384c2842d4e069d5ccacf5fe1dca4ef8d07a5444329715f0fc3c61813502d4d1"
[[package]]
name = "redox-path"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64072665120942deff5fd5425d6c1811b854f4939e7f1c01ce755f64432bbea7"
checksum = "d515f4eec916ba5ea351bd7ad7b25232af420282e88c932b29b2a4e807538e19"
[[package]]
name = "redox_simple_endian"
+1 -1
View File
@@ -43,7 +43,7 @@ range-tree = { version = "0.1", optional = true }
seahash = { version = "4.1.0", default-features = false }
termion = { version = "1.5.6", optional = true }
uuid = { version = "1.4", default-features = false }
redox-path = "0.2.0"
redox-path = "0.3.0"
# https://github.com/rexlunae/simple-endian-rs/pull/5
[dependencies.redox_simple_endian]
+9 -7
View File
@@ -207,17 +207,19 @@ fn filesystem_by_uuid(
) -> Option<(String, FileSystem<DiskCache<DiskFile>>)> {
use std::fs;
use redox_path::canonicalize_using_scheme;
use redox_path::RedoxPath;
match fs::read_dir("/scheme") {
Ok(entries) => {
for entry_res in entries {
if let Ok(entry) = entry_res {
if let Ok(scheme) = entry.file_name().into_string() {
if scheme.starts_with("disk") {
println!("redoxfs: found scheme {}", scheme);
let scheme_path = canonicalize_using_scheme(&scheme, "")?;
match fs::read_dir(scheme_path) {
if let Some(disk) = entry.path().to_str() {
if RedoxPath::from_absolute(disk)
.unwrap_or(RedoxPath::from_absolute("/")?)
.is_scheme_category("disk")
{
println!("redoxfs: found scheme {}", disk);
match fs::read_dir(disk) {
Ok(entries) => {
for entry_res in entries {
if let Ok(entry) = entry_res {
@@ -249,7 +251,7 @@ fn filesystem_by_uuid(
}
}
Err(err) => {
println!("redoxfs: failed to list '{}': {}", scheme, err);
println!("redoxfs: failed to list '{}': {}", disk, err);
}
}
}
+10 -32
View File
@@ -15,7 +15,7 @@ use syscall::flag::{
use syscall::scheme::SchemeMut;
use syscall::{MunmapFlags, EBADFD};
use redox_path::{canonicalize_using_cwd, canonicalize_using_scheme, RedoxPath};
use redox_path::{canonicalize_to_standard, canonicalize_using_cwd, canonicalize_using_scheme, scheme_path, RedoxPath};
use crate::{Disk, FileSystem, Node, Transaction, TreeData, TreePtr, BLOCK_SIZE};
@@ -50,10 +50,10 @@ impl<D: Disk> FileScheme<D> {
nodes: &mut Vec<(TreeData<Node>, String)>,
) -> Result<String> {
let atime = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
let scheme_path = canonicalize_using_scheme(scheme_name, "").ok_or(Error::new(EINVAL))?;
// symbolic link is relative to this part of the url
let mut working_dir = dirname(full_path).unwrap_or(scheme_path.to_string());
let mut working_dir =
dirname(full_path).unwrap_or(scheme_path(scheme_name).ok_or(Error::new(EINVAL))?);
// node of the link
let mut node = node;
@@ -69,40 +69,18 @@ impl<D: Disk> FileScheme<D> {
atime.subsec_nanos(),
)?;
let target = canonicalize_using_cwd(
let target = canonicalize_to_standard(
Some(&working_dir),
str::from_utf8(&buf[..count]).or(Err(Error::new(EINVAL)))?,
)
.ok_or(Error::new(EINVAL))?;
let target_as_path = RedoxPath::from_absolute(&target).ok_or(Error::new(EINVAL))?;
let target_reference = match target_as_path {
RedoxPath::Standard(_) => {
let (scheme, reference) =
target_as_path.as_parts().ok_or(Error::new(EINVAL))?;
if scheme.as_ref() != scheme_name {
return Err(Error::new(EXDEV));
}
reference.as_ref().to_string()
}
RedoxPath::Legacy(scheme, reference) => {
// Legacy references are not canonicalized because they can contain coded information
// We know this is a `file:` reference, so canonicalize into a Standard path
if scheme.as_ref() != scheme_name {
return Err(Error::new(EXDEV));
}
let target = canonicalize_using_scheme(scheme_name, reference.as_ref())
.ok_or(Error::new(EINVAL))?;
let target_as_path =
RedoxPath::from_absolute(&target).ok_or(Error::new(EINVAL))?;
let (scheme, reference) =
target_as_path.as_parts().ok_or(Error::new(EINVAL))?;
if scheme.as_ref() != scheme_name {
return Err(Error::new(EXDEV));
}
reference.as_ref().to_string()
}
};
let (scheme, reference) = target_as_path.as_parts().ok_or(Error::new(EINVAL))?;
if scheme.as_ref() != scheme_name {
return Err(Error::new(EXDEV));
}
let target_reference = reference.to_string();
nodes.clear();
if let Some((next_node, next_node_name)) =
@@ -110,7 +88,7 @@ impl<D: Disk> FileScheme<D> {
{
if !next_node.data().is_symlink() {
nodes.push((next_node, next_node_name));
return Ok(target_reference.to_string());
return Ok(target_reference);
}
node = next_node;
working_dir = dirname(&target).ok_or(Error::new(EINVAL))?.to_string();