Commit b47c5346 authored by Ragnar Thomsen's avatar Ragnar Thomsen

libarchive: Improve error-handling when loading archive

Improves error-handling in LibarchivePlugin::list().

Previously we only checked whether we could read until the end of the
archive, and even if we couldn't there was no error shown to the user.
Now we check the return value of both archive_read_next_header() and
archive_read_data_skip(), and show a corrupt archive query if either
was not successful.

This partially solves bug 411074, as Ark now at least gives a warning
when opening a corrupt archive with libarchiveplugin. We still need to
improve error-handling when extracting, but this requires some
refactoring first so will be done later.
CCBUG: 411074
Differential Revision: D29383
parent a914765b
......@@ -99,17 +99,47 @@ bool LibarchivePlugin::list()
emit progress(float(archive_filter_bytes(, -1))/float(compressedArchiveSize));
// Skip the entry data.
int readSkipResult = archive_read_data_skip(;
if (readSkipResult != ARCHIVE_OK) {
qCCritical(ARK) << "Error while skipping data for entry:"
<< QString::fromWCharArray(archive_entry_pathname_w(aentry))
<< readSkipResult
<< QLatin1String(archive_error_string(;
if (!emitCorruptArchive()) {
return false;
if (result != ARCHIVE_EOF) {
qCWarning(ARK) << "Could not read until the end of the archive:" << QLatin1String(archive_error_string(;
return false;
qCCritical(ARK) << "Error while reading archive:"
<< result
<< QLatin1String(archive_error_string(;
if (!emitCorruptArchive()) {
return false;
return archive_read_close( == ARCHIVE_OK;
bool LibarchivePlugin::emitCorruptArchive()
Kerfuffle::LoadCorruptQuery query(filename());
emit userQuery(&query);
if (!query.responseYes()) {
emit cancelled();
return false;
} else {
emit progress(1.0);
return true;
bool LibarchivePlugin::addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions &options, uint numberOfEntriesToAdd)
......@@ -94,6 +94,7 @@ private Q_SLOTS:
int extractionFlags() const;
QString convertCompressionName(const QString &method);
bool emitCorruptArchive();
int m_cachedArchiveEntryCount;
qlonglong m_currentExtractedFilesSize;
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