@@ -14,6 +14,7 @@ use oo7::{
14
14
portal:: { Item , Keyring } ,
15
15
Key ,
16
16
} ;
17
+ use tokio:: sync:: RwLock ;
17
18
use zbus:: {
18
19
proxy:: ProxyDefault ,
19
20
zvariant:: { ObjectPath , OwnedObjectPath , OwnedValue , Value } ,
@@ -26,7 +27,7 @@ use super::{
26
27
27
28
#[ derive( Debug ) ]
28
29
pub struct Service {
29
- collections : Vec < Collection > ,
30
+ collections : RwLock < Vec < Collection > > ,
30
31
keyring : Arc < Keyring > ,
31
32
cnx : Mutex < Option < zbus:: Connection > > ,
32
33
}
@@ -66,6 +67,13 @@ impl Service {
66
67
. unwrap ( ) ,
67
68
Arc :: clone ( & self . keyring ) ,
68
69
) ;
70
+ self . collections . write ( ) . await . push ( Collection :: new (
71
+ collection. label ( ) ,
72
+ alias,
73
+ * collection. created ( ) ,
74
+ Arc :: clone ( & self . keyring ) ,
75
+ ) ) ;
76
+
69
77
let path = OwnedObjectPath :: from ( collection. path ( ) ) ;
70
78
object_server. at ( & path, collection) . await ?;
71
79
let prompt = Prompt :: default ( ) ; // temp Prompt
@@ -113,7 +121,7 @@ impl Service {
113
121
let mut unlocked: Vec < OwnedObjectPath > = Vec :: new ( ) ;
114
122
115
123
' main: for object in objects {
116
- for collection in self . collections . iter ( ) {
124
+ for collection in self . collections . read ( ) . await . iter ( ) {
117
125
if collection. path ( ) == * object {
118
126
if collection. locked ( ) {
119
127
collection. set_locked ( false ) . await ;
@@ -144,7 +152,7 @@ impl Service {
144
152
let mut locked: Vec < OwnedObjectPath > = Vec :: new ( ) ;
145
153
146
154
for object in objects {
147
- for collection in self . collections . iter ( ) {
155
+ for collection in self . collections . read ( ) . await . iter ( ) {
148
156
if collection. path ( ) == * object && !collection. locked ( ) {
149
157
collection. set_locked ( true ) . await ;
150
158
locked. push ( object. clone ( ) ) ;
@@ -167,7 +175,7 @@ impl Service {
167
175
session : ObjectPath < ' _ > ,
168
176
) -> Result < HashMap < OwnedObjectPath , SecretInner > > {
169
177
let mut secrets = HashMap :: with_capacity ( paths. len ( ) ) ;
170
- for collection in & self . collections {
178
+ for collection in self . collections . read ( ) . await . iter ( ) {
171
179
let items = collection. items . read ( ) . await ;
172
180
for item in items. iter ( ) {
173
181
for path in paths. iter ( ) {
@@ -194,13 +202,12 @@ impl Service {
194
202
. unwrap_or_default ( )
195
203
}
196
204
197
- pub async fn set_alias (
205
+ pub fn set_alias (
198
206
& self ,
199
207
#[ zbus( signal_context) ] ctxt : SignalContext < ' _ > ,
200
208
alias : & str ,
201
209
path : ObjectPath < ' _ > ,
202
210
) -> Result < ( ) > {
203
- // WIP: not complete:: handle alias & default path '/' to remove the alias
204
211
match self . collections . iter ( ) . find ( |c| c. path ( ) == path) {
205
212
Some ( collection) => {
206
213
collection. set_alias ( & ctxt, alias) . await ?;
@@ -214,8 +221,10 @@ impl Service {
214
221
}
215
222
216
223
#[ zbus( property, name = "Collections" ) ]
217
- pub fn collections ( & self ) -> Vec < ObjectPath > {
224
+ pub async fn collections ( & self ) -> Vec < ObjectPath > {
218
225
self . collections
226
+ . read ( )
227
+ . await
219
228
. iter ( )
220
229
. map ( |collection| collection. path ( ) )
221
230
. collect ( )
@@ -243,7 +252,7 @@ impl Service {
243
252
impl Service {
244
253
pub async fn new ( ) -> Self {
245
254
Self {
246
- collections : Vec :: new ( ) ,
255
+ collections : RwLock :: new ( Vec :: new ( ) ) ,
247
256
keyring : Arc :: new ( Keyring :: load_default ( ) . await . unwrap ( ) ) ,
248
257
cnx : Default :: default ( ) ,
249
258
}
0 commit comments