fix: correct path handling in directory processing
- Fix duplicate subdirectory creation bug when processing nested directories - Change relative path calculation to use current directory instead of root - Remove redundant subdirectory creation code - Improve path display in logs to show cleaner relative paths
This commit is contained in:
parent
4bfd43e1e0
commit
a0b78e3c7e
@ -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")
|
||||
|
@ -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")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user