Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update Rust core to use case insensitive matching for logos

Leendert de Borst6fe1640e1efd
diff --git a/core/rust/src/vault_items/logos.rs b/core/rust/src/vault_items/logos.rs
index 50fe11b79..0400a6f7b 100644
--- a/core/rust/src/vault_items/logos.rs
+++ b/core/rust/src/vault_items/logos.rs
@@ -6,6 +6,7 @@ use super::sql_error;
use crate::common::error::VaultResult;
use crate::favicon::favicon_source_key;
use crate::vault_codec::logo_id_for;
+use crate::vault_model::ids_equal;
const FAVICON: &str = "favicon";
const FAVICON_MIME_TYPE: &str = "image/x-icon";
@@ -51,7 +52,7 @@ pub(super) fn resolve_logo_id(conn: &Connection, scope: &str, existing_logo_id:
pub(super) fn refresh_item_logo(conn: &Connection, item_id: &str, manifest_id: &str, url: &str, logo: Option<&[u8]>, now: &str) -> VaultResult<()> {
let current: Option<String> = conn.query_row(GET_ITEM_LOGO_ID, params![item_id, manifest_id], |row| row.get(0)).optional().map_err(sql_error)?.flatten();
let Some(logo_id) = resolve_logo_id(conn, manifest_id, current.as_deref(), url, logo, now)? else { return Ok(()) };
- if current.as_deref() != Some(logo_id.as_str()) {
+ if !current.as_deref().is_some_and(|current| ids_equal(current, &logo_id)) {
conn.execute(SET_ITEM_LOGO_ID, params![logo_id, now, item_id, manifest_id]).map_err(sql_error)?;
}
Ok(())
diff --git a/core/rust/src/vault_pruner/mod.rs b/core/rust/src/vault_pruner/mod.rs
index 5a1e8353c..411feb488 100644
--- a/core/rust/src/vault_pruner/mod.rs
+++ b/core/rust/src/vault_pruner/mod.rs
@@ -13,7 +13,7 @@ use crate::vault_model::names::{
DELETED_AT_COL, FILE_DATA_COL, ID_COL, IS_DELETED_COL, ITEMS_TABLE, KIND_COL, LOGOS_TABLE,
LOGO_ID_COL, LOGO_KIND_FAVICON, UPDATED_AT_COL,
};
-use crate::vault_model::{BLOB_COLUMNS, MANIFEST_ID_COL, SYNCABLE_TABLES};
+use crate::vault_model::{id_key, ids_equal, BLOB_COLUMNS, MANIFEST_ID_COL, SYNCABLE_TABLES};
/// Input for the prune operation.
#[derive(Debug, Clone)]
@@ -190,12 +190,12 @@ fn sweep_orphan_favicons(
) {
let Some(logos) = records_of(tables, LOGOS_TABLE) else { return };
let blob_clear = blob_clear_fragment(LOGOS_TABLE);
- let expired_set: HashSet<(&str, &str)> = expired.iter().map(|(manifest_id, id)| (manifest_id.as_str(), id.as_str())).collect();
+ let expired_set: HashSet<(String, String)> = expired.iter().map(|(manifest_id, id)| (id_key(manifest_id), id_key(id))).collect();
- let referenced_logos: HashSet<(&str, &str)> = items.iter()
+ let referenced_logos: HashSet<(String, String)> = items.iter()
.filter(|item| !is_deleted(item))
- .filter(|item| !expired_set.contains(&(manifest_of(item), str_col(item, ID_COL).unwrap_or(""))))
- .filter_map(|item| str_col(item, LOGO_ID_COL).map(|logo_id| (manifest_of(item), logo_id)))
+ .filter(|item| !expired_set.contains(&(id_key(manifest_of(item)), id_key(str_col(item, ID_COL).unwrap_or("")))))
+ .filter_map(|item| str_col(item, LOGO_ID_COL).map(|logo_id| (id_key(manifest_of(item)), id_key(logo_id))))
.collect();
for logo in logos.iter().filter(|logo| !is_deleted(logo)) {
@@ -203,7 +203,7 @@ fn sweep_orphan_favicons(
continue;
}
let Some(logo_id) = str_col(logo, ID_COL) else { continue };
- if referenced_logos.contains(&(manifest_of(logo), logo_id)) {
+ if referenced_logos.contains(&(id_key(manifest_of(logo)), id_key(logo_id))) {
continue;
}
statements.push(SqlStatement {
@@ -233,7 +233,7 @@ fn clear_tombstoned_blobs(tables: &[CodecTableData], now_str: &str, statements:
/// Count the live records of one manifest that match a foreign key value.
fn count_related_records(records: &[CodecRecord], manifest_id: &str, fk_column: &str, fk_value: &str) -> u32 {
- records.iter().filter(|r| manifest_of(r) == manifest_id && str_col(r, fk_column) == Some(fk_value) && !is_deleted(r)).count() as u32
+ records.iter().filter(|r| ids_equal(manifest_of(r), manifest_id) && str_col(r, fk_column).is_some_and(|value| ids_equal(value, fk_value)) && !is_deleted(r)).count() as u32
}
#[cfg(test)]
diff --git a/core/rust/src/vault_sync/errors.rs b/core/rust/src/vault_sync/errors.rs
index adb88ba9a..a7062175d 100644
--- a/core/rust/src/vault_sync/errors.rs
+++ b/core/rust/src/vault_sync/errors.rs
@@ -224,12 +224,12 @@ impl SyncError {
}
}
-/// The client error code a host failure of the named command maps to.
+/// The client error code a host failure of the named command maps to; the error detail names the command.
fn storage_error_code(command: &str) -> ErrorCode {
match command {
"stateGet" | "dbQuery" | "dbExport" | "vaultLoad" => ErrorCode::StorageReadFailed,
"stateSet" | "stateRemove" | "dbExec" | "vaultStore" | "markClean" => ErrorCode::StorageWriteFailed,
- _ => ErrorCode::UnknownError,
+ _ => ErrorCode::SyncEngineFailed,
}
}
@@ -251,6 +251,7 @@ mod tests {
assert_eq!(SyncError::Auth.failure(), Failure::Logout(LogoutReason::SessionExpired));
assert_eq!(SyncError::Staging(String::new()).failure(), Failure::Coded(ErrorCode::DatabaseInitFailed));
assert_eq!(SyncError::Host { command: "dbExec", message: String::new() }.failure(), Failure::Coded(ErrorCode::StorageWriteFailed));
+ assert_eq!(SyncError::Host { command: "vaultKey", message: String::new() }.failure(), Failure::Coded(ErrorCode::SyncEngineFailed));
}
#[test]