]> git.r.bdr.sh - rbdr/page/blob - src/file_handler/file_strategies/file.rs
Add license
[rbdr/page] / src / file_handler / file_strategies / file.rs
1 pub struct Strategy {}
2
3 use std::path::PathBuf;
4 use std::fs::{copy, create_dir_all};
5
6 use crate::file_handler::{File, FileType, FileHandlerStrategy};
7
8 impl 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 }