]> git.r.bdr.sh - rbdr/page/blame_incremental - src/file_handler/file_strategies/file.rs
Update behavior about hidden files
[rbdr/page] / src / file_handler / file_strategies / file.rs
... / ...
CommitLineData
1pub struct Strategy {}
2
3use std::path::PathBuf;
4use std::fs::{copy, create_dir_all};
5
6use crate::file_handler::{File, FileType, FileHandlerStrategy};
7
8impl FileHandlerStrategy for Strategy {
9 fn is(&self, path: &PathBuf) -> bool {
10 !path.is_dir()
11 }
12
13 fn identify(&self) -> FileType {
14 FileType::File
15 }
16
17 fn can_handle(&self, file_type: &FileType) -> bool {
18 match file_type {
19 FileType::File => true,
20 _ => false,
21 }
22 }
23
24 fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File) {
25 let relative_path = file.path.strip_prefix(&source).unwrap();
26 let complete_destination = destination.join(relative_path);
27 let destination_parent = complete_destination.parent().unwrap();
28 create_dir_all(destination_parent).unwrap();
29 copy(&file.path, &complete_destination).unwrap();
30 }
31}