@@ -6,7 +6,7 @@ use rustc_hash::FxHashMap;
66use serde:: { Deserialize , Serialize } ;
77use thiserror:: Error ;
88use url:: Url ;
9- use uv_fs:: { LockedFile , LockedFileError , with_added_extension} ;
9+ use uv_fs:: { LockedFile , LockedFileError , LockedFileMode , with_added_extension} ;
1010use uv_preview:: { Preview , PreviewFeatures } ;
1111use uv_redacted:: DisplaySafeUrl ;
1212
@@ -29,15 +29,15 @@ pub enum AuthBackend {
2929}
3030
3131impl AuthBackend {
32- pub fn from_settings ( preview : Preview ) -> Result < Self , TomlCredentialError > {
32+ pub async fn from_settings ( preview : Preview ) -> Result < Self , TomlCredentialError > {
3333 // If preview is enabled, we'll use the system-native store
3434 if preview. is_enabled ( PreviewFeatures :: NATIVE_AUTH ) {
3535 return Ok ( Self :: System ( KeyringProvider :: native ( ) ) ) ;
3636 }
3737
3838 // Otherwise, we'll use the plaintext credential store
3939 let path = TextCredentialStore :: default_file ( ) ?;
40- match TextCredentialStore :: read ( & path) {
40+ match TextCredentialStore :: read ( & path) . await {
4141 Ok ( ( store, lock) ) => Ok ( Self :: TextStore ( store, lock) ) ,
4242 Err ( err)
4343 if err
@@ -46,7 +46,7 @@ impl AuthBackend {
4646 {
4747 Ok ( Self :: TextStore (
4848 TextCredentialStore :: default ( ) ,
49- TextCredentialStore :: lock ( & path) ?,
49+ TextCredentialStore :: lock ( & path) . await ?,
5050 ) )
5151 }
5252 Err ( err) => Err ( err) ,
@@ -255,12 +255,12 @@ impl TextCredentialStore {
255255 }
256256
257257 /// Acquire a lock on the credentials file at the given path.
258- pub fn lock ( path : & Path ) -> Result < LockedFile , TomlCredentialError > {
258+ pub async fn lock ( path : & Path ) -> Result < LockedFile , TomlCredentialError > {
259259 if let Some ( parent) = path. parent ( ) {
260260 fs:: create_dir_all ( parent) ?;
261261 }
262262 let lock = with_added_extension ( path, ".lock" ) ;
263- Ok ( LockedFile :: acquire_blocking ( lock, "credentials store" ) ?)
263+ Ok ( LockedFile :: acquire ( lock, LockedFileMode :: Exclusive , "credentials store" ) . await ?)
264264 }
265265
266266 /// Read credentials from a file.
@@ -291,8 +291,8 @@ impl TextCredentialStore {
291291 /// Returns [`TextCredentialStore`] and a [`LockedFile`] to hold if mutating the store.
292292 ///
293293 /// If the store will not be written to following the read, the lock can be dropped.
294- pub fn read < P : AsRef < Path > > ( path : P ) -> Result < ( Self , LockedFile ) , TomlCredentialError > {
295- let lock = Self :: lock ( path. as_ref ( ) ) ?;
294+ pub async fn read < P : AsRef < Path > > ( path : P ) -> Result < ( Self , LockedFile ) , TomlCredentialError > {
295+ let lock = Self :: lock ( path. as_ref ( ) ) . await ?;
296296 let store = Self :: from_file ( path) ?;
297297 Ok ( ( store, lock) )
298298 }
@@ -468,8 +468,8 @@ mod tests {
468468 assert ! ( store. get_credentials( & url, None ) . is_none( ) ) ;
469469 }
470470
471- #[ test]
472- fn test_file_operations ( ) {
471+ #[ tokio :: test]
472+ async fn test_file_operations ( ) {
473473 let mut temp_file = NamedTempFile :: new ( ) . unwrap ( ) ;
474474 writeln ! (
475475 temp_file,
@@ -505,7 +505,7 @@ password = "pass2"
505505 store
506506 . write (
507507 temp_output. path ( ) ,
508- TextCredentialStore :: lock ( temp_file. path ( ) ) . unwrap ( ) ,
508+ TextCredentialStore :: lock ( temp_file. path ( ) ) . await . unwrap ( ) ,
509509 )
510510 . unwrap ( ) ;
511511
0 commit comments