pddb: close all related filehandles when a file is deleted

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2022-07-05 23:56:31 +08:00
parent 5cc51ebdaf
commit 086c014de2
2 changed files with 12 additions and 11 deletions

View file

@ -336,7 +336,6 @@ pub(crate) fn open_key(
crate::PddbRetcode::AccessDenied
})?;
let mut writer = backing
.writer(*b"KyOR")
.ok_or(crate::PddbRetcode::InternalError)?;
@ -542,7 +541,7 @@ pub(crate) fn delete_key(
mem: &mut xous::MemoryMessage,
pddb_os: &mut PddbOs,
basis_cache: &mut BasisCache,
fds: &mut Vec<Option<crate::FileHandle>>,
all_fds: &mut std::collections::HashMap<Option<xous::PID>, Vec<Option<FileHandle>>>,
) -> Result<(), crate::PddbRetcode> {
// Convert the memory to a Senres buffer
let backing = senres::Message::from_mut_slice(mem.buf.as_slice_mut())
@ -580,14 +579,16 @@ pub(crate) fn delete_key(
Err(crate::PddbRetcode::UnexpectedEof)
})?;
// Mark the entries as deleted in all remaining file handles
for fd in fds
.iter_mut()
.filter(|f| f.is_some())
.map(|f| f.as_mut().unwrap())
{
if fd.basis == basis && fd.key == key && fd.dict == dict {
fd.deleted = true;
// Mark the entry as deleted in all remaining file handles in the entire system
for fds in all_fds.values_mut() {
for fd in fds
.iter_mut()
.filter(|f| f.is_some())
.map(|f| f.as_mut().unwrap())
{
if fd.basis == basis && fd.key == key && fd.dict == dict {
fd.deleted = true;
}
}
}

View file

@ -1045,7 +1045,7 @@ fn wrapped_main() -> ! {
Opcode::DeleteKeyStd => {
if let Some(mem) = msg.body.memory_message_mut() {
mem.offset = None;
if let Err(err) = libstd::delete_key(mem, &mut pddb_os, &mut basis_cache, fd_mapping.entry(msg.sender.pid()).or_default()) {
if let Err(err) = libstd::delete_key(mem, &mut pddb_os, &mut basis_cache, &mut fd_mapping) {
mem.offset = xous::MemoryAddress::new(err as usize);
}
}