Skip to content

Commit 6781d6f

Browse files
committed
Tidy storage APIs.
1 parent 414a81b commit 6781d6f

File tree

10 files changed

+101
-111
lines changed

10 files changed

+101
-111
lines changed

crates/account/src/local_account.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl LocalAccount {
157157

158158
#[allow(unused_mut)]
159159
let mut storage = ClientStorage::new_authenticated(
160-
*account_id,
160+
account_id,
161161
BackendTarget::FileSystem(paths),
162162
user,
163163
)
@@ -641,7 +641,7 @@ impl LocalAccount {
641641
let paths = Paths::new(data_dir, account_id.to_string());
642642

643643
let storage = ClientStorage::new_unauthenticated(
644-
account_id,
644+
&account_id,
645645
BackendTarget::FileSystem(paths.clone()),
646646
)
647647
.await?;
@@ -713,7 +713,7 @@ impl LocalAccount {
713713
let (authenticated_user, public_account) = new_account.into();
714714

715715
let mut storage = ClientStorage::new_authenticated(
716-
account_id,
716+
&account_id,
717717
BackendTarget::FileSystem(paths),
718718
authenticated_user,
719719
/*
@@ -781,7 +781,7 @@ impl Account for LocalAccount {
781781
let paths = self.paths();
782782

783783
let mut storage = ClientStorage::new_unauthenticated(
784-
account_id,
784+
&account_id,
785785
BackendTarget::FileSystem((&*paths).clone()),
786786
)
787787
.await?;
@@ -1213,10 +1213,11 @@ impl Account for LocalAccount {
12131213
}
12141214

12151215
async fn root_commit(&self, summary: &Summary) -> Result<CommitHash> {
1216-
let folder =
1217-
self.storage.folders().get(summary.id()).ok_or_else(|| {
1218-
StorageError::FolderNotFound(*summary.id())
1219-
})?;
1216+
let folder = self
1217+
.storage
1218+
.folders()
1219+
.get(summary.id())
1220+
.ok_or_else(|| StorageError::FolderNotFound(*summary.id()))?;
12201221
let event_log = folder.event_log();
12211222
let log_file = event_log.read().await;
12221223
Ok(log_file
@@ -1337,10 +1338,11 @@ impl Account for LocalAccount {
13371338
.await?
13381339
.ok_or(Error::NoFolderPassword(*summary.id()))?;
13391340

1340-
let folder =
1341-
self.storage.folders().get(summary.id()).ok_or_else(|| {
1342-
StorageError::FolderNotFound(*summary.id())
1343-
})?;
1341+
let folder = self
1342+
.storage
1343+
.folders()
1344+
.get(summary.id())
1345+
.ok_or_else(|| StorageError::FolderNotFound(*summary.id()))?;
13441346

13451347
let event_log = folder.event_log();
13461348
let log_file = event_log.read().await;

crates/database_upgrader/src/upgrader/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async fn compute_fs_account_status(
129129
) -> Result<SyncStatus> {
130130
let sync_status = if account_paths.is_server() {
131131
let storage = ServerStorage::new(
132-
account_paths.documents_dir(),
132+
account_paths,
133133
account.account_id(),
134134
BackendTarget::FileSystem(account_paths.clone()),
135135
)
@@ -138,7 +138,7 @@ async fn compute_fs_account_status(
138138
storage.sync_status().await?
139139
} else {
140140
let storage = ClientStorage::new_unauthenticated(
141-
*account.account_id(),
141+
account.account_id(),
142142
BackendTarget::FileSystem(account_paths.clone()),
143143
)
144144
.await?;
@@ -156,14 +156,15 @@ async fn compute_db_account_status(
156156
) -> Result<SyncStatus> {
157157
let sync_status = if account_paths.is_server() {
158158
let storage = ServerStorage::new(
159-
account_paths.documents_dir(),
159+
account_paths,
160160
account.account_id(),
161161
BackendTarget::Database(client.clone()),
162162
)
163163
.await?;
164164
storage.sync_status().await?
165165
} else {
166-
todo!("compute for client accounts");
166+
Default::default()
167+
// todo!("compute for client accounts");
167168
/*
168169
let storage = ClientFileSystemStorage::new_unauthenticated(
169170
*account.account_id(),

crates/login/src/identity_folder.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,6 @@ impl IdentityFolder {
593593
account_id: AccountId,
594594
keeper: &AccessPoint,
595595
) -> Result<(UrnLookup, PrivateIdentity)> {
596-
println!("doing login private identity...");
597-
598596
let (index, identity_secret) =
599597
Self::lookup_identity_secrets(keeper).await?;
600598

crates/server/src/backend.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ impl Backend {
8080
"server_backend::read_dir",
8181
);
8282

83+
let paths = Paths::new_global_server(&self.directory);
84+
8385
let account = ServerStorage::new(
84-
&self.directory,
86+
&paths,
8587
&account_id,
86-
BackendTarget::FileSystem(
87-
Paths::new_global_server(&self.directory),
88-
),
88+
BackendTarget::FileSystem(paths.clone()),
8989
)
9090
.await?;
9191

@@ -121,9 +121,13 @@ impl Backend {
121121
"server_backend::create_account",
122122
);
123123

124-
let account = ServerStorage::create_fs_account(
125-
&self.directory,
124+
let paths = Paths::new_global_server(&self.directory)
125+
.with_account_id(account_id);
126+
127+
let account = ServerStorage::create_account(
128+
&paths,
126129
account_id,
130+
BackendTarget::FileSystem(paths.clone()),
127131
&account_data,
128132
)
129133
.await?;

crates/storage/client/src/filesystem/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub struct ClientFileSystemStorage {
117117
impl ClientFileSystemStorage {
118118
/// Create unauthenticated folder storage for client-side access.
119119
pub async fn new_unauthenticated(
120-
account_id: AccountId,
120+
account_id: &AccountId,
121121
paths: Paths,
122122
) -> Result<Self> {
123123
paths.ensure().await?;
@@ -142,7 +142,7 @@ impl ClientFileSystemStorage {
142142
let paths = Arc::new(paths);
143143

144144
let mut storage = Self {
145-
account_id,
145+
account_id: *account_id,
146146
summaries: Vec::new(),
147147
current: Arc::new(Mutex::new(None)),
148148
folders: Default::default(),
@@ -169,7 +169,7 @@ impl ClientFileSystemStorage {
169169

170170
/// Create folder storage for client-side access.
171171
pub async fn new_authenticated(
172-
account_id: AccountId,
172+
account_id: &AccountId,
173173
paths: Paths,
174174
authenticated_user: Identity,
175175
/*
@@ -214,7 +214,7 @@ impl ClientFileSystemStorage {
214214
let paths = Arc::new(paths);
215215

216216
Ok(Self {
217-
account_id,
217+
account_id: *account_id,
218218
summaries: Vec::new(),
219219
current: Arc::new(Mutex::new(None)),
220220
folders: Default::default(),

crates/storage/client/src/storage.rs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub enum ClientStorage {
5656
impl ClientStorage {
5757
/// Create new client storage.
5858
pub async fn new_unauthenticated(
59-
account_id: AccountId,
59+
account_id: &AccountId,
6060
target: BackendTarget,
6161
) -> Result<Self> {
6262
match target {
@@ -71,7 +71,7 @@ impl ClientStorage {
7171

7272
/// Create new client storage in authenticated state.
7373
pub async fn new_authenticated(
74-
account_id: AccountId,
74+
account_id: &AccountId,
7575
target: BackendTarget,
7676
authenticated_user: Identity,
7777
) -> Result<Self> {
@@ -97,9 +97,11 @@ impl ClientStorage {
9797

9898
/// Create new file system storage.
9999
async fn new_unauthenticated_fs(
100-
account_id: AccountId,
100+
account_id: &AccountId,
101101
paths: Paths,
102102
) -> Result<Self> {
103+
debug_assert!(!paths.is_server());
104+
103105
Ok(Self::FileSystem(
104106
ClientFileSystemStorage::new_unauthenticated(account_id, paths)
105107
.await?,
@@ -108,56 +110,36 @@ impl ClientStorage {
108110

109111
/// Create new file system storage in authenticated state.
110112
async fn new_authenticated_fs(
111-
account_id: AccountId,
113+
account_id: &AccountId,
112114
paths: Paths,
113115
authenticated_user: Identity,
114116
) -> Result<Self> {
117+
debug_assert!(!paths.is_server());
118+
115119
Ok(Self::FileSystem(
116120
ClientFileSystemStorage::new_authenticated(
117121
account_id,
118122
paths,
119123
authenticated_user,
120-
/*
121-
identity_log,
122-
device,
123-
*/
124124
)
125125
.await?,
126126
))
127127
}
128128

