Add the modification time to the List struct
This commit is contained in:
parent
a952765328
commit
1f1e4ed079
10
src/list.rs
10
src/list.rs
|
@ -4,12 +4,14 @@ use inflector::Inflector;
|
|||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
use std::time::SystemTime;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct List {
|
||||
pub id: String,
|
||||
pub index: i8,
|
||||
pub data: String,
|
||||
pub mtime: SystemTime,
|
||||
pub name: String,
|
||||
path: PathBuf
|
||||
}
|
||||
|
@ -21,13 +23,16 @@ impl List {
|
|||
}
|
||||
|
||||
pub fn update_data(&mut self, data : &String) {
|
||||
self.data = data.clone();
|
||||
let mut file = File::create(&self.path)
|
||||
.expect(&format!("Cannot open list file {}",
|
||||
self.path.to_str().unwrap()));
|
||||
file.write_all(data.as_bytes())
|
||||
.expect(&format!("Cannot write list file {}",
|
||||
self.path.to_str().unwrap()));
|
||||
|
||||
self.data = data.clone();
|
||||
let metadata = file.metadata().unwrap();
|
||||
self.mtime = metadata.modified().unwrap();
|
||||
}
|
||||
|
||||
pub fn load_all() -> Vec<Self> {
|
||||
|
@ -44,11 +49,14 @@ impl List {
|
|||
.expect(&format!("Cannot open list file {}", file_name));
|
||||
file.read_to_string(&mut data)
|
||||
.expect(&format!("Cannot read list file {}", file_name));
|
||||
let metadata = file.metadata()
|
||||
.expect(&format!("Cannot get metadata of list file {}", file_name));
|
||||
|
||||
let mut list = List {
|
||||
id: String::from(name),
|
||||
index : index,
|
||||
data: data,
|
||||
mtime: metadata.modified().unwrap(),
|
||||
name: String::from(name).to_title_case(),
|
||||
path: entry.clone()
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue