alexcrichton / filetime

Accessing file timestamps in a platform-agnostic fashion in Rust
Apache License 2.0
122 stars 56 forks source link

lutimes not available on all platforms #18

Closed kallisti5 closed 6 years ago

kallisti5 commented 6 years ago

lutimes isn't available on all platforms. https://www.gnu.org/software/gnulib/manual/html_node/lutimes.html To improve portability, can we do some kind of fallback?

A quick search of rust\liblibc\src shows limited lutimes while a search of futimes shows a more complete implementation across all platforms.

kallisti5 commented 6 years ago

One such issue during bootstrap.

/Data/rust> python x.py build --stage 0
Updating submodules
   Compiling filetime v0.1.14
error[E0425]: cannot find value `lutimes` in module `libc`
  --> /boot/home/.cargo/registry/src/github.com-1ecc6299db9ec823/filetime-0.1.14/src/unix/utimes.rs:12:42
   |
12 |     super::utimes(p, atime, mtime, libc::lutimes)
   |                                          ^^^^^^^ did you mean `futimes`?

error: aborting due to previous error

error: Could not compile `filetime`.

To learn more, run the command again with --verbose.
failed to run: /bin/cargo build --manifest-path /Data/rust/src/bootstrap/Cargo.toml
Build completed unsuccessfully in 0:00:20
alexcrichton commented 6 years ago

PRs are of course always welcome to port to new platforms!

kallisti5 commented 6 years ago

So, I really don't get the details on this implementation, however utimes is defined identically minus the name of the first char_c.

https://dylanmckay.io/hllvm/libc/fn.lutimes.html https://dylanmckay.io/hllvm/libc/fn.utimes.html

A simple change of libc::lutimes to libc::utimes fixes the build on Haiku and still compiles (and passes all testing via cargo test) on Linux

That feels too simple though :-)

kallisti5 commented 6 years ago

Yeah. filetime is technically correct per the manpages.

#include <sys/time.h>
int futimes(int fd, const struct timeval tv[2]);
int lutimes(const char *filename, const struct timeval tv[2]);
int utimes(const char *filename, const struct timeval times[2]);
pub unsafe extern "C" fn lutimes(
    file: *const c_char, 
    times: *const timeval
) -> c_int
pub unsafe extern "C" fn utimes(
    filename: *const c_char, 
    times: *const timeval
) -> c_int

Let me look into adding lutimes to our posix compatibility libraries. BeOS didn't classically have lutimes, but we're not BeOS :-)

jessicah commented 6 years ago

We should add lutimes to Haiku. Looks pretty straightforward: if it's a symlink, don't dereference it. If tests are passing, then it seems like tests aren't thorough enough.

kallisti5 commented 6 years ago

Done. Now to just define it in rust's std :tada: http://cgit.haiku-os.org/haiku/commit/?id=be149e8ccf9ecfc71a4aea33a4685534142d5e55