feat: tolerate the absence of mtime

pull/559/head
sigoden 2025-03-20 08:34:12 +08:00
parent d0453b7591
commit cb9c3aef68
1 changed files with 5 additions and 2 deletions

View File

@ -1394,7 +1394,10 @@ impl Server {
(true, false) => PathType::SymlinkFile, (true, false) => PathType::SymlinkFile,
(false, false) => PathType::File, (false, false) => PathType::File,
}; };
let mtime = to_timestamp(&meta.modified()?); let mtime = match meta.modified().ok().or_else(|| meta.created().ok()) {
Some(v) => to_timestamp(&v),
None => 0,
};
let size = match path_type { let size = match path_type {
PathType::Dir | PathType::SymlinkDir => { PathType::Dir | PathType::SymlinkDir => {
let mut count = 0; let mut count = 0;
@ -1690,7 +1693,7 @@ async fn zip_dir<W: AsyncWrite + Unpin>(
} }
fn extract_cache_headers(meta: &Metadata) -> Option<(ETag, LastModified)> { fn extract_cache_headers(meta: &Metadata) -> Option<(ETag, LastModified)> {
let mtime = meta.modified().ok()?; let mtime = meta.modified().ok().or_else(|| meta.created().ok())?;
let timestamp = to_timestamp(&mtime); let timestamp = to_timestamp(&mtime);
let size = meta.len(); let size = meta.len();
let etag = format!(r#""{timestamp}-{size}""#).parse::<ETag>().ok()?; let etag = format!(r#""{timestamp}-{size}""#).parse::<ETag>().ok()?;