kutils: remove the temporary archive if error occurs in KArchive::add() and KArchive::remove()

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-12-20 10:56:10 +02:00
parent 212cc9717a
commit 45110ac273

View file

@ -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()) {