diff --git a/keystore2/src/legacy_blob.rs b/keystore2/src/legacy_blob.rs index a3e440b9..e6313569 100644 --- a/keystore2/src/legacy_blob.rs +++ b/keystore2/src/legacy_blob.rs @@ -686,10 +686,18 @@ impl LegacyBlobLoader { let user_id = uid_to_android_user(uid); path.push(format!("user_{}", user_id)); let uid_str = uid.to_string(); - let dir = - Self::with_retry_interrupted(|| fs::read_dir(path.as_path())).with_context(|| { - format!("In list_vpn_profiles: Failed to open legacy blob database. {:?}", path) - })?; + let dir = match Self::with_retry_interrupted(|| fs::read_dir(path.as_path())) { + Ok(dir) => dir, + Err(e) => match e.kind() { + ErrorKind::NotFound => return Ok(Default::default()), + _ => { + return Err(e).context(format!( + "In list_vpn_profiles: Failed to open legacy blob database. {:?}", + path + )) + } + }, + }; let mut result: Vec = Vec::new(); for entry in dir { let file_name = @@ -1370,4 +1378,14 @@ mod test { Ok(()) } + + #[test] + fn list_vpn_profiles_on_non_existing_user() -> Result<()> { + let temp_dir = TempDir::new("list_vpn_profiles_on_non_existing_user")?; + let legacy_blob_loader = LegacyBlobLoader::new(temp_dir.path()); + + assert!(legacy_blob_loader.list_vpn_profiles(20)?.is_empty()); + + Ok(()) + } } diff --git a/keystore2/vpnprofilestore/lib.rs b/keystore2/vpnprofilestore/lib.rs index f5adc1b0..51238378 100644 --- a/keystore2/vpnprofilestore/lib.rs +++ b/keystore2/vpnprofilestore/lib.rs @@ -75,15 +75,11 @@ impl DB { } fn is_locked_error(e: &anyhow::Error) -> bool { - matches!(e.root_cause().downcast_ref::(), - Some(rusqlite::ffi::Error { - code: rusqlite::ErrorCode::DatabaseBusy, - .. - }) - | Some(rusqlite::ffi::Error { - code: rusqlite::ErrorCode::DatabaseLocked, - .. - })) + matches!( + e.root_cause().downcast_ref::(), + Some(rusqlite::ffi::Error { code: rusqlite::ErrorCode::DatabaseBusy, .. }) + | Some(rusqlite::ffi::Error { code: rusqlite::ErrorCode::DatabaseLocked, .. }) + ) } fn init_tables(&mut self) -> Result<()> { @@ -192,7 +188,7 @@ where { result.map_or_else( |e| { - log::error!("{:#?}", e); + log::error!("{:?}", e); let root_cause = e.root_cause(); let rc = match root_cause.downcast_ref::() { Some(Error::Error(e)) => *e,