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
|
//! Utility module which handles filesystem writes
use std::path::PathBuf;
use std::fs::{self, OpenOptions};
use lcc::traits::AutoEncoder;
pub struct Filesystem {
name: String,
path: String,
root: PathBuf,
}
/// A switching enum to determine what type of file to load
pub enum FileType {
/// A data record file
Record,
/// A vault/ zser metadata file
Metadata,
/// A simple checksum file
Checksum
}
impl Filesystem {
pub fn create(path: &str, name: &str) -> Filesystem {
let mut buffer = PathBuf::new();
buffer.push(path);
buffer.push(format!("{}.vault", name));
Filesystem {
name: name.to_owned(),
path: path.to_owned(),
root: buffer,
}
}
/// Create required directories
pub fn scaffold(&self) -> Option<()> {
fs::create_dir_all(&self.root).ok()?;
fs::create_dir(&self.root.join("records")).ok()?;
fs::create_dir(&self.root.join("metadata")).ok()?;
fs::create_dir(&self.root.join("checksums")).ok()?;
Some(())
}
/// Load all files of a certain type into a Vec<String>
pub fn fetch<T: AutoEncoder>(&self, types: FileType) -> Vec<T> {
unimplemented!()
}
/// Load a single file of a certain type
pub fn pull<T: AutoEncoder>(&self, ftype: FileType, id: &str) -> T {
unimplemented!()
}
}
|