diff --git a/src/core/copyjob.h b/src/core/copyjob.h --- a/src/core/copyjob.h +++ b/src/core/copyjob.h @@ -130,6 +130,11 @@ void setWriteIntoExistingDirectories(bool overwriteAllDirs); /** + * Reimplemented to do a proper cleanup of partially copied files. + */ + bool doKill() Q_DECL_OVERRIDE; + + /** * Reimplemented for internal reasons */ bool doSuspend() Q_DECL_OVERRIDE; diff --git a/src/core/copyjob.cpp b/src/core/copyjob.cpp --- a/src/core/copyjob.cpp +++ b/src/core/copyjob.cpp @@ -135,6 +135,7 @@ , m_totalSize(0) , m_processedSize(0) , m_fileProcessedSize(0) + , m_bFileCopyingIsInProcess(false) , m_processedFiles(0) , m_processedDirs(0) , m_srcList(src) @@ -180,6 +181,7 @@ KIO::filesize_t m_totalSize; KIO::filesize_t m_processedSize; KIO::filesize_t m_fileProcessedSize; + bool m_bFileCopyingIsInProcess; int m_processedFiles; int m_processedDirs; QList files; @@ -544,6 +546,24 @@ } } +bool CopyJob::doKill() +{ + const bool res = Job::doKill(); + + Q_D(CopyJob); + + // 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 (d->state == STATE_COPYING_FILES && d->m_bFileCopyingIsInProcess) { + QList::Iterator it = d->files.begin(); + const QUrl dest = (*it).uDest; + KIO::del(dest); + } + + return res; +} + bool CopyJob::doSuspend() { Q_D(CopyJob); @@ -1272,6 +1292,9 @@ void CopyJobPrivate::slotResultCopyingFiles(KJob *job) { Q_Q(CopyJob); + + m_bFileCopyingIsInProcess = false; + // The file we were trying to copy: QList::Iterator it = files.begin(); if (job->error()) { @@ -1797,6 +1820,7 @@ { Q_Q(CopyJob); qCDebug(KIO_COPYJOB_DEBUG) << data_size; + m_bFileCopyingIsInProcess = true; m_fileProcessedSize = data_size; q->setProcessedAmount(KJob::Bytes, m_processedSize + m_fileProcessedSize);