From 91f0d049db62d9a45df19b2beeea5dd81690d43e Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 1 Aug 2017 20:17:59 +0300 Subject: [PATCH] Fix saving a loaded file as another existing file. --- Telegram/SourceFiles/mediaview.cpp | 8 ++++++-- Telegram/SourceFiles/structs.cpp | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Telegram/SourceFiles/mediaview.cpp b/Telegram/SourceFiles/mediaview.cpp index 6469f0013..39d296e77 100644 --- a/Telegram/SourceFiles/mediaview.cpp +++ b/Telegram/SourceFiles/mediaview.cpp @@ -783,6 +783,7 @@ void MediaView::onSaveAs() { psShowOverAll(this); if (!file.isEmpty() && file != location.name()) { if (_doc->data().isEmpty()) { + QFile(file).remove(); QFile(location.name()).copy(file); } else { QFile f(file); @@ -900,8 +901,11 @@ void MediaView::onDownload() { if (location.accessEnable()) { if (!QDir().exists(path)) QDir().mkpath(path); toName = filedialogNextFilename(_doc->name, location.name(), path); - if (toName != location.name() && !QFile(location.name()).copy(toName)) { - toName = QString(); + if (!toName.isEmpty() && toName != location.name()) { + QFile(toName).remove(); + if (!QFile(location.name()).copy(toName)) { + toName = QString(); + } } location.accessDisable(); } else { diff --git a/Telegram/SourceFiles/structs.cpp b/Telegram/SourceFiles/structs.cpp index ba899ad50..4877806e4 100644 --- a/Telegram/SourceFiles/structs.cpp +++ b/Telegram/SourceFiles/structs.cpp @@ -1889,6 +1889,7 @@ void DocumentData::save(const QString &toFile, ActionOnLoad action, const FullMs } else if (l.accessEnable()) { auto alreadyName = l.name(); if (alreadyName != toFile) { + QFile(toFile).remove(); QFile(alreadyName).copy(toFile); } l.accessDisable();