Commit e777831f authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Properly kill AddToArchive jobs

Both AddToArchive and CreateJob are wrapper jobs, they need to implement
doKill() and call kill() on the actual jobs that are doing the work.

BUG: 374433
FIXED-IN: 16.12.1

Differential Revision: D4000
parent 0e8dfd1b
......@@ -138,6 +138,11 @@ void AddToArchive::start()
QTimer::singleShot(0, this, &AddToArchive::slotStartJob);
}
bool AddToArchive::doKill()
{
return m_createJob && m_createJob->kill();
}
void AddToArchive::slotStartJob()
{
if (m_entries.isEmpty()) {
......@@ -192,15 +197,15 @@ void AddToArchive::slotStartJob()
m_options.setGlobalWorkDir(stripDir.path());
}
auto createJob = Archive::create(m_filename, m_mimeType, m_entries, m_options, this);
m_createJob = Archive::create(m_filename, m_mimeType, m_entries, m_options, this);
if (!m_password.isEmpty()) {
createJob->enableEncryption(m_password, m_enableHeaderEncryption);
m_createJob->enableEncryption(m_password, m_enableHeaderEncryption);
}
KIO::getJobTracker()->registerJob(createJob);
connect(createJob, &KJob::result, this, &AddToArchive::slotFinished);
createJob->start();
KIO::getJobTracker()->registerJob(m_createJob);
connect(m_createJob, &KJob::result, this, &AddToArchive::slotFinished);
m_createJob->start();
}
void AddToArchive::slotFinished(KJob *job)
......
......@@ -72,12 +72,16 @@ public slots:
void setHeaderEncryptionEnabled(bool enabled);
void start() Q_DECL_OVERRIDE;
protected:
bool doKill() Q_DECL_OVERRIDE;
private slots:
void slotFinished(KJob*);
void slotStartJob();
private:
CompressionOptions m_options;
CreateJob *m_createJob;
QString m_filename;
QString m_strippedPath;
QString m_autoFilenameSuffix;
......
......@@ -466,21 +466,26 @@ void CreateJob::setMultiVolume(bool isMultiVolume)
void CreateJob::doWork()
{
auto addJob = archive()->addFiles(m_entries, new Archive::Entry(this), m_options);
m_addJob = archive()->addFiles(m_entries, new Archive::Entry(this), m_options);
if (addJob) {
connect(addJob, &KJob::result, this, &CreateJob::emitResult);
if (m_addJob) {
connect(m_addJob, &KJob::result, this, &CreateJob::emitResult);
// Forward description signal from AddJob, we need to change the first argument ('this' needs to be a CreateJob).
connect(addJob, &KJob::description, this, [=](KJob *, const QString &title, const QPair<QString,QString> &field1, const QPair<QString,QString> &) {
connect(m_addJob, &KJob::description, this, [=](KJob *, const QString &title, const QPair<QString,QString> &field1, const QPair<QString,QString> &) {
emit description(this, title, field1);
});
addJob->start();
m_addJob->start();
} else {
emitResult();
}
}
bool CreateJob::doKill()
{
return m_addJob && m_addJob->kill();
}
ExtractJob::ExtractJob(const QVector<Archive::Entry*> &entries, const QString &destinationDir, const ExtractionOptions &options, ReadOnlyArchiveInterface *interface)
: Job(interface)
, m_entries(entries)
......
......@@ -216,7 +216,11 @@ public:
public slots:
virtual void doWork() Q_DECL_OVERRIDE;
protected:
virtual bool doKill() Q_DECL_OVERRIDE;
private:
AddJob *m_addJob = Q_NULLPTR;
QVector<Archive::Entry*> m_entries;
CompressionOptions m_options;
};
......
......@@ -503,7 +503,7 @@ void LibarchivePlugin::copyData(const QString& filename, struct archive *dest, b
}
readBytes = file.read(buff, sizeof(buff));
while (readBytes > 0) {
while (!QThread::currentThread()->isInterruptionRequested() && readBytes > 0) {
archive_write_data(dest, buff, readBytes);
if (archive_errno(dest) != ARCHIVE_OK) {
qCCritical(ARK) << "Error while writing" << filename << ":" << archive_error_string(dest)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment