mirror of
https://github.com/nix-community/comma.git
synced 2024-09-11 12:05:28 +03:00
Merge pull request #34 from houstdav000/patch/handle-db-in-store
Index.rs: Add db writeability check
This commit is contained in:
commit
4ed30d58db
17
src/index.rs
17
src/index.rs
@ -26,15 +26,16 @@ pub fn check_database() {
|
|||||||
|
|
||||||
/// Test whether the database is more than 30 days old
|
/// Test whether the database is more than 30 days old
|
||||||
fn is_database_old(database_file: std::path::PathBuf) -> bool {
|
fn is_database_old(database_file: std::path::PathBuf) -> bool {
|
||||||
let modified = match database_file.metadata() {
|
let metadata = match database_file.metadata() {
|
||||||
Ok(metadata) => metadata.modified().unwrap_or_else(|_| SystemTime::now()),
|
Ok(metadata) => metadata,
|
||||||
Err(_) => return false,
|
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));
|
.unwrap_or(Duration::new(0, 0));
|
||||||
if time_since_modified > Duration::from_secs(30 * 24 * 60 * 60) {
|
|
||||||
return true;
|
time_since_modified > Duration::from_secs(30 * 24 * 60 * 60) && !metadata.permissions().readonly()
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user