#mtime #cargo #save-file #cargo-build #sha-256 #file-content #rebuild

app mtime-travel

A small tool to save and restore the mtime attribute for files

2 unstable releases

0.1.0 May 23, 2024
0.0.1 Dec 25, 2023

#57 in Caching

44 downloads per month

MIT/Apache

15KB
259 lines

mtime-travel

crates.io link

A small tool to save and restore the mtime attribute for files. When saving, it will record the file hashes, and when restoring, it will only restore the mtime if the file hash matches. File hashing is done using SHA-256.

This can be useful for things like avoiding Rust rebuilds if the file contents didn't change, but the mtimes did, as Rust will rebuild based on mtimes (see https://github.com/rust-lang/cargo/issues/6529). A example where rebuilding like this is undesirable is pulling a project via git in CI, as that will alter the mtime values and therefore normally trigger a rebuild, even if you may already have cached the build artifacts from a prior CI run.

Installation

You can install mtime-travel via cargo:

cargo install --locked mtime-travel

Usage

Saving

Usage: mtime-travel save [OPTIONS] <TARGET_DIR>

Arguments:
  <TARGET_DIR>  The location to recursively scan for files

Options:
  -f, --file <FILE>           The location to a file to save the current mtimes to [default: mtimes.json]
  -i, --ignore [<IGNORE>...]  Regex patterns for which files to skip; multiple regex strings can be passed. Note the file paths checked are the absolute paths
  -v, --verbose               Enable verbose output
  -h, --help                  Print help

To save the current directory to a file called mtimes.json:

mtime-travel save ./

To ignore certain regexes:

mtime-travel save --ignore ".*foo.*" ./

To save to another location:

mtime-travel save --file <MTIME_FILE_PATH> ./

This will output a .json file with the files' hashes and mtime value.

Restoring

Usage: mtime-travel restore [OPTIONS] <TARGET_DIR>

Arguments:
  <TARGET_DIR>  The location to recursively restore mtimes to

Options:
  -f, --file <FILE>  The location to a file to restore previous mtimes from [default: mtimes.json]
  -v, --verbose      Enable verbose output
  -i, --ignore-hash  Restore mtime for a file even if the hash does not match
  -h, --help         Print help

To restore the current directory's files given a file called mtimes.json in the same directory if the file hashes match:

mtime-travel restore ./

To ignore file hashes:

mtime-travel restore --ignore-hash ./

To restore from a file at a different path:

mtime-travel restore --file <MTIME_FILE_PATH> ./

Dependencies

~4–13MB
~160K SLoC