@@ -161,6 +161,7 @@ impl StoredCredential {
161
161
162
162
struct StorageWithLastRead {
163
163
storage : Box < dyn StorageImplementation > ,
164
+ fallback_storage : Option < FileStorage > ,
164
165
last_read : Cell < Result < Option < StoredCredential > , WrappedError > > ,
165
166
}
166
167
@@ -392,14 +393,18 @@ impl Auth {
392
393
let mut keyring_storage = ThreadKeyringStorage :: default ( ) ;
393
394
let mut file_storage = FileStorage ( PersistedState :: new ( self . file_storage_path . clone ( ) ) ) ;
394
395
395
- let keyring_storage_result = match std:: env:: var ( "VSCODE_CLI_USE_FILE_KEYCHAIN" ) {
396
- Ok ( _) => Err ( wrap ( "" , "user prefers file storage" ) . into ( ) ) ,
397
- _ => keyring_storage. read ( ) ,
396
+ let native_storage_result = if std:: env:: var ( "VSCODE_CLI_USE_FILE_KEYCHAIN" ) . is_ok ( )
397
+ || self . file_storage_path . exists ( )
398
+ {
399
+ Err ( wrap ( "" , "user prefers file storage" ) . into ( ) )
400
+ } else {
401
+ keyring_storage. read ( )
398
402
} ;
399
403
400
- let mut storage = match keyring_storage_result {
404
+ let mut storage = match native_storage_result {
401
405
Ok ( v) => StorageWithLastRead {
402
406
last_read : Cell :: new ( Ok ( v) ) ,
407
+ fallback_storage : Some ( file_storage) ,
403
408
storage : Box :: new ( keyring_storage) ,
404
409
} ,
405
410
Err ( e) => {
@@ -410,6 +415,7 @@ impl Auth {
410
415
. read ( )
411
416
. map_err ( |e| wrap ( e, "could not read from file storage" ) ) ,
412
417
) ,
418
+ fallback_storage : None ,
413
419
storage : Box :: new ( file_storage) ,
414
420
}
415
421
}
@@ -531,7 +537,18 @@ impl Auth {
531
537
"Failed to update keyring with new credentials: {}" ,
532
538
e
533
539
) ;
540
+
541
+ if let Some ( fb) = storage. fallback_storage . take ( ) {
542
+ storage. storage = Box :: new ( fb) ;
543
+ match storage. storage . store ( creds. clone ( ) ) {
544
+ Err ( e) => {
545
+ warning ! ( self . log, "Also failed to update fallback storage: {}" , e)
546
+ }
547
+ Ok ( _) => debug ! ( self . log, "Updated fallback storage successfully" ) ,
548
+ }
549
+ }
534
550
}
551
+
535
552
storage. last_read . set ( Ok ( Some ( creds) ) ) ;
536
553
} )
537
554
}
0 commit comments