Keep iPhone TOTP cache across installs (#78)
This commit is contained in:
@@ -348,7 +348,7 @@ impl<'a> MobileTotpService<'a> {
|
||||
progress.total = u32::try_from(initial_inventory.len()).unwrap_or(u32::MAX);
|
||||
});
|
||||
|
||||
let store = store_identity(self.repository.root_path());
|
||||
let store = store_identity(self.repository.root_path(), cache_path);
|
||||
let (cached, mut cache_notice) = load_cache(cache_path, &store);
|
||||
let mut records = BTreeMap::new();
|
||||
let mut rows = Vec::new();
|
||||
@@ -424,7 +424,7 @@ impl<'a> MobileTotpService<'a> {
|
||||
shared: &BTreeSet<EntryPath>,
|
||||
cache_path: &Path,
|
||||
) -> Option<MobileTotpPage> {
|
||||
let store = store_identity(self.repository.root_path());
|
||||
let store = store_identity(self.repository.root_path(), cache_path);
|
||||
let (catalog, _) = load_cache(cache_path, &store);
|
||||
let mut rows: Vec<_> = catalog?
|
||||
.entries
|
||||
@@ -460,7 +460,7 @@ impl<'a> MobileTotpService<'a> {
|
||||
ciphertext_hash: digest(ciphertext.as_bytes()),
|
||||
is_totp: uri.is_some(),
|
||||
};
|
||||
let store = store_identity(self.repository.root_path());
|
||||
let store = store_identity(self.repository.root_path(), cache_path);
|
||||
let cache_notice =
|
||||
upsert_cache_record(cache_path, &store, document.path().to_string(), record);
|
||||
let detail = match (uri, unix_seconds) {
|
||||
@@ -667,8 +667,15 @@ fn set_private_permissions(_temporary: &TempFile<'_>) -> Result<(), MobileTotpCa
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn store_identity(root: &Path) -> String {
|
||||
digest(root.to_string_lossy().as_bytes())
|
||||
fn store_identity(root: &Path, cache_path: &Path) -> String {
|
||||
let cache_parent = cache_path
|
||||
.parent()
|
||||
.and_then(|parent| fs::canonicalize(parent).ok());
|
||||
let stable_root = cache_parent
|
||||
.as_deref()
|
||||
.and_then(|parent| root.strip_prefix(parent).ok())
|
||||
.unwrap_or(root);
|
||||
digest(stable_root.to_string_lossy().as_bytes())
|
||||
}
|
||||
|
||||
fn digest(bytes: &[u8]) -> String {
|
||||
|
||||
Reference in New Issue
Block a user