]>
Commit | Line | Data |
---|---|---|
1e2d00b6 RBR |
1 | pub struct Strategy {} |
2 | ||
3 | use std::path::PathBuf; | |
ea529736 | 4 | use std::fs::{copy, create_dir_all}; |
1e2d00b6 | 5 | |
4fd89b80 | 6 | use crate::file_handler::{File, FileType, FileHandlerStrategy}; |
1e2d00b6 | 7 | |
dd0a540c RBR |
8 | impl Strategy { |
9 | fn handle(&self, source: &PathBuf, destination: &PathBuf, file: &File) { | |
10 | let relative_path = file.path.strip_prefix(&source).unwrap(); | |
11 | let complete_destination = destination.join(relative_path); | |
12 | let destination_parent = complete_destination.parent().unwrap(); | |
13 | create_dir_all(destination_parent).unwrap(); | |
14 | copy(&file.path, &complete_destination).unwrap(); | |
15 | } | |
16 | } | |
17 | ||
1e2d00b6 RBR |
18 | impl FileHandlerStrategy for Strategy { |
19 | fn is(&self, path: &PathBuf) -> bool { | |
20 | !path.is_dir() | |
21 | } | |
22 | ||
23 | fn identify(&self) -> FileType { | |
24 | FileType::File | |
25 | } | |
26 | ||
4fd89b80 RBR |
27 | fn can_handle(&self, file_type: &FileType) -> bool { |
28 | match file_type { | |
29 | FileType::File => true, | |
30 | _ => false, | |
31 | } | |
1e2d00b6 RBR |
32 | } |
33 | ||
dd0a540c RBR |
34 | fn handle_html(&self, source: &PathBuf, destination: &PathBuf, file: &File, _l: &String) { |
35 | return self.handle(source, destination, file); | |
36 | } | |
37 | ||
38 | fn handle_gemini(&self, source: &PathBuf, destination: &PathBuf, file: &File) { | |
39 | return self.handle(source, destination, file); | |
1e2d00b6 RBR |
40 | } |
41 | } |