fix(tlc): redox_scheme uses syscall crate name and manual Stat fallback
This commit is contained in:
@@ -22,8 +22,8 @@
|
||||
use std::io::{self, Read};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use redox_syscall::flag::{O_RDONLY, O_DIRECTORY, O_STAT};
|
||||
use redox_syscall::data::Stat as RedoxStat;
|
||||
use syscall::flag::{O_RDONLY, O_DIRECTORY, O_STAT};
|
||||
use syscall::data::Stat as RedoxStat;
|
||||
|
||||
use crate::fs::{FileType, Permissions, Stat};
|
||||
use crate::vfs::local::Entry;
|
||||
@@ -61,9 +61,9 @@ impl RedoxSchemeVfs {
|
||||
|
||||
/// Map a redox `Stat` to TLC's [`Stat`].
|
||||
fn map_stat(rs: &RedoxStat) -> Stat {
|
||||
let file_type = if rs.st_mode & redox_syscall::flag::MODE_DIR != 0 {
|
||||
let file_type = if rs.st_mode & syscall::flag::MODE_DIR != 0 {
|
||||
FileType::Directory
|
||||
} else if rs.st_mode & redox_syscall::flag::MODE_SYMLINK != 0 {
|
||||
} else if rs.st_mode & syscall::flag::MODE_SYMLINK != 0 {
|
||||
FileType::Symlink
|
||||
} else {
|
||||
FileType::Regular
|
||||
@@ -92,12 +92,12 @@ impl Vfs for RedoxSchemeVfs {
|
||||
let path = Self::scheme_path(p)?;
|
||||
let path_c = std::ffi::CString::new(path.clone())
|
||||
.map_err(|e| VfsError::Other(format!("scheme path: {e}")))?;
|
||||
let fd = redox_syscall::open(&path_c, O_RDONLY | O_DIRECTORY | O_STAT, 0)
|
||||
let fd = syscall::open(&path_c, O_RDONLY | O_DIRECTORY | O_STAT, 0)
|
||||
.map_err(|e| VfsError::Other(format!("scheme open dir: {e}")))?;
|
||||
let mut entries = Vec::new();
|
||||
let mut buf = vec![0u8; 4096];
|
||||
loop {
|
||||
let n = redox_syscall::read(fd, &mut buf)
|
||||
let n = syscall::read(fd, &mut buf)
|
||||
.map_err(|e| VfsError::Other(format!("scheme read dir: {e}")))?;
|
||||
if n == 0 {
|
||||
break;
|
||||
@@ -116,13 +116,24 @@ impl Vfs for RedoxSchemeVfs {
|
||||
let child_c = std::ffi::CString::new(&child_path)
|
||||
.map_err(|_| VfsError::Other("invalid child path".into()))?;
|
||||
let mut rs = RedoxStat::default();
|
||||
let stat_fd = redox_syscall::open(&child_c, O_RDONLY | O_STAT, 0)
|
||||
let stat_fd = syscall::open(&child_c, O_RDONLY | O_STAT, 0)
|
||||
.map_err(|e| VfsError::Other(format!("scheme stat child: {e}")))?;
|
||||
let stat_result = redox_syscall::fstat(stat_fd, &mut rs);
|
||||
let _ = redox_syscall::close(stat_fd);
|
||||
let stat_result = syscall::fstat(stat_fd, &mut rs);
|
||||
let _ = syscall::close(stat_fd);
|
||||
let stat = match stat_result {
|
||||
Ok(_) => Self::map_stat(&rs),
|
||||
Err(_) => Stat::default(),
|
||||
Err(_) => Stat {
|
||||
file_type: FileType::Other,
|
||||
size: 0,
|
||||
mtime: 0,
|
||||
atime: 0,
|
||||
ctime: 0,
|
||||
permissions: Permissions::from_mode(0),
|
||||
nlinks: 0,
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
inode: 0,
|
||||
},
|
||||
};
|
||||
entries.push(Entry {
|
||||
name,
|
||||
@@ -130,7 +141,7 @@ impl Vfs for RedoxSchemeVfs {
|
||||
});
|
||||
}
|
||||
}
|
||||
let _ = redox_syscall::close(fd);
|
||||
let _ = syscall::close(fd);
|
||||
entries.sort_by(|a, b| {
|
||||
b.is_dir()
|
||||
.cmp(&a.is_dir())
|
||||
@@ -143,12 +154,12 @@ impl Vfs for RedoxSchemeVfs {
|
||||
let path = Self::scheme_path(p)?;
|
||||
let path_c = std::ffi::CString::new(path)
|
||||
.map_err(|e| VfsError::Other(format!("scheme path: {e}")))?;
|
||||
let fd = redox_syscall::open(&path_c, O_RDONLY | O_STAT, 0)
|
||||
let fd = syscall::open(&path_c, O_RDONLY | O_STAT, 0)
|
||||
.map_err(|e| VfsError::Other(format!("scheme stat: {e}")))?;
|
||||
let mut rs = RedoxStat::default();
|
||||
redox_syscall::fstat(fd, &mut rs)
|
||||
syscall::fstat(fd, &mut rs)
|
||||
.map_err(|e| VfsError::Other(format!("scheme fstat: {e}")))?;
|
||||
let _ = redox_syscall::close(fd);
|
||||
let _ = syscall::close(fd);
|
||||
Ok(Self::map_stat(&rs))
|
||||
}
|
||||
|
||||
@@ -168,13 +179,13 @@ impl Vfs for RedoxSchemeVfs {
|
||||
let path = Self::scheme_path(p)?;
|
||||
let path_c = std::ffi::CString::new(path.clone())
|
||||
.map_err(|e| VfsError::Other(format!("scheme path: {e}")))?;
|
||||
let fd = redox_syscall::open(&path_c, O_RDONLY, 0)
|
||||
let fd = syscall::open(&path_c, O_RDONLY, 0)
|
||||
.map_err(|e| VfsError::Other(format!("scheme open read: {e}")))?;
|
||||
let mut buf = vec![0u8; fd as usize];
|
||||
let n = redox_syscall::read(fd, &mut buf)
|
||||
let n = syscall::read(fd, &mut buf)
|
||||
.map_err(|e| VfsError::Other(format!("scheme read: {e}")))?;
|
||||
buf.truncate(n);
|
||||
let _ = redox_syscall::close(fd);
|
||||
let _ = syscall::close(fd);
|
||||
Ok(Box::new(io::Cursor::new(buf)))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user