fix bug: i was ignoring the symlink follow flag in path_filestat_{get,
set_times}
This commit is contained in:
@@ -175,8 +175,12 @@ impl WasiDir for Dir {
|
||||
ctim: meta.created().map(|t| Some(t.into_std())).unwrap_or(None),
|
||||
})
|
||||
}
|
||||
fn get_path_filestat(&self, path: &str) -> Result<Filestat, Error> {
|
||||
let meta = self.0.metadata(Path::new(path))?;
|
||||
fn get_path_filestat(&self, path: &str, follow_symlinks: bool) -> Result<Filestat, Error> {
|
||||
let meta = if follow_symlinks {
|
||||
self.0.metadata(Path::new(path))?
|
||||
} else {
|
||||
self.0.symlink_metadata(Path::new(path))?
|
||||
};
|
||||
Ok(Filestat {
|
||||
device_id: meta.dev(),
|
||||
inode: meta.ino(),
|
||||
@@ -217,12 +221,21 @@ impl WasiDir for Dir {
|
||||
path: &str,
|
||||
atime: Option<wasi_c2::SystemTimeSpec>,
|
||||
mtime: Option<wasi_c2::SystemTimeSpec>,
|
||||
follow_symlinks: bool,
|
||||
) -> Result<(), Error> {
|
||||
if follow_symlinks {
|
||||
self.0.set_times(
|
||||
Path::new(path),
|
||||
convert_systimespec(atime),
|
||||
convert_systimespec(mtime),
|
||||
)?;
|
||||
} else {
|
||||
self.0.set_symlink_times(
|
||||
Path::new(path),
|
||||
convert_systimespec(atime),
|
||||
convert_systimespec(mtime),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ pub trait WasiDir {
|
||||
fn unlink_file(&self, path: &str) -> Result<(), Error>;
|
||||
fn read_link(&self, path: &str) -> Result<PathBuf, Error>;
|
||||
fn get_filestat(&self) -> Result<Filestat, Error>;
|
||||
fn get_path_filestat(&self, path: &str) -> Result<Filestat, Error>;
|
||||
fn get_path_filestat(&self, path: &str, follow_symlinks: bool) -> Result<Filestat, Error>;
|
||||
fn rename(&self, path: &str, dest_dir: &dyn WasiDir, dest_path: &str) -> Result<(), Error>;
|
||||
fn hard_link(
|
||||
&self,
|
||||
@@ -40,6 +40,7 @@ pub trait WasiDir {
|
||||
path: &str,
|
||||
atime: Option<SystemTimeSpec>,
|
||||
mtime: Option<SystemTimeSpec>,
|
||||
follow_symlinks: bool,
|
||||
) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#![allow(unused_variables)]
|
||||
use crate::{
|
||||
dir::{DirCaps, DirEntry, DirEntryExt, DirFdStat, ReaddirCursor, ReaddirEntity, TableDirExt},
|
||||
file::{
|
||||
@@ -417,7 +416,7 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
|
||||
.get_dir(fd)
|
||||
.expect("checked that entry is dir")
|
||||
.get_cap(DirCaps::FILESTAT_SET_TIMES)?
|
||||
.set_times(".", atim, mtim)
|
||||
.set_times(".", atim, mtim, false)
|
||||
} else {
|
||||
Err(Error::badf())
|
||||
}
|
||||
@@ -703,7 +702,10 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
|
||||
.table()
|
||||
.get_dir(u32::from(dirfd))?
|
||||
.get_cap(DirCaps::PATH_FILESTAT_GET)?
|
||||
.get_path_filestat(path.as_str()?.deref())?;
|
||||
.get_path_filestat(
|
||||
path.as_str()?.deref(),
|
||||
flags.contains(types::Lookupflags::SYMLINK_FOLLOW),
|
||||
)?;
|
||||
Ok(types::Filestat::from(filestat))
|
||||
}
|
||||
|
||||
@@ -726,7 +728,12 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
|
||||
self.table()
|
||||
.get_dir(u32::from(dirfd))?
|
||||
.get_cap(DirCaps::PATH_FILESTAT_SET_TIMES)?
|
||||
.set_times(path.as_str()?.deref(), atim, mtim)
|
||||
.set_times(
|
||||
path.as_str()?.deref(),
|
||||
atim,
|
||||
mtim,
|
||||
flags.contains(types::Lookupflags::SYMLINK_FOLLOW),
|
||||
)
|
||||
}
|
||||
|
||||
fn path_link(
|
||||
|
||||
Reference in New Issue
Block a user