Skip to main content

coven_storage/
folder_label.rs

1//! A folder's name and web address, as the account a connection signs in
2//! with names them (ยง20.2): display labels each connection reads again, so
3//! a device shows the folder as its provider names it now.
4
5use crate::{
6    DropboxLocation, ProviderOps, Storage, StorageConfig, StorageConnection, StorageError,
7};
8
9impl<P: ProviderOps + ?Sized> StorageConnection<P> {
10    /// This connection's location with its folder's label as the provider
11    /// answers it now: a Dropbox shared folder's or a OneDrive folder's.
12    /// Other locations have none and send no request. A failed read keeps
13    /// its provider cause.
14    pub async fn labelled_config(&self) -> Result<StorageConfig, StorageError> {
15        let mut config = self.config();
16        match &mut config {
17            StorageConfig::Dropbox {
18                location: DropboxLocation::SharedFolder { .. },
19                folder_label,
20                ..
21            }
22            | StorageConfig::OneDrive { folder_label, .. } => {
23                let read = self
24                    .resent(move || async move {
25                        self.cooling()?;
26                        let read = self
27                            .send(crate::RequestKind::Status, 0, self.provider.folder_label())
28                            .await;
29                        self.observed(read).await
30                    })
31                    .await?;
32                *folder_label = Some(read);
33            }
34            StorageConfig::Dropbox { location: DropboxLocation::AppFolder, .. }
35            | StorageConfig::S3 { .. }
36            | StorageConfig::CloudKit { .. } => {}
37        }
38        Ok(config)
39    }
40}