Commit c2f144e6 authored by Ilya Pominov's avatar Ilya Pominov Committed by Elvis Angelaccio
Browse files

Keep files sparse when extracting with libarchive plugin

parent e4c56b81
Pipeline #245268 passed with stage
in 1 minute and 34 seconds
......@@ -18,6 +18,7 @@ Archive::Entry::Entry(QObject *parent, const QString &fullPath, const QString &r
, m_parent(qobject_cast<Entry*>(parent))
, m_size(0)
, m_compressedSize(0)
, m_sparseSize(0)
, m_isDirectory(false)
, m_isExecutable(false)
, m_isPasswordProtected(false)
......@@ -35,6 +36,11 @@ qulonglong Archive::Entry::size() const
return m_size;
}
qulonglong Archive::Entry::sparseSize() const
{
return m_sparseSize;
}
void Archive::Entry::copyMetaData(const Archive::Entry *sourceEntry)
{
setProperty("fullPath", sourceEntry->property("fullPath"));
......@@ -43,6 +49,7 @@ void Archive::Entry::copyMetaData(const Archive::Entry *sourceEntry)
setProperty("group", sourceEntry->property("group"));
setProperty("size", sourceEntry->property("size"));
setProperty("compressedSize", sourceEntry->property("compressedSize"));
setProperty("sparseSize", sourceEntry->property("sparseSize"));
setProperty("link", sourceEntry->property("link"));
setProperty("ratio", sourceEntry->property("ratio"));
setProperty("CRC", sourceEntry->property("CRC"));
......
......@@ -40,6 +40,7 @@ class Archive::Entry : public QObject
Q_PROPERTY(QString group MEMBER m_group)
Q_PROPERTY(qulonglong size MEMBER m_size)
Q_PROPERTY(qulonglong compressedSize MEMBER m_compressedSize)
Q_PROPERTY(qulonglong sparseSize MEMBER m_sparseSize)
Q_PROPERTY(QString link MEMBER m_link)
Q_PROPERTY(QString ratio MEMBER m_ratio)
Q_PROPERTY(QString CRC MEMBER m_CRC)
......@@ -78,6 +79,7 @@ public:
Entry *findByPath(const QStringList & pieces, int index = 0) const;
QIcon icon() const;
qulonglong size() const;
qulonglong sparseSize() const;
/**
* Fills @p dirs and @p files with the number of directories and files
......@@ -102,6 +104,7 @@ private:
QString m_group;
qulonglong m_size;
qulonglong m_compressedSize;
qulonglong m_sparseSize;
QString m_link;
QString m_ratio;
QString m_CRC;
......
......@@ -555,7 +555,7 @@ void ExtractJob::doWork()
qulonglong totalUncompressedSize = 0;
for (Archive::Entry *entry : qAsConst(m_entries)) {
totalUncompressedSize += entry->size();
totalUncompressedSize += entry->sparseSize() > 0 ? entry->sparseSize() : entry->size();
}
QStorageInfo destinationStorage(m_destinationDir);
......
......@@ -188,8 +188,6 @@ bool LibarchivePlugin::extractFiles(const QVector<Archive::Entry*> &files, const
return false;
}
archive_write_disk_set_options(writer.data(), extractionFlags());
int totalEntriesCount = 0;
const bool extractAll = files.isEmpty();
if (extractAll) {
......@@ -356,6 +354,12 @@ bool LibarchivePlugin::extractFiles(const QVector<Archive::Entry*> &files, const
}
}
int flags = extractionFlags();
if (archive_entry_sparse_count(entry) > 0) {
flags |= ARCHIVE_EXTRACT_SPARSE;
}
archive_write_disk_set_options(writer.data(), flags);
// Write the entry header and check return value.
const int returnCode = archive_write_header(writer.data(), entry);
switch (returnCode) {
......@@ -485,6 +489,15 @@ void LibarchivePlugin::emitEntryFromArchiveEntry(struct archive_entry *aentry)
auto time = static_cast<uint>(archive_entry_mtime(aentry));
e->setProperty("timestamp", QDateTime::fromSecsSinceEpoch(time));
if (archive_entry_sparse_reset(aentry)) {
qulonglong sparseSize = 0;
la_int64_t offset, len;
while (archive_entry_sparse_next(aentry, &offset, &len) == ARCHIVE_OK) {
sparseSize += static_cast<qulonglong>(len);
}
e->setProperty("sparseSize", sparseSize);
}
Q_EMIT entry(e);
m_emittedEntries << e;
}
......
Supports Markdown
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