@@ -8,7 +8,7 @@ use std::{
8
8
collections:: HashMap ,
9
9
fs,
10
10
path:: { Path , PathBuf } ,
11
- sync:: { Arc , Mutex } ,
11
+ sync:: { Arc , Mutex , MutexGuard } ,
12
12
time:: Duration ,
13
13
} ;
14
14
use tauri:: { path:: BaseDirectory , AppHandle , Emitter , Manager , Resource , ResourceId , Runtime } ;
@@ -170,10 +170,11 @@ impl<R: Runtime> StoreBuilder<R> {
170
170
self
171
171
}
172
172
173
- pub ( crate ) fn build_inner ( mut self , load : bool ) -> crate :: Result < ( Arc < Store < R > > , ResourceId ) > {
174
- let state = self . app . state :: < StoreState > ( ) ;
175
- let mut stores = state. stores . lock ( ) . unwrap ( ) ;
176
-
173
+ pub ( crate ) fn build_inner (
174
+ mut self ,
175
+ load : bool ,
176
+ mut stores : MutexGuard < ' _ , HashMap < PathBuf , ResourceId > > ,
177
+ ) -> crate :: Result < ( Arc < Store < R > > , ResourceId ) > {
177
178
if stores. contains_key ( & self . path ) {
178
179
return Err ( crate :: Error :: AlreadyExists ( self . path ) ) ;
179
180
}
@@ -227,7 +228,8 @@ impl<R: Runtime> StoreBuilder<R> {
227
228
}
228
229
229
230
pub ( crate ) fn create_inner ( self ) -> crate :: Result < ( Arc < Store < R > > , ResourceId ) > {
230
- self . build_inner ( false )
231
+ let stores = self . app . state :: < StoreState > ( ) . stores . clone ( ) ;
232
+ self . build_inner ( false , stores. lock ( ) . unwrap ( ) )
231
233
}
232
234
233
235
/// Get the existing store with the same path or creates a new [`Store`].
@@ -251,14 +253,13 @@ impl<R: Runtime> StoreBuilder<R> {
251
253
}
252
254
253
255
pub ( crate ) fn new_or_existing_inner ( self ) -> crate :: Result < ( Arc < Store < R > > , ResourceId ) > {
254
- {
255
- let state = self . app . state :: < StoreState > ( ) ;
256
- let stores = state. stores . lock ( ) . unwrap ( ) ;
257
- if let Some ( rid) = stores. get ( & self . path ) {
258
- return Ok ( ( self . app . resources_table ( ) . get ( * rid) . unwrap ( ) , * rid) ) ;
259
- }
256
+ let stores = self . app . state :: < StoreState > ( ) . stores . clone ( ) ;
257
+ let stores_ = stores. lock ( ) . unwrap ( ) ;
258
+ if let Some ( rid) = stores_. get ( & self . path ) {
259
+ return Ok ( ( self . app . resources_table ( ) . get ( * rid) . unwrap ( ) , * rid) ) ;
260
260
}
261
- self . build_inner ( true )
261
+
262
+ self . build_inner ( true , stores_)
262
263
}
263
264
}
264
265
0 commit comments