diff --git a/src/core/filecopyjob.h b/src/core/filecopyjob.h --- a/src/core/filecopyjob.h +++ b/src/core/filecopyjob.h @@ -71,7 +71,6 @@ bool doSuspend() override; bool doResume() override; - bool doKill() override; Q_SIGNALS: /** diff --git a/src/core/filecopyjob.cpp b/src/core/filecopyjob.cpp --- a/src/core/filecopyjob.cpp +++ b/src/core/filecopyjob.cpp @@ -578,21 +578,6 @@ bool FileCopyJob::doKill() { - Q_D(FileCopyJob); - - // If we are interrupted in the middle of file copying, - // we may end up with corrupted file at the destination. - // It is better to clean up this file. If a copy is being - // made as part of move operation then delete the dest only if - // source file is intact (m_delJob == NULL). - if (d->m_bFileCopyInProgress && d->m_copyJob && d->m_dest.isLocalFile()) { - if (d->m_flags & Overwrite) { - QFile::remove(d->m_dest.toLocalFile() + QStringLiteral(".part")); - } else { - QFile::remove(d->m_dest.toLocalFile()); - } - } - return Job::doKill(); } diff --git a/src/ioslaves/file/file_unix.cpp b/src/ioslaves/file/file_unix.cpp --- a/src/ioslaves/file/file_unix.cpp +++ b/src/ioslaves/file/file_unix.cpp @@ -261,7 +261,7 @@ bool use_sendfile = buff_src.st_size < 0x7FFFFFFF; #endif bool existing_dest_delete_attempted = false; - while (1) { + while (!wasKilled()) { #ifdef USE_SENDFILE if (use_sendfile) { off_t sf = processed_size; @@ -348,6 +348,15 @@ src_file.close(); dest_file.close(); + if (wasKilled()) { + qCDebug(KIO_FILE) << "Clean dest file after ioslave was killed:" << dest; + if (!QFile::remove(dest)) { // don't keep partly copied file + execWithElevatedPrivilege(DEL, {_dest}, errno); + } + finished(); + return; + } + if (dest_file.error() != QFile::NoError) { qCWarning(KIO_FILE) << "Error when closing file descriptor[2]:" << dest_file.errorString(); error(KIO::ERR_CANNOT_WRITE, dest); diff --git a/src/ioslaves/file/file_win.cpp b/src/ioslaves/file/file_win.cpp --- a/src/ioslaves/file/file_win.cpp +++ b/src/ioslaves/file/file_win.cpp @@ -182,6 +182,11 @@ return; } + if (wasKilled()) { + qCDebug(KIO_FILE) << "Clean dest file after ioslave was killed:" << dest; + QFile::remove(_dest); + } + finished(); }