From 45110ac27353f899ec5bf43fb062b522ae922698 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 20 Dec 2022 10:56:10 +0200 Subject: [PATCH] kutils: remove the temporary archive if error occurs in KArchive::add() and KArchive::remove() Signed-off-by: Ivailo Monev --- kutils/karchive/karchive.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kutils/karchive/karchive.cpp b/kutils/karchive/karchive.cpp index 16c5cab8..8bf31a0e 100644 --- a/kutils/karchive/karchive.cpp +++ b/kutils/karchive/karchive.cpp @@ -688,13 +688,15 @@ bool KArchive::add(const QStringList &paths, const QByteArray &strip, const QByt if (result) { kDebug() << "Replacing" << d->m_path << "with" << tmpfile; - // TODO: set permissions on file after copy, same as the original result = (KDE::rename(tmpfile, d->m_path) != -1); if (!result) { d->m_error = i18n("Could not move: %1 to: %2", tmpfile, d->m_path); kDebug() << d->m_error; } + } else { + kDebug() << "Removing temporary archive" << tmpfile; + QFile::remove(tmpfile); } #else Q_UNUSED(paths); @@ -796,12 +798,14 @@ bool KArchive::remove(const QStringList &paths) const if (result) { kDebug() << "Replacing" << d->m_path << "with" << tmpfile; - result = (KDE::rename(tmpfile, d->m_path) != -1); if (!result) { d->m_error = i18n("Could not move: %1 to: %2", tmpfile, d->m_path); kDebug() << d->m_error; } + } else { + kDebug() << "Removing temporary archive" << tmpfile; + QFile::remove(tmpfile); } if (!notfound.isEmpty()) {