129129
/// Create new file system storage.
130130
async fn new_unauthenticated_db(
131-
account_id: AccountId,
131+
account_id: &AccountId,
132132
client: Client,
133133
) -> Result<Self> {
134-
/*
135-
Ok(Self::FileSystem(
136-
ClientFileSystemStorage::new_unauthenticated(account_id, paths).await?,
137-
))
138-
*/
139-
140134
todo!("unauthenticated db storage");
141135
}
142136

143137
/// Create new file system storage in authenticated state.
144138
async fn new_authenticated_db(
145-
account_id: AccountId,
139+
account_id: &AccountId,
146140
client: Client,
147141
authenticated_user: Identity,
148142
) -> Result<Self> {
149-
/*
150-
Ok(Self::FileSystem(
151-
ClientFileSystemStorage::new_authenticated(
152-
account_id,
153-
paths,
154-
identity_log,
155-
device,
156-
)
157-
.await?,
158-
))
159-
*/
160-
161143
todo!("authenticated db storage");
162144
}
163145
}

crates/storage/server/src/database/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,11 @@ impl ServerDatabaseStorage {
7373
pub async fn new(
7474
client: Client,
7575
account_id: AccountId,
76-
data_dir: Option<PathBuf>,
7776
identity_log: Arc<RwLock<FolderEventLog>>,
77+
paths: Paths,
7878
) -> Result<Self> {
79-
let data_dir = if let Some(data_dir) = data_dir {
80-
data_dir
81-
} else {
82-
Paths::data_dir().map_err(|_| Error::NoCache)?
83-
};
84-
85-
let dirs = Paths::new_server(data_dir, account_id.to_string());
86-
Self::new_client(client, Arc::new(dirs), account_id, identity_log)
79+
debug_assert!(!paths.is_global());
80+
Self::new_client(client, Arc::new(paths), account_id, identity_log)
8781
.await
8882
}
8983

@@ -101,8 +95,6 @@ impl ServerDatabaseStorage {
10195
.into());
10296
}
10397

104-
paths.ensure().await?;
105-
10698
let account_row =
10799
Self::lookup_account(&mut client, &account_id).await?;
108100

crates/storage/server/src/filesystem/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,12 @@ pub struct ServerFileStorage {
6060
impl ServerFileStorage {
6161
/// Create folder storage for server-side access.
6262
pub async fn new(
63+
paths: Paths,
6364
account_id: AccountId,
6465
identity_log: Arc<RwLock<FolderEventLog>>,
65-
data_dir: Option<PathBuf>,
6666
) -> Result<Self> {
67-
let data_dir = if let Some(data_dir) = data_dir {
68-
data_dir
69-
} else {
70-
Paths::data_dir().map_err(|_| Error::NoCache)?
71-
};
72-
73-
let dirs = Paths::new_server(data_dir, account_id.to_string());
74-
Self::new_paths(Arc::new(dirs), account_id, identity_log).await
67+
debug_assert!(!paths.is_global());
68+
Self::new_paths(Arc::new(paths), account_id, identity_log).await
7569
}
7670

7771
/// Create new storage backed by files on disc.

0 commit comments

Comments
 (0)