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
@@ -13,7 +13,6 @@ use std::{
|
||||
atomic::{AtomicUsize, Ordering},
|
||||
Arc, Mutex,
|
||||
},
|
||||
time::UNIX_EPOCH,
|
||||
};
|
||||
use tauri::http::{header, Method, Request, Response, StatusCode};
|
||||
|
||||
@@ -38,8 +37,7 @@ impl Identity {
|
||||
let modified_ns = metadata
|
||||
.modified()
|
||||
.ok()
|
||||
.and_then(|value| value.duration_since(UNIX_EPOCH).ok())
|
||||
.and_then(|value| i64::try_from(value.as_nanos()).ok())
|
||||
.and_then(|value| searchi_media::unix_time_ns(value).ok())
|
||||
.ok_or("Preview source timestamp is unavailable.")?;
|
||||
Ok(Self {
|
||||
len: metadata.len(),
|
||||
@@ -503,6 +501,35 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pre_epoch_media_is_indexed_and_previewed_with_current_identity() {
|
||||
let mut fixture = Fixture::new(64);
|
||||
File::options()
|
||||
.write(true)
|
||||
.open(&fixture.path)
|
||||
.unwrap()
|
||||
.set_times(
|
||||
std::fs::FileTimes::new()
|
||||
.set_modified(std::time::UNIX_EPOCH - std::time::Duration::from_secs(1)),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
fixture.request(Method::GET, None).status(),
|
||||
StatusCode::GONE
|
||||
);
|
||||
SearchIndex::open(&fixture.database)
|
||||
.unwrap()
|
||||
.index_folder(fixture.path.parent().unwrap())
|
||||
.unwrap();
|
||||
fixture.token = fixture
|
||||
.registry
|
||||
.grant(fixture.database.clone(), fixture.path.clone(), "audio")
|
||||
.unwrap();
|
||||
let response = fixture.request(Method::GET, None);
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
assert_eq!(response.body().len(), 64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn large_media_never_allocates_the_full_file_and_head_is_metadata_only() {
|
||||
let fixture = Fixture::new(8 * MAX_CHUNK);
|
||||
|
||||
Reference in new issue
Block a user