From 66729d85a45d49b24d4823b168f3c63305b7599d Mon Sep 17 00:00:00 2001 From: Kevin Lee Drum Date: Fri, 5 Jul 2024 19:59:52 -0400 Subject: [PATCH] handle missing file created/modified date --- src-tauri/src/import.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/import.rs b/src-tauri/src/import.rs index 9c5b4f5..0dea89c 100644 --- a/src-tauri/src/import.rs +++ b/src-tauri/src/import.rs @@ -7,6 +7,7 @@ use std::panic; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use std::time::SystemTime; use crate::{emit_log, emit_progress, ProgressEventPayload}; @@ -185,9 +186,14 @@ fn get_exif_datetime(path: &Path) -> Option { fn get_file_datetime(path: &Path) -> Option { let metadata = fs::metadata(path).ok()?; - let created = metadata.created().ok()?; - let modified = metadata.modified().ok()?; - let older_time = std::cmp::min(created, modified); + let created = metadata.created().ok(); + let modified = metadata.modified().ok(); + let older_time = match (created, modified) { + (Some(c), Some(m)) => std::cmp::min(c, m), + (Some(c), None) => c, + (None, Some(m)) => m, + (None, None) => SystemTime::now(), + }; let duration = older_time.duration_since(std::time::UNIX_EPOCH).ok()?; let seconds = duration.as_secs() as i64; let nanos = duration.subsec_nanos() as u32;