diff --git a/src/core/filecopyjob.h b/src/core/filecopyjob.h --- a/src/core/filecopyjob.h +++ b/src/core/filecopyjob.h @@ -71,6 +71,7 @@ bool doSuspend() Q_DECL_OVERRIDE; bool doResume() Q_DECL_OVERRIDE; + bool doKill() Q_DECL_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 @@ -41,7 +41,7 @@ bool move, JobFlags flags) : m_sourceSize(filesize_t(-1)), m_src(src), m_dest(dest), m_moveJob(nullptr), m_copyJob(nullptr), m_delJob(nullptr), m_chmodJob(nullptr), m_getJob(nullptr), m_putJob(nullptr), m_permissions(permissions), - m_move(move), m_mustChmod(0), m_flags(flags) + m_move(move), m_mustChmod(0), m_bFileWritingIsInProcess(false), m_flags(flags) { } KIO::filesize_t m_sourceSize; @@ -60,6 +60,7 @@ bool m_canResume: 1; bool m_resumeAnswerSent: 1; bool m_mustChmod: 1; + bool m_bFileWritingIsInProcess: 1; JobFlags m_flags; void startBestCopyMethod(); @@ -307,9 +308,26 @@ return true; } +bool FileCopyJob::doKill() +{ + const bool res = Job::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 (!isSuspended() && d->m_bFileWritingIsInProcess) { + KIO::file_delete(d->m_dest); + } + + return res; +} + void FileCopyJobPrivate::slotProcessedSize(KJob *, qulonglong size) { Q_Q(FileCopyJob); + m_bFileWritingIsInProcess = (size > 0); q->setProcessedAmount(KJob::Bytes, size); } @@ -489,6 +507,13 @@ Q_D(FileCopyJob); //qDebug() << "this=" << this << "job=" << job; removeSubjob(job); + + // If result comes from one of the file writing jobs, + // then we are probably not writing anymore. + if ((job == d->m_copyJob) || (job == d->m_putJob)) { + d->m_bFileWritingIsInProcess = false; + } + // Did job have an error ? if (job->error()) { if ((job == d->m_moveJob) && (job->error() == ERR_UNSUPPORTED_ACTION)) {