Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,21 @@ impl InputAction {
if matches!(self.build_kind, BuildKind::Normal) && !self.force_compile {
match fs::File::open(&built_binary_path) {
Ok(built_binary_file) => {
// Use ctime instead of mtime as cargo may copy an already
// built binary (with old mtime) here:
let built_binary_ctime = built_binary_file.metadata()?.created()?;
// When possible, use creation time instead of modified time as cargo may copy
// an already built binary (with old modified time):
let built_binary_time = built_binary_file
.metadata()?
.created()
.unwrap_or(built_binary_file.metadata()?.modified()?);
match (
fs::File::open(&self.script_path),
fs::File::open(manifest_path),
) {
(Ok(script_file), Ok(manifest_file)) => {
let script_mtime = script_file.metadata()?.modified()?;
let manifest_mtime = manifest_file.metadata()?.modified()?;
if built_binary_ctime.cmp(&script_mtime).is_ge()
&& built_binary_ctime.cmp(&manifest_mtime).is_ge()
if built_binary_time.cmp(&script_mtime).is_ge()
&& built_binary_time.cmp(&manifest_mtime).is_ge()
{
debug!("Keeping old binary");
return Ok(execute_command());
Expand Down