fornwall / rust-script

Run Rust files and expressions as scripts without any setup or compilation step.
https://rust-script.org
Apache License 2.0
1.2k stars 41 forks source link

Fall back to modified time if creation time of cached binaries is unavailable #108

Closed jmariondev closed 1 year ago

jmariondev commented 1 year ago

When attempting to re-run the example script from the README in a podman container (Alpine Linux 3.17) I receive the following output:

code $ ./example.rs
A random number: 15946831555454293876
code $ ./example.rs
error: creation time is not available on this platform currently

In the container ~/.cache/ is on a fuse-overlayfs, which doesn't seem to expose file creation (called "Birth") time information:

code $ stat ~/.cache/rust-script/binaries/release/example_09d44c1e4ea1d0fc4dcbb3cb
[ ... ]
Access: 2023-06-17 01:54:11.809091333 +0000
Modify: 2023-06-17 01:54:11.822424859 +0000
Change: 2023-06-17 01:54:11.829091621 +0000
 Birth: -

This seems to be introduced by the change here: https://github.com/fornwall/rust-script/commit/ab77a62efaf4e6e55300f44128f919b50b3eadd4#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcR364-R366

The issue is that this code assumes all files will have a creation time, while that's not true on Linux.

This commit makes no behavioral change if retrieving creation time is successful, but changes the error path to instead fall back to modified time if the creation time is missing (instead of erroring out).

fornwall commented 1 year ago

Thanks a lot! Has now been released as version 0.29.0.