Fix handling of negative timestamps in Stat.#999
Conversation
Deprecate `Stat::st_mtime` etc., because they're unsigned and should be signed, and introduce a `StatExt` extension trait which adds `mtime()` etc. accessor functions which return the values in the appropriate signed type. This `StatExt` trait can go away next time we have a semver breaking change, but for now this preserves compatibility.
|
Why a |
|
Depending on the target and configuration, This is one of the things in progress for the next major version of rustix, to move to encapsulate all the libc/linux-raw-sys types, as having them in the public API causes a variety of problems. But that requires a breaking change too, so for now, an extension trait seems the best we can do. |
|
@sunfishcode Ah, I didn't realize it was ever directly exposing the underlying type. Fair enough. This looks like a sensible interim fix, then. |
|
This is now released in rustix 0.38.31. |
|
Thanks again for tackling this issue! I was trying to use these improvements but had trouble doing so. The code looks like this (reproduced here for convenience) #[cfg(not(target_os = "aix"))]
let seconds = self.0.st_mtime;
#[cfg(target_os = "aix")]
let seconds = self.0.st_mtim.tv_sec;
// The fix I'd like to live without
let seconds = seconds as i64;
system_time_from_secs_nanos(seconds, nanoseconds.try_into().ok()?)
The solution seems to be to add such an implementation, but maybe there was a reason to not implement it in the first place. In any way, without This also gave me the idea to use #[cfg(not(any(target_os = "netbsd", target_os = "aix")))]
let nanoseconds = self.0.st_mtime_nsec;
#[cfg(target_os = "netbsd")]
let nanoseconds = self.0.st_mtimensec;
#[cfg(target_os = "aix")]
let nanoseconds = self.0.st_mtim.tv_nsec;Thanks for letting me know how to proceed here. |
6ec74e0 ("Fix handling of negative timestamps in `Stat`. (bytecodealliance#999)") broke the hurd build, where we have a st_[acm]tim timespec instead of st_[acm], like on aix and nto.
6ec74e0 ("Fix handling of negative timestamps in `Stat`. (bytecodealliance#999)") broke the hurd build, where we have a st_[acm]tim timespec instead of st_[acm], like on aix and nto.
|
In https://github.com/bytecodealliance/rustix/pull/1064/files I added the implementation |
Deprecate
Stat::st_mtimeetc., because they're unsigned and should be signed, and introduce aStatExtextension trait which addsmtime()etc. accessor functions which return the values in the appropriate signed type.This
StatExttrait can go away next time we have a semver breaking change, but for now this preserves compatibility.