Handle pre-epoch file timestamps consistently and record Rust audit
This commit is contained in:
1 parent
59b2fc39b2
commit
14adbbc616
7 files changed
+262
-46
No files matched your search
@@ -21,7 +21,6 @@ use std::{
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
time::UNIX_EPOCH,
|
||||
};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
@@ -657,12 +656,7 @@ impl SearchIndex {
|
||||
report.discovered += 1;
|
||||
let metadata = entry.metadata()?;
|
||||
let size = i64::try_from(metadata.len()).context("file exceeds supported size")?;
|
||||
let modified = metadata
|
||||
.modified()?
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.context("file timestamp predates Unix epoch")?;
|
||||
let mtime = i64::try_from(modified.as_nanos())
|
||||
.context("file timestamp exceeds supported range")?;
|
||||
let mtime = searchi_media::unix_time_ns(metadata.modified()?)?;
|
||||
let extension = entry
|
||||
.path()
|
||||
.extension()
|
||||
@@ -1257,7 +1251,7 @@ impl SearchIndex {
|
||||
pub fn file_signature(&self, path: &str) -> Result<Option<(u64, i64)>> {
|
||||
self.connection
|
||||
.query_row(
|
||||
"SELECT size,mtime FROM files WHERE path=?1 AND size>=0 AND mtime>=0",
|
||||
"SELECT size,mtime FROM files WHERE path=?1 AND size>=0",
|
||||
[path],
|
||||
|row| Ok((row.get(0)?, row.get(1)?)),
|
||||
)
|
||||
@@ -1294,9 +1288,8 @@ impl SearchIndex {
|
||||
Ok(value) if value.is_file() => value,
|
||||
_ => return Ok(None),
|
||||
};
|
||||
let mtime = metadata.modified()?.duration_since(UNIX_EPOCH)?;
|
||||
let size = i64::try_from(metadata.len())?;
|
||||
let modified = i64::try_from(mtime.as_nanos())?;
|
||||
let modified = searchi_media::unix_time_ns(metadata.modified()?)?;
|
||||
let Some(expected_hash) = self.extracted_source_hash(path)? else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user