this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Break out copying to target path

+19 -10
+19 -10
src/main.rs
··· 1 + use std::path::{Path, PathBuf}; 2 + 1 3 use clap::Parser; 2 4 use glob::glob; 3 5 use miette::IntoDiagnostic; ··· 19 21 let guess = mime_guess::from_path(&path); 20 22 match guess.first() { 21 23 Some(mime) if mime.type_() == mime::IMAGE => { 22 - let metadata = std::fs::metadata(&path).into_diagnostic()?; 23 - let created: chrono::DateTime<chrono::Local> = 24 - metadata.created().into_diagnostic()?.into(); 25 - let dest_path = cli.target_dir.join(created.date_naive().to_string()); 24 + let dest_path = copy_file_to_target(&path, &cli.target_dir)?; 26 25 27 - if !dest_path.exists() { 28 - std::fs::create_dir_all(&dest_path).into_diagnostic()?; 29 - } 30 - 31 - let dest_path = dest_path.join(path.file_name().unwrap()); 32 26 println!("{} - {} ({:?})", path.display(), dest_path.display(), guess); 33 - std::fs::copy(&path, dest_path).into_diagnostic()?; 34 27 } 35 28 _ => {} 36 29 } ··· 43 36 44 37 Ok(()) 45 38 } 39 + 40 + pub fn copy_file_to_target(origin_path: &Path, target_path: &Path) -> miette::Result<PathBuf> { 41 + let metadata = std::fs::metadata(origin_path).into_diagnostic()?; 42 + let created: chrono::DateTime<chrono::Local> = metadata.created().into_diagnostic()?.into(); 43 + let dest_path = target_path.join(created.date_naive().to_string()); 44 + 45 + if !dest_path.exists() { 46 + std::fs::create_dir_all(&dest_path).into_diagnostic()?; 47 + } 48 + 49 + let dest_path = dest_path.join(origin_path.file_name().unwrap()); 50 + 51 + std::fs::copy(origin_path, &dest_path).into_diagnostic()?; 52 + 53 + Ok(dest_path) 54 + }