Skip to content

Commit

Permalink
handle missing file created/modified date
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinleedrum committed Jul 5, 2024
1 parent de32a2b commit 66729d8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src-tauri/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -185,9 +186,14 @@ fn get_exif_datetime(path: &Path) -> Option<NaiveDateTime> {

fn get_file_datetime(path: &Path) -> Option<NaiveDateTime> {
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;
Expand Down

0 comments on commit 66729d8

Please sign in to comment.