Skip to content

Commit

Permalink
refactor path_cache trait
Browse files Browse the repository at this point in the history
Signed-off-by: bokket <[email protected]>
  • Loading branch information
bokket committed Jan 17, 2024
1 parent 131cd41 commit 6c94ae9
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 158 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Major components of the project include:

- gdrive: [Google Drive](https://www.google.com/drive/) *being worked on*
- onedrive: [OneDrive](https://www.microsoft.com/en-us/microsoft-365/onedrive/online-cloud-storage) *being worked on*
- icloud: [Icloud Drive](https://www.icloud.com.cn/iclouddrive/) *being worked on*

</details>

Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ services-http = []
services-huggingface = []
services-ipfs = ["dep:prost"]
services-ipmfs = []
services-icloud = []
services-icloud = ["internal-path-cache"]
services-libsql = ["dep:hrana-client-proto"]
services-memcached = ["dep:bb8"]
services-memory = []
Expand Down
34 changes: 20 additions & 14 deletions core/src/services/icloud/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::raw::*;
use crate::*;
use crate::{Builder, Capability, Error, ErrorKind, Scheme};

use super::client::Client;
use super::client::{Client, IcloudPathQuery};
use super::core::{parse_error, IcloudSigner, SessionData};

/// Config for icloud services support.
Expand Down Expand Up @@ -101,7 +101,12 @@ impl IcloudBuilder {
///
/// All operations will happen under this root.
pub fn root(&mut self, root: &str) -> &mut Self {
self.config.root = Some(root.to_string());
self.config.root = if root.is_empty() {
None
} else {
Some(root.to_string())
};

self
}

Expand Down Expand Up @@ -182,7 +187,6 @@ impl Builder for IcloudBuilder {
fn from_map(map: HashMap<String, String>) -> Self {
let config = IcloudConfig::deserialize(ConfigDeserializer::new(map))
.expect("config deserialize must succeed");

IcloudBuilder {
config,
http_client: None,
Expand Down Expand Up @@ -238,20 +242,22 @@ impl Builder for IcloudBuilder {

let session_data = SessionData::new();

let core = IcloudSigner {
client: client.clone(),
data: session_data,
apple_id,
password,
trust_token: Some(trust_token),
ds_web_auth_token: Some(ds_web_auth_token),
is_china_mainland: self.config.is_china_mainland,
};

let core = Arc::new(Mutex::new(core));
Ok(IcloudBackend {
client: Arc::new(Client {
core: Arc::new(Mutex::new(IcloudSigner {
client,

data: session_data,
apple_id,
password,
trust_token: Some(trust_token),
ds_web_auth_token: Some(ds_web_auth_token),
is_china_mainland: self.config.is_china_mainland,
})),
core: core.clone(),
root,
path_cache: Arc::new(Default::default()),
path_cache: PathCacher::new(IcloudPathQuery::new(client, core.clone())).with_lock(),
}),
})
}
Expand Down
Loading

0 comments on commit 6c94ae9

Please sign in to comment.