The resolution is to close the previously open basis if one with
the smae name is opened. This is in part because there isn't
a universally sensible/deterministic way of resolving behavior
in this case, and partially because the structure of the basis
map is a hash map keyed by name ... to differentiate basis with
same name/different password would require...leaking some information
about the password? i guess we could go strictly by opening order
by adding an opening parameter but basis management is already
confusing enough.

A message is popped up to indicate when the previous basis is
being unmounted.
This commit is contained in:
bunnie 2023-04-07 14:51:37 +08:00
parent e8fe8b9123
commit 4d118e72b8
3 changed files with 27 additions and 7 deletions

View file

@ -13,13 +13,6 @@
"ja": "パスワードを認証失敗でした。\n\nもう一度実行しください。",
"zh": "密码错误。"
},
"pddb.waitmount": {
"en": "Mounting PDDB, please wait...",
"en-tts": "Mounting PDDB, please wait...",
"fr": "Montage de PDDB, veuillez patienter...*MT*",
"ja": "PDDB をマウントしています。お待ちください...",
"zh": "正在挂载 PDDB,请稍候..."
},
"pddb.basisname": {
"en": "Basis Name:",
"en-tts": "Enter name of Basis",
@ -300,6 +293,20 @@
"ja": "コミットルート\n(6/6)",
"zh": "提交根(6/6)"
},
"pddb.unmount_previous": {
"en": "Warning: newly opened basis has the same name as a previously open basis. The previously opened basis has been closed.",
"en-tts": "Warning: newly opened basis has the same name as a previously open basis. The previously opened basis has been closed.",
"fr": "Attention : la base nouvellement ouverte porte le même nom qu'une base précédemment ouverte. La base précédemment ouverte a été fermée.*MT*",
"ja": "警告: 新しく開かれた基底は、以前に開いた基底と同じ名前です。 以前に開設されたベーシスは閉鎖されました。",
"zh": "警告:新打开的基础与以前打开的基础具有相同的名称。 之前打开的基础已经关闭。"
},
"pddb.waitmount": {
"en": "Mounting PDDB, please wait...",
"en-tts": "Mounting PDDB, please wait...",
"fr": "Montage de PDDB, veuillez patienter...*MT*",
"ja": "PDDB をマウントしています。お待ちください...",
"zh": "正在挂载 PDDB,请稍候..."
},
"pddb.yes": {
"en": "Yes",
"en-tts": "Yes",

View file

@ -1001,6 +1001,15 @@ impl BasisCache {
}
}
pub(crate) fn basis_contains(&self, by_name: &str) -> bool {
for bcache in &self.cache {
if bcache.name == by_name {
return true
}
}
false
}
/// note: you can "delete" a basis simply by forgetting its password, but this is more thorough.
/// there might also need to be a variant to make which is a "change my password" function, but that is actually
/// surprisingly hard.

View file

@ -876,6 +876,10 @@ fn wrapped_main() -> ! {
&mut pddb_os, mgmt.name.as_str().expect("name is not valid utf-8"), pw.as_str().expect("password was not valid utf-8"),
mgmt.policy.unwrap_or(BasisRetentionPolicy::Persist)
) {
if basis_cache.basis_contains(&basis.name) {
basis_cache.basis_unmount(&mut pddb_os, &basis.name).expect("couldn't unmount previously mounted basis of same name");
modals.show_notification(t!("pddb.unmount_previous", xous::LANG), None).expect("notification failed");
}
basis_cache.basis_add(basis);
finished = true;
log::info!("{}PDDB.UNLOCKOK,{},{}", xous::BOOKEND_START, mgmt.name.as_str().unwrap(), xous::BOOKEND_END);