Dynamically load utimensat if exists on the host (#535)
* Dynamically load utimensat if exists on the host This commit introduces a change to file time management for *nix based hosts in that it firstly tries to load `utimensat` symbol, and if it doesn't exist, then falls back to `utimes` instead. This change is borrowing very heavily from [filetime] crate, however, it introduces a couple of helpers and methods specific to WASI use case (or more generally, to a use case which requires modifying times of entities specified by a pair `(DirFD, RelativePath)` rather than the typical file time specification based only absolute path or raw file descriptor as is the case with [filetime] crate. The trick here is, that on kernels which do not have `utimensat` symbol, this implementation emulates this behaviour by a combination of `openat` and `utimes`. This commit also is meant to address #516. [filetime]: https://github.com/alexcrichton/filetime * Fix symlink NOFOLLOW flag setting * Add docs and specify UTIME_NOW/OMIT on Linux Previously, we relied on [libc] crate for `UTIME_NOW` and `UTIME_OMIT` constants on Linux. However, following the convention assumed in [filetime] crate, this is now changed to directly specified by us in our crate. [libc]: https://github.com/rust-lang/libc [filetime]: https://github.com/alexcrichton/filetime * Refactor UTIME_NOW/OMIT for BSD * Address final discussion points
This commit is contained in:
committed by
Alex Crichton
parent
5a1845b4ca
commit
0006a2af95
@@ -1,3 +1,4 @@
|
||||
pub(crate) mod filetime;
|
||||
pub(crate) mod hostcalls_impl;
|
||||
pub(crate) mod osfile;
|
||||
|
||||
@@ -38,45 +39,3 @@ pub(crate) mod host_impl {
|
||||
Ok(entry)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod fs_helpers {
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
pub(crate) fn utime_now() -> libc::c_long {
|
||||
cfg_if! {
|
||||
if #[cfg(any(
|
||||
target_os = "macos",
|
||||
target_os = "freebsd",
|
||||
target_os = "ios",
|
||||
target_os = "dragonfly"
|
||||
))] {
|
||||
-1
|
||||
} else if #[cfg(target_os = "openbsd")] {
|
||||
// https://github.com/openbsd/src/blob/master/sys/sys/stat.h#L187
|
||||
-2
|
||||
} else if #[cfg(target_os = "netbsd" )] {
|
||||
// http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/stat.h?rev=1.69&content-type=text/x-cvsweb-markup&only_with_tag=MAIN
|
||||
1_073_741_823
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn utime_omit() -> libc::c_long {
|
||||
cfg_if! {
|
||||
if #[cfg(any(
|
||||
target_os = "macos",
|
||||
target_os = "freebsd",
|
||||
target_os = "ios",
|
||||
target_os = "dragonfly"
|
||||
))] {
|
||||
-2
|
||||
} else if #[cfg(target_os = "openbsd")] {
|
||||
// https://github.com/openbsd/src/blob/master/sys/sys/stat.h#L187
|
||||
-1
|
||||
} else if #[cfg(target_os = "netbsd")] {
|
||||
// http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/stat.h?rev=1.69&content-type=text/x-cvsweb-markup&only_with_tag=MAIN
|
||||
1_073_741_822
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user