cc_sync_session/filesystem/
mod.rs1mod real;
2
3pub use real::RealFileSystem;
4
5use std::path::{Path, PathBuf};
6use std::time::SystemTime;
7use thiserror::Error;
8
9#[derive(Debug, Error)]
10pub enum FileSystemError {
11 #[error("IO error: {0}")]
12 Io(#[from] std::io::Error),
13
14 #[error("Path error: {0}")]
15 PathError(String),
16
17 #[error("Not found: {0}")]
18 NotFound(PathBuf),
19}
20
21pub type Result<T> = std::result::Result<T, FileSystemError>;
22
23#[derive(Debug, Clone)]
24pub struct EntryMetadata {
25 pub path: PathBuf,
26 pub modified: SystemTime,
27 pub is_directory: bool,
28}
29
30pub trait FileSystem: Send + Sync {
31 fn list_directory(&self, path: &Path) -> Result<Vec<EntryMetadata>>;
32
33 fn get_metadata(&self, path: &Path) -> Result<EntryMetadata>;
34
35 fn copy_file(&self, from: &Path, to: &Path) -> Result<()>;
36
37 fn create_directory(&self, path: &Path) -> Result<()>;
38
39 fn exists(&self, path: &Path) -> Result<bool>;
40
41 fn set_modified_time(&self, path: &Path, time: SystemTime) -> Result<()>;
42}