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