fn build()

in core/src/services/icloud/backend.rs [161:238]


    fn build(self) -> Result<impl Access> {
        let root = normalize_root(&self.config.root.unwrap_or_default());

        let apple_id = match &self.config.apple_id {
            Some(apple_id) => Ok(apple_id.clone()),
            None => Err(Error::new(ErrorKind::ConfigInvalid, "apple_id is empty")
                .with_operation("Builder::build")
                .with_context("service", Scheme::Icloud)),
        }?;

        let password = match &self.config.password {
            Some(password) => Ok(password.clone()),
            None => Err(Error::new(ErrorKind::ConfigInvalid, "password is empty")
                .with_operation("Builder::build")
                .with_context("service", Scheme::Icloud)),
        }?;

        let ds_web_auth_token = match &self.config.ds_web_auth_token {
            Some(ds_web_auth_token) => Ok(ds_web_auth_token.clone()),
            None => Err(
                Error::new(ErrorKind::ConfigInvalid, "ds_web_auth_token is empty")
                    .with_operation("Builder::build")
                    .with_context("service", Scheme::Icloud),
            ),
        }?;

        let trust_token = match &self.config.trust_token {
            Some(trust_token) => Ok(trust_token.clone()),
            None => Err(Error::new(ErrorKind::ConfigInvalid, "trust_token is empty")
                .with_operation("Builder::build")
                .with_context("service", Scheme::Icloud)),
        }?;

        let session_data = SessionData::new();

        let info = AccessorInfo::default();
        info.set_scheme(Scheme::Icloud)
            .set_root(&root)
            .set_native_capability(Capability {
                stat: true,
                stat_has_content_length: true,
                stat_has_last_modified: true,

                read: true,

                shared: true,
                ..Default::default()
            });

        // allow deprecated api here for compatibility
        #[allow(deprecated)]
        if let Some(client) = self.http_client {
            info.update_http_client(|_| client);
        }

        let accessor_info = Arc::new(info);

        let signer = IcloudSigner {
            info: accessor_info.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,
            initiated: false,
        };

        let signer = Arc::new(Mutex::new(signer));
        Ok(IcloudBackend {
            core: Arc::new(IcloudCore {
                info: accessor_info,
                signer: signer.clone(),
                root,
                path_cache: PathCacher::new(IcloudPathQuery::new(signer.clone())),
            }),
        })
    }