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
use std::io::{Read, Result, Seek, Write};
use std::path::Path;
use std::sync::Arc;
mod default;
mod obfuscated;
pub use default::DefaultFileSystem;
pub use obfuscated::ObfuscatedFileSystem;
pub trait FileSystem: Send + Sync {
type Handle: Send + Sync + Handle;
type Reader: Seek + Read + Send;
type Writer: Seek + Write + Send + WriteExt;
fn create<P: AsRef<Path>>(&self, path: P) -> Result<Self::Handle>;
fn open<P: AsRef<Path>>(&self, path: P) -> Result<Self::Handle>;
fn delete<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn rename<P: AsRef<Path>>(&self, src_path: P, dst_path: P) -> Result<()>;
fn reuse<P: AsRef<Path>>(&self, src_path: P, dst_path: P) -> Result<()> {
self.rename(src_path, dst_path)
}
fn delete_metadata<P: AsRef<Path>>(&self, _path: P) -> Result<()> {
Ok(())
}
fn exists_metadata<P: AsRef<Path>>(&self, _path: P) -> bool {
false
}
fn new_reader(&self, handle: Arc<Self::Handle>) -> Result<Self::Reader>;
fn new_writer(&self, handle: Arc<Self::Handle>) -> Result<Self::Writer>;
}
pub trait Handle {
fn truncate(&self, offset: usize) -> Result<()>;
fn file_size(&self) -> Result<usize>;
fn sync(&self) -> Result<()>;
}
pub trait WriteExt {
fn truncate(&mut self, offset: usize) -> Result<()>;
fn allocate(&mut self, offset: usize, size: usize) -> Result<()>;
}