Skip to content

Commit

Permalink
fix - refcell borrow crash when referenced file deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
noxware committed Aug 13, 2024
1 parent 483c348 commit f1865ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/data/chats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ impl Chats {
}

/// Get the file id to use with this chat, or the loaded file id as a fallback.
/// The fallback is used if the chat does not have a file id set, or, if it has
/// one but references a no longer existing (deleted) file.
///
/// If the fallback is used, the chat is updated with this, and persisted.
pub fn get_or_init_chat_file_id(&self, chat_id: ChatID) -> Option<FileID> {
let mut chat = self.get_chat_by_id(chat_id)?.borrow_mut();

pub fn get_or_init_chat_file_id(&self, chat: &mut Chat) -> Option<FileID> {
if let Some(file_id) = chat.last_used_file_id.clone() {
Some(file_id)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/data/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl Store {
if let Some(mut chat) = self.chats.get_current_chat().map(|c| c.borrow_mut()) {
let wanted_file = self
.chats
.get_or_init_chat_file_id(chat.id)
.get_or_init_chat_file_id(&mut chat)
.map(|file_id| self.downloads.get_file(&file_id))
.flatten();

Expand Down Expand Up @@ -145,7 +145,7 @@ impl Store {
if let Some(mut chat) = self.chats.get_current_chat().map(|c| c.borrow_mut()) {
let wanted_file = self
.chats
.get_or_init_chat_file_id(chat.id)
.get_or_init_chat_file_id(&mut chat)
.map(|file_id| self.downloads.get_file(&file_id))
.flatten();

Expand Down

0 comments on commit f1865ea

Please sign in to comment.