From d7177cac979a376dd7ea6dd46f5c5edbb68a06d8 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Mon, 6 Jun 2022 03:59:20 -0400 Subject: [PATCH] remove temporary image file when attachment removed --- src/components/chatinput.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/chatinput.cpp b/src/components/chatinput.cpp index 94bca22..7597bbe 100644 --- a/src/components/chatinput.cpp +++ b/src/components/chatinput.cpp @@ -104,8 +104,11 @@ ChatInputAttachmentContainer::ChatInputAttachmentContainer() } void ChatInputAttachmentContainer::Clear() { - for (auto *x : m_attachments) - delete x; + for (auto *item : m_attachments) { + std::error_code ec; + std::filesystem::remove(item->GetPath(), ec); + delete item; + } m_attachments.clear(); } @@ -137,6 +140,8 @@ bool ChatInputAttachmentContainer::AddImage(const Glib::RefPtr &pb) m_attachments.insert(item); item->signal_remove().connect([this, item] { + std::error_code ec; + std::filesystem::remove(item->GetPath(), ec); m_attachments.erase(item); delete item; if (m_attachments.empty())