Merge "Legacy VPN Profile Store: Fix listing empty legacy user directory."

This commit is contained in:
Treehugger Robot 2021-04-19 19:04:09 +00:00 committed by Gerrit Code Review
commit 33b8c2c799
2 changed files with 28 additions and 14 deletions

View file

@ -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<String> = 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(())
}
}

View file

@ -75,15 +75,11 @@ impl DB {
}
fn is_locked_error(e: &anyhow::Error) -> bool {
matches!(e.root_cause().downcast_ref::<rusqlite::ffi::Error>(),
Some(rusqlite::ffi::Error {
code: rusqlite::ErrorCode::DatabaseBusy,
..
})
| Some(rusqlite::ffi::Error {
code: rusqlite::ErrorCode::DatabaseLocked,
..
}))
matches!(
e.root_cause().downcast_ref::<rusqlite::ffi::Error>(),
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::<Error>() {
Some(Error::Error(e)) => *e,