From 55dd39871dde030c3efaa87c2b3b1b104a2be097 Mon Sep 17 00:00:00 2001 From: David Houston Date: Tue, 20 Sep 2022 19:11:55 -0400 Subject: [PATCH] Index.rs: Add db writeability check Signed-off-by: David Houston --- src/index.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/index.rs b/src/index.rs index 508b80f..70749e4 100644 --- a/src/index.rs +++ b/src/index.rs @@ -26,15 +26,16 @@ pub fn check_database() { /// Test whether the database is more than 30 days old fn is_database_old(database_file: std::path::PathBuf) -> bool { - let modified = match database_file.metadata() { - Ok(metadata) => metadata.modified().unwrap_or_else(|_| SystemTime::now()), + let metadata = match database_file.metadata() { + Ok(metadata) => metadata, Err(_) => return false, }; - let time_since_modified = SystemTime::now() - .duration_since(modified) + + let time_since_modified = metadata + .modified() + .unwrap_or_else(|_| SystemTime::now()) + .elapsed() .unwrap_or(Duration::new(0, 0)); - if time_since_modified > Duration::from_secs(30 * 24 * 60 * 60) { - return true; - } - false + + time_since_modified > Duration::from_secs(30 * 24 * 60 * 60) && !metadata.permissions().readonly() }