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
use std::time::SystemTime;
use std::path::Path;
use crate::error::FsResult;
use crate::common::hash::folder_name_to_hash;
use crate::imp::common::path::created_time_file::{ from_time_dat};
use std::fs::{File, Metadata};
use crate::imp::common::path::reserved_filename::CREATED_TIME_FILE_NAME;
pub fn get_hash_times<P : AsRef<Path>>(proj_dir : P) -> FsResult<Vec<(u128, SystemTime)>>{
let dir = std::fs::read_dir(proj_dir)?;
let mut r : Vec<(u128, SystemTime)> = vec![];
for entry in dir{
let entry = entry?;
let meta = entry.metadata()?;
if meta.is_dir(){
if let Some(hash) = folder_name_to_hash(&entry.file_name()){
let file_path = entry.path().join(CREATED_TIME_FILE_NAME);
let time = get_folder_time(file_path, &meta);
r.push((hash, time));
}
}
}
r.sort_by_key(|(_hash, time)| *time);
Ok(r)
}
fn get_folder_time<P : AsRef<Path>>(path : P, hash_dir_meta : &Metadata) -> SystemTime {
if let Ok(mut file) = File::open(path) {
if let Ok(time) = from_time_dat(&mut file){
return time;
}
}
if let Ok(time) = hash_dir_meta.created() {
return time;
}
SystemTime::UNIX_EPOCH
}