comma icon indicating copy to clipboard operation
comma copied to clipboard

Comma db age check runs on "modified" time

Open cyntheticfox opened this issue 3 years ago • 4 comments

Found this when going to run comma, and getting

Warning: Nix-index database is older than 30 days, try updating with `--update`.

Though my database is definitely up-to-date. I'm using a pre-packaged db, so it stays up-to-date. From what I can tell, Nix sets file modification times in /nix/store to 1.

Perhaps ctime (using stat terms since the std::fs::metadata function returns based on that)/inode-update time would be a better metric for store age?

https://github.com/nix-community/comma/blob/c83ff3839983b3cb8deb407ff618ca12179de588/src/index.rs#L34

cyntheticfox avatar Sep 20 '22 21:09 cyntheticfox

It's a little more complicated than I thought, with ctime not being implemented consistently, but there is the created function on the std::fs::Metadata struct that looks to accurately contain the creation date, even when in the Nix store.

It might be best to create a case-handler for when modified returns 1 to either just ignore it entirely or to then check created instead. It might be best to create a case-handler for when modified returns 1 to either just ignore it entirely or to then check created instead.

cyntheticfox avatar Sep 20 '22 21:09 cyntheticfox

How about ignoring it when the file isn't writable

Artturin avatar Sep 20 '22 21:09 Artturin

Or is a link, yeah that'd probably work. -------- Original message --------From: Artturi @.> Date: 9/20/22 5:58 PM (GMT-05:00) To: nix-community/comma @.> Cc: David Houston @.>, Author @.> Subject: Re: [nix-community/comma] Comma db age check runs on "modified" time (Issue #33) How about ignoring it when the file isn't writable

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

cyntheticfox avatar Sep 20 '22 22:09 cyntheticfox

Something like this?

/// Test whether the database is more than 30 days old
fn is_database_old(database_file: std::path::PathBuf) -> bool {
    let metadata = match database_file.metadata() {
        Ok(metadata) => metadata,
        Err(_) => return false,
    };

    let time_since_modified = metadata
        .modified()
        .unwrap_or_else(|_| SystemTime::now())
        .elapsed()
        .unwrap_or(Duration::new(0, 0));

    time_since_modified > Duration::from_secs(30 * 24 * 60 * 60) && !metadata.is_symlink()
}

Not super familiar with Rust yet

EDIT: Alternatively, for a write-check, replace the last condition check with metadata.permissions().readonly()

cyntheticfox avatar Sep 20 '22 23:09 cyntheticfox