-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e280c80
commit 46e92be
Showing
6 changed files
with
132 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
use crate::config::CloudOptions; | ||
pub use anyhow::Result; | ||
pub use std::path::Path; | ||
use tokio::fs; | ||
use dashmap::DashSet; | ||
pub use std::path::{Path, PathBuf}; | ||
|
||
pub enum Operation { | ||
Write(PathBuf), // Load file from cloud | ||
WriteEmpty(PathBuf), | ||
Save(PathBuf), // Save local file to cloud | ||
} | ||
|
||
#[async_trait] | ||
pub trait CloudAdapter { | ||
fn new(options: CloudOptions) -> Self; | ||
async fn sync(&self) -> Result<u32>; | ||
async fn init(options: CloudOptions) -> Self; | ||
async fn sync(&self) -> Result<(DashSet<PathBuf>, Vec<Operation>)>; | ||
async fn get(&self, path: &Path) -> Result<Vec<u8>>; | ||
async fn exists(&self, path: &Path) -> Result<bool>; | ||
async fn delete(&self, path: &Path) -> Result<()>; | ||
async fn save(&self, path: &Path) -> Result<()>; | ||
async fn save(&self, path: &Path, content: &[u8]) -> Result<()>; | ||
async fn rename(&self, oldpath: &Path, path: &Path) -> Result<()>; | ||
async fn read_file(path: &Path) -> Result<Vec<u8>> { | ||
Ok(fs::read(path).await?) | ||
} | ||
fn kind(&self) -> &'static str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.