1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// use std::path::Path;
// use crate::{ArcResult, ArchiveData};
// use std::collections::HashMap;
// use std::fs::{create_dir, File, OpenOptions};
// use std::io::Write;
//
//
// pub fn resume_archive<P : AsRef<Path>>(dir_path : P, data : &ArchiveData, overwrite : bool) -> ArcResult<()>{
// let dir_path = dir_path.as_ref();
// let mut folders = FolderItem::new();
// for (rel_path, _data) in data.iter() {
// let path = Path::new(rel_path);
// let ancs = get_ancestor_names(path)?;
// folders.set_ancestor_names(&ancs)
// }
// folders.create_folders(dir_path);
//
// for (rel_path, data) in data.iter(){
// let path = dir_path.join(rel_path);
// let mut file = if overwrite{
// File::create(&path)?
// } else {
// OpenOptions::new()
// .write(true)
// .create_new(true)
// .open(&path)?
// };
//
// file.write_all(data)?;
// }
// Ok(())
// }
//
// fn get_ancestor_names(path : &Path) -> ArcResult<Vec<String>>{
// let mut v : Vec<String> = vec![];
// for p in path.ancestors().skip(1){
// if let Some(filename) = p.file_name() {
// v.push(filename.to_string_lossy().to_string());
// }
// }
// v.reverse();
// Ok(v)
// }
//
// struct FolderItem{
// folders : HashMap<String, FolderItem>
// }
//
// impl FolderItem{
// fn new() -> FolderItem{ FolderItem{ folders : HashMap::new() } }
//
// fn set_ancestor_names(&mut self, ancs : &[String]){
// if ancs.len() == 0{ return; }
// if self.folders.contains_key(&ancs[0]) == false{
// self.folders.insert(ancs[0].clone(), FolderItem::new());
// }
// self.folders.get_mut(&ancs[0]).unwrap().set_ancestor_names(&ancs[1..]);
// }
//
// fn create_folders(&self, current_path : &Path){
// for (name, f) in &self.folders{
// let folder_path = current_path.join(name);
//
// create_dir(&folder_path).ok(); //できなければ出来ないで良い
//
// f.create_folders(&folder_path);
// }
// }
// }