@@ -91,7 +91,8 @@ impl Vault {
91
91
let key_file = key_file. map ( std:: convert:: Into :: into) ;
92
92
create_new_vault_dir ( & path) ?;
93
93
94
- let master_key_dto = generate_master_key ( password, key_file. as_ref ( ) . map ( std:: convert:: AsRef :: as_ref) ) ?;
94
+ let master_key_dto =
95
+ generate_master_key ( password, key_file. as_ref ( ) . map ( std:: convert:: AsRef :: as_ref) ) ?;
95
96
96
97
let salt = generate_salt ( ) ;
97
98
let nonce = generate_chacha20_nonce ( ) ?;
@@ -304,18 +305,21 @@ impl Vault {
304
305
305
306
/// Insert a new [`Group`](Group) into this [`Vault`](Vault).
306
307
pub fn insert_group ( & mut self , group : Group ) {
307
- // Insert into parent's children.
308
- let _ = group
309
- . parent ( )
310
- . as_ref ( )
311
- . and_then ( |parent| self . children . get_mut ( parent) )
312
- . filter ( |parent| !parent. groups ( ) . contains ( group. uuid ( ) ) ) // TODO: find better way
313
- . map ( |parent| parent. groups_mut ( ) . push ( group. uuid ( ) . clone ( ) ) ) ;
314
- // Add own children.
315
- drop (
316
- self . children
317
- . insert ( group. uuid ( ) . clone ( ) , Children :: default ( ) ) ,
318
- ) ;
308
+ if !self . groups ( ) . contains_key ( group. uuid ( ) ) {
309
+ // Insert into parent's children.
310
+ let _ = group
311
+ . parent ( )
312
+ . as_ref ( )
313
+ . and_then ( |parent| self . children . get_mut ( parent) )
314
+ . filter ( |parent| !parent. groups ( ) . contains ( group. uuid ( ) ) ) // TODO: find better way
315
+ . map ( |parent| parent. groups_mut ( ) . push ( group. uuid ( ) . clone ( ) ) ) ;
316
+ // Add own children.
317
+ drop (
318
+ self . children
319
+ . insert ( group. uuid ( ) . clone ( ) , Children :: default ( ) ) ,
320
+ ) ;
321
+ }
322
+
319
323
drop ( self . groups . insert ( group. uuid ( ) . clone ( ) , group) ) ;
320
324
}
321
325
0 commit comments