for entry in entries {
let path = entry.unwrap().path();
let relative_path = path.strip_prefix(&root_path).unwrap();
- if relative_path.starts_with(".git") {
+ if relative_path.starts_with(".git") || relative_path.starts_with(".gitignore") {
continue;
}
if path.is_dir() {
pub struct Strategy {}
use std::path::PathBuf;
+use std::fs::{copy, create_dir_all};
use crate::file_handler::{File, FileType, FileHandlerStrategy};
}
}
- fn handle(&self, file: &File) {
- println!("Should copy {}", file.path.display())
+ fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File) {
+ let relative_path = file.path.strip_prefix(&source).unwrap();
+ let complete_destination = destination.join(relative_path);
+ let destination_parent = complete_destination.parent().unwrap();
+ create_dir_all(destination_parent).unwrap();
+ copy(&file.path, &complete_destination).unwrap();
}
}
}
}
- fn handle(&self, file: &File) {
+ fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File) {
println!("Should parse and copy {}", file.path.display())
}
}
}
}
- fn handle(&self, _file: &File) {}
+ // We don't implement handling for layout, as we assume there's only one
+ // and it got handled before.
+ fn handle(&self, _s: &PathBuf, _d: &PathBuf, _f: &File) {}
}
pub fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File) {
for strategy in self.strategies.iter() {
if strategy.can_handle(&file.file_type) {
- return strategy.handle(file);
+ return strategy.handle(source, destination, file);
}
}
}
fn is(&self, path: &PathBuf) -> bool;
fn identify(&self) -> FileType;
fn can_handle(&self, file_type: &FileType) -> bool;
- fn handle(&self, file: &File);
+ fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File);
}
pub enum FileType {
use std::io::Result;
use std::env::current_dir;
-use std::fs::create_dir_all;
+use std::fs::{create_dir_all, remove_dir_all};
use crate::gemini_parser::parse;
use crate::file_finder::find_files;
let files = find_files(&source);
// Step 2. Prepare the target priority
+ match remove_dir_all(&destination) {
+ _ => {}
+ };
create_dir_all(&destination)?;
println!("Found {} files", files.len());