diff --git a/src/directory_processor.rs b/src/directory_processor.rs index 57f44c5..aca8a74 100644 --- a/src/directory_processor.rs +++ b/src/directory_processor.rs @@ -3,7 +3,7 @@ use std::fs; use std::path::{Path, PathBuf}; use std::time::UNIX_EPOCH; use crate::tools; -use crate::FILES_TO_COPY; +use crate::{FILES_TO_COPY, FILES_TO_CONVERT}; pub struct DirectoryProcessor { source_dir: PathBuf, @@ -45,7 +45,7 @@ impl DirectoryProcessor { if path.is_dir() { self.get_source_files(&path)?; } else if let Some(ext) = path.extension().and_then(|e| e.to_str()) { - if ext == "odt" || FILES_TO_COPY.contains(&ext.to_lowercase().as_str()) { + if FILES_TO_CONVERT.contains(&ext.to_lowercase().as_str()) || FILES_TO_COPY.contains(&ext.to_lowercase().as_str()) { if let Ok(rel_path) = path.strip_prefix(&self.source_dir) { self.source_files.insert(rel_path.to_path_buf()); } @@ -83,8 +83,10 @@ impl DirectoryProcessor { // Check if this file should exist based on source files let should_exist = if let Some(ext) = rel_path.extension().and_then(|e| e.to_str()) { if ext == "pdf" { - // For PDF files, check if corresponding ODT exists in source - self.source_files.contains(&rel_path.with_extension("odt")) + // For PDF files, check if any corresponding source file exists + FILES_TO_CONVERT.iter().any(|&ext| { + self.source_files.contains(&rel_path.with_extension(ext)) + }) } else { // For other files, check if they exist in source self.source_files.contains(rel_path) @@ -135,7 +137,7 @@ impl DirectoryProcessor { let relative_path = path.strip_prefix(current_source) .map_err(|e| format!("Error getting relative path: {}", e))?; - if ext == "odt" { + if FILES_TO_CONVERT.contains(&ext.to_lowercase().as_str()) { // Construct the PDF path in the current target directory let pdf_path = current_target.join( relative_path.with_extension("pdf") diff --git a/src/main.rs b/src/main.rs index 81a65fc..ed2ee1c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,15 +7,16 @@ mod directory_processor; use directory_processor::DirectoryProcessor; pub const FILES_TO_COPY: [&str; 10] = ["jpg", "jpeg", "png", "gif", "bmp", "tiff", "webp", "avif", "txt", "md"]; +pub const FILES_TO_CONVERT: [&str; 3] = ["odt", "doc", "docx"]; #[derive(Parser, Debug)] #[command( author, version, - about = "Convert source directory with odt files to target path with pdf files with changes verification" + about = "Convert source directory with document files (odt/doc/docx) to target path with pdf files with changes verification" )] struct Args { - #[arg(help = "Source directory with .odt files")] + #[arg(help = "Source directory with .odt, .doc, or .docx files")] source: PathBuf, #[arg(help = "Target directory for PDFs converted files")]