Commit 3dbdac81 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Simplify kill logic

Evolution of b1a251eb. We no longer want to distinguish between
libarchive and libzip. If there are crashes in libarchive because of
this new kill logic, we need to fix them.
parent 3ac306f2
......@@ -152,8 +152,8 @@ public:
static QStringList entryPathsFromDestination(QStringList entries, const Archive::Entry *destination, int entriesWithoutChildren);
/**
* @return true if the interface has killed the job or if it will stop it as soon as possible.
* Otherwise returns false if the interface is not able to kill the operation.
* @return true if the interface has killed the job.
* Otherwise returns false if the interface is not able to instantly kill the operation.
*/
virtual bool doKill();
......
......@@ -223,22 +223,18 @@ void Job::onUserQuery(Query *query)
bool Job::doKill()
{
const bool canKillJob = archiveInterface()->doKill();
if (!d->isRunning()) {
return canKillJob;
const bool killed = archiveInterface()->doKill();
if (killed) {
return true;
}
d->requestInterruption();
if (!canKillJob) {
qCDebug(ARK) << "Forcing thread exit in one second...";
if (d->isRunning()) {
qCDebug(ARK) << "Requesting graceful thread interruption, will abort in one second otherwise.";
d->requestInterruption();
d->wait(1000);
return true;
}
d->wait();
return canKillJob;
return true;
}
LoadJob::LoadJob(Archive *archive, ReadOnlyArchiveInterface *interface)
......
......@@ -158,7 +158,7 @@ bool LibarchivePlugin::hasBatchExtractionProgress() const
bool LibarchivePlugin::doKill()
{
return true;
return false;
}
bool LibarchivePlugin::extractFiles(const QVector<Archive::Entry*> &files, const QString &destinationDirectory, const ExtractionOptions &options)
......
......@@ -70,7 +70,6 @@ LibzipPlugin::~LibzipPlugin()
bool LibzipPlugin::list()
{
qCDebug(ARK) << "Listing archive contents for:" << QFile::encodeName(filename());
setOperationMode(List);
m_numberOfEntries = 0;
int errcode = 0;
......@@ -116,7 +115,6 @@ bool LibzipPlugin::list()
bool LibzipPlugin::addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions& options, uint numberOfEntriesToAdd)
{
Q_UNUSED(numberOfEntriesToAdd)
setOperationMode(Add);
int errcode = 0;
zip_error_t err;
......@@ -381,7 +379,6 @@ bool LibzipPlugin::emitEntryForIndex(zip_t *archive, qlonglong index)
bool LibzipPlugin::deleteFiles(const QVector<Archive::Entry*> &files)
{
setOperationMode(Delete);
int errcode = 0;
zip_error_t err;
......@@ -427,7 +424,6 @@ bool LibzipPlugin::deleteFiles(const QVector<Archive::Entry*> &files)
bool LibzipPlugin::addComment(const QString& comment)
{
setOperationMode(Comment);
int errcode = 0;
zip_error_t err;
......@@ -457,7 +453,6 @@ bool LibzipPlugin::addComment(const QString& comment)
bool LibzipPlugin::testArchive()
{
qCDebug(ARK) << "Testing archive";
setOperationMode(Test);
int errcode = 0;
zip_error_t err;
......@@ -507,24 +502,12 @@ bool LibzipPlugin::testArchive()
bool LibzipPlugin::doKill()
{
QMutexLocker mutexLocker(&m_mutex);
switch (m_operationMode) {
case Add:
case Copy:
case Delete:
case Move:
return false;
default:
break;
}
return true;
return false;
}
bool LibzipPlugin::extractFiles(const QVector<Archive::Entry*> &files, const QString& destinationDirectory, const ExtractionOptions& options)
{
qCDebug(ARK) << "Extracting files to:" << destinationDirectory;
setOperationMode(Extract);
const bool extractAll = files.isEmpty();
const bool removeRootNode = options.isDragAndDropEnabled();
......@@ -796,7 +779,6 @@ bool LibzipPlugin::extractEntry(zip_t *archive, const QString &entry, const QStr
bool LibzipPlugin::moveFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions &options)
{
Q_UNUSED(options)
setOperationMode(Move);
int errcode = 0;
zip_error_t err;
......@@ -846,7 +828,6 @@ bool LibzipPlugin::moveFiles(const QVector<Archive::Entry*> &files, Archive::Ent
bool LibzipPlugin::copyFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions &options)
{
Q_UNUSED(options)
setOperationMode(Copy);
int errcode = 0;
zip_error_t err;
......@@ -977,10 +958,4 @@ QString LibzipPlugin::permissionsToString(const mode_t &perm)
return modeval;
}
void LibzipPlugin::setOperationMode(ReadWriteArchiveInterface::OperationMode operationMode)
{
QMutexLocker mutexLocker(&m_mutex);
m_operationMode = operationMode;
}
#include "libzipplugin.moc"
......@@ -59,14 +59,12 @@ private:
bool emitEntryForIndex(zip_t *archive, qlonglong index);
void emitProgress(double percentage);
QString permissionsToString(const mode_t &perm);
void setOperationMode(OperationMode operationMode);
static void progressCallback(zip_t *, double progress, void *that);
QVector<Archive::Entry*> m_emittedEntries;
bool m_overwriteAll;
bool m_skipAll;
bool m_listAfterAdd;
QMutex m_mutex;
};
#endif // LIBZIPPLUGIN_H
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