Commit ef1753b4 authored by Ragnar Thomsen's avatar Ragnar Thomsen
Browse files

Show progress in percentage for all job types in LibarchivePlugin

Progress is now also shown in percentage for Addjob, CopyJob, DeleteJob
and MoveJob for archives handled by LibarchivePlugin. This was a bit
tricky due to libarchive always iterating the whole archive and means
that the plugin needs to know the total number of existing archive
entries.

A new member variable m_numberOfEntries was added to
ReadOnlyArchiveInterface, which holds the total number of entries in the
archive. The variable is kept up-to-date by incrementing/decrementing it
whenever the entry and entryRemoved signals are emitted by a plugin.
This necessitated a slight rework of the handling of MoveJob and CopyJob
by LibarchivePlugin because these emitted entry when iterating over the
old entries. The new approach should also be more efficient.

The two Archive members m_numberOfFiles and m_numberOfFolders were
removed.

ReadOnlyArchiveInterface::addFiles() got an additional argument of type
uint that holds the number of entries to be added.

Differential Revision: D3072
parent 8aaf9693
......@@ -56,40 +56,35 @@ void AddToArchiveTest::testCompressHere_data()
QTest::addColumn<Archive::EncryptionType>("expectedEncryptionType");
QTest::addColumn<QStringList>("inputFiles");
QTest::addColumn<QString>("expectedArchiveName");
QTest::addColumn<qulonglong>("expectedNumberOfFiles");
QTest::addColumn<qulonglong>("expectedNumberOfFolders");
QTest::addColumn<qulonglong>("expectedNumberOfEntries");
QTest::newRow("compress here (as TAR) - dir with files")
<< QStringLiteral("tar.gz")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testdir")}
<< QStringLiteral("testdir.tar.gz")
<< 2ULL
<< 1ULL;
<< 3ULL;
QTest::newRow("compress here (as TAR) - dir with subdirs")
<< QStringLiteral("tar.gz")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testdirwithsubdirs")}
<< QStringLiteral("testdirwithsubdirs.tar.gz")
<< 4ULL
<< 4ULL;
<< 8ULL;
QTest::newRow("compress here (as TAR) - dir with empty subdir")
<< QStringLiteral("tar.gz")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testdirwithemptysubdir")}
<< QStringLiteral("testdirwithemptysubdir.tar.gz")
<< 2ULL
<< 2ULL;
<< 4ULL;
QTest::newRow("compress here (as TAR) - single file")
<< QStringLiteral("tar.gz")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testfile.txt")}
<< QStringLiteral("testfile.tar.gz")
<< 1ULL
<< 0ULL;
<< 1ULL;
QTest::newRow("compress here (as TAR) - file + folder")
<< QStringLiteral("tar.gz")
......@@ -99,16 +94,14 @@ void AddToArchiveTest::testCompressHere_data()
QFINDTESTDATA("data/testfile.txt")
}
<< QStringLiteral("data.tar.gz")
<< 3ULL
<< 1ULL;
<< 4ULL;
QTest::newRow("compress here (as TAR) - bug #362690")
<< QStringLiteral("tar.gz")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/test-3.4.0")}
<< QStringLiteral("test-3.4.0.tar.gz")
<< 1ULL
<< 1ULL;
<< 2ULL;
if (!PluginManager().preferredWritePluginsFor(QMimeDatabase().mimeTypeForName(QStringLiteral("application/zip"))).isEmpty()) {
QTest::newRow("compress here (as ZIP) - dir with files")
......@@ -116,32 +109,28 @@ void AddToArchiveTest::testCompressHere_data()
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testdir")}
<< QStringLiteral("testdir.zip")
<< 2ULL
<< 1ULL;
<< 3ULL;
QTest::newRow("compress here (as ZIP) - dir with subdirs")
<< QStringLiteral("zip")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testdirwithsubdirs")}
<< QStringLiteral("testdirwithsubdirs.zip")
<< 4ULL
<< 4ULL;
<< 8ULL;
QTest::newRow("compress here (as ZIP) - dir with empty subdir")
<< QStringLiteral("zip")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testdirwithemptysubdir")}
<< QStringLiteral("testdirwithemptysubdir.zip")
<< 2ULL
<< 2ULL;
<< 4ULL;
QTest::newRow("compress here (as ZIP) - single file")
<< QStringLiteral("zip")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testfile.txt")}
<< QStringLiteral("testfile.zip")
<< 1ULL
<< 0ULL;
<< 1ULL;
QTest::newRow("compress here (as ZIP) - file + folder")
<< QStringLiteral("zip")
......@@ -151,15 +140,14 @@ void AddToArchiveTest::testCompressHere_data()
QFINDTESTDATA("data/testfile.txt")
}
<< QStringLiteral("data.zip")
<< 3ULL
<< 1ULL;
<< 4ULL;
QTest::newRow("compress here (as TAR) - dir with special name (see #365798)")
<< QStringLiteral("tar.gz")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/test%dir")}
<< QStringLiteral("test%dir.tar.gz")
<< 2ULL
<< 1ULL;
<< 3ULL;
} else {
qDebug() << "7z/zip executable not found in path. Skipping compress-here-(ZIP) tests.";
......@@ -171,32 +159,28 @@ void AddToArchiveTest::testCompressHere_data()
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testdir")}
<< QStringLiteral("testdir.rar")
<< 2ULL
<< 1ULL;
<< 3ULL;
QTest::newRow("compress here (as RAR) - dir with subdirs")
<< QStringLiteral("rar")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testdirwithsubdirs")}
<< QStringLiteral("testdirwithsubdirs.rar")
<< 4ULL
<< 4ULL;
<< 8ULL;
QTest::newRow("compress here (as RAR) - dir with empty subdir")
<< QStringLiteral("rar")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testdirwithemptysubdir")}
<< QStringLiteral("testdirwithemptysubdir.rar")
<< 2ULL
<< 2ULL;
<< 4ULL;
QTest::newRow("compress here (as RAR) - single file")
<< QStringLiteral("rar")
<< Archive::Unencrypted
<< QStringList {QFINDTESTDATA("data/testfile.txt")}
<< QStringLiteral("testfile.rar")
<< 1ULL
<< 0ULL;
<< 1ULL;
QTest::newRow("compress here (as RAR) - file + folder")
<< QStringLiteral("rar")
......@@ -206,8 +190,7 @@ void AddToArchiveTest::testCompressHere_data()
QFINDTESTDATA("data/testfile.txt")
}
<< QStringLiteral("data.rar")
<< 3ULL
<< 1ULL;
<< 4ULL;
QTest::newRow("compress to encrypted RAR - file + folder")
<< QStringLiteral("rar")
......@@ -217,8 +200,7 @@ void AddToArchiveTest::testCompressHere_data()
QFINDTESTDATA("data/testfile.txt")
}
<< QStringLiteral("data.rar")
<< 3ULL
<< 1ULL;
<< 4ULL;
} else {
qDebug() << "rar executable not found in path. Skipping compress-here-(RAR) tests.";
}
......@@ -260,11 +242,8 @@ void AddToArchiveTest::testCompressHere()
QCOMPARE(archive->encryptionType(), expectedEncryptionType);
QFETCH(qulonglong, expectedNumberOfFiles);
QCOMPARE(archive->numberOfFiles(), expectedNumberOfFiles);
QFETCH(qulonglong, expectedNumberOfFolders);
QCOMPARE(archive->numberOfFolders(), expectedNumberOfFolders);
QFETCH(qulonglong, expectedNumberOfEntries);
QCOMPARE(archive->numberOfEntries(), expectedNumberOfEntries);
QVERIFY(QFile(archive->fileName()).remove());
......
......@@ -64,9 +64,10 @@ bool JSONArchiveInterface::open()
return !m_archive.isEmpty();
}
bool JSONArchiveInterface::addFiles(const QVector<Kerfuffle::Archive::Entry*>& files, const Kerfuffle::Archive::Entry *destination, const Kerfuffle::CompressionOptions& options)
bool JSONArchiveInterface::addFiles(const QVector<Kerfuffle::Archive::Entry*>& files, const Kerfuffle::Archive::Entry *destination, const Kerfuffle::CompressionOptions& options, uint numberOfEntriesToAdd)
{
Q_UNUSED(options)
Q_UNUSED(numberOfEntriesToAdd)
foreach (const Kerfuffle::Archive::Entry *entry, files) {
const QString &path = destination->fullPath() + entry->fullPath();
......
......@@ -55,7 +55,7 @@ public:
virtual bool list() Q_DECL_OVERRIDE;
virtual bool open() Q_DECL_OVERRIDE;
virtual bool addFiles(const QVector<Kerfuffle::Archive::Entry*>& files, const Kerfuffle::Archive::Entry *destination, const Kerfuffle::CompressionOptions& options) Q_DECL_OVERRIDE;
virtual bool addFiles(const QVector<Kerfuffle::Archive::Entry*>& files, const Kerfuffle::Archive::Entry *destination, const Kerfuffle::CompressionOptions& options, uint numberOfEntriesToAdd = 0) Q_DECL_OVERRIDE;
virtual bool moveFiles(const QVector<Kerfuffle::Archive::Entry*>& files, Kerfuffle::Archive::Entry *destination, const Kerfuffle::CompressionOptions& options) Q_DECL_OVERRIDE;
virtual bool copyFiles(const QVector<Kerfuffle::Archive::Entry*>& files, Kerfuffle::Archive::Entry *destination, const Kerfuffle::CompressionOptions& options) Q_DECL_OVERRIDE;
virtual bool extractFiles(const QVector<Kerfuffle::Archive::Entry*>& files, const QString &destinationDirectory, const Kerfuffle::ExtractionOptions& options) Q_DECL_OVERRIDE;
......
......@@ -163,15 +163,12 @@ Archive::Archive(ReadOnlyArchiveInterface *archiveInterface, bool isReadOnly, QO
, m_extractedFilesSize(0)
, m_error(NoError)
, m_encryptionType(Unencrypted)
, m_numberOfFiles(0)
, m_numberOfFolders(0)
{
qCDebug(ARK) << "Created archive instance";
Q_ASSERT(m_iface);
m_iface->setParent(this);
connect(m_iface, &ReadOnlyArchiveInterface::entry, this, &Archive::onNewEntry);
connect(m_iface, &ReadOnlyArchiveInterface::compressionMethodFound, this, &Archive::onCompressionMethodFound);
}
......@@ -264,13 +261,13 @@ QMimeType Archive::mimeType()
bool Archive::isEmpty() const
{
return (numberOfFiles() == 0) && (numberOfFolders() == 0);
return (numberOfEntries() == 0);
}
bool Archive::isReadOnly() const
{
return isValid() ? (m_iface->isReadOnly() || m_isReadOnly ||
(isMultiVolume() && (numberOfFiles() > 0 || numberOfFolders() > 0))) : false;
(isMultiVolume() && (numberOfEntries() > 0))) : false;
}
bool Archive::isSingleFolder() const
......@@ -320,22 +317,13 @@ QString Archive::password() const
return m_iface->password();
}
qulonglong Archive::numberOfFiles() const
uint Archive::numberOfEntries() const
{
if (!isValid()) {
return 0;
}
return m_numberOfFiles;
}
qulonglong Archive::numberOfFolders() const
{
if (!isValid()) {
return 0;
}
return m_numberOfFolders;
return m_iface->numberOfEntries();
}
qulonglong Archive::unpackedSize() const
......@@ -361,11 +349,6 @@ QString Archive::subfolderName() const
return m_subfolderName;
}
void Archive::onNewEntry(const Archive::Entry *entry)
{
entry->isDir() ? m_numberOfFolders++ : m_numberOfFiles++;
}
bool Archive::isValid() const
{
return m_iface && (m_error == NoError);
......
......@@ -80,8 +80,7 @@ class KERFUFFLE_EXPORT Archive : public QObject
Q_PROPERTY(bool isMultiVolume READ isMultiVolume WRITE setMultiVolume)
Q_PROPERTY(bool numberOfVolumes READ numberOfVolumes)
Q_PROPERTY(EncryptionType encryptionType MEMBER m_encryptionType READ encryptionType)
Q_PROPERTY(qulonglong numberOfFiles READ numberOfFiles)
Q_PROPERTY(qulonglong numberOfFolders READ numberOfFolders)
Q_PROPERTY(uint numberOfEntries READ numberOfEntries)
Q_PROPERTY(qulonglong unpackedSize MEMBER m_extractedFilesSize READ unpackedSize)
Q_PROPERTY(qulonglong packedSize READ packedSize)
Q_PROPERTY(QString subfolderName MEMBER m_subfolderName READ subfolderName)
......@@ -113,8 +112,7 @@ public:
int numberOfVolumes() const;
EncryptionType encryptionType() const;
QString password() const;
qulonglong numberOfFiles() const;
qulonglong numberOfFolders() const;
uint numberOfEntries() const;
qulonglong unpackedSize() const;
qulonglong packedSize() const;
QString subfolderName() const;
......@@ -212,7 +210,6 @@ public:
private slots:
void onAddFinished(KJob*);
void onUserQuery(Kerfuffle::Query*);
void onNewEntry(const Archive::Entry *entry);
void onCompressionMethodFound(const QStringList &methods);
private:
......
......@@ -40,6 +40,7 @@ namespace Kerfuffle
ReadOnlyArchiveInterface::ReadOnlyArchiveInterface(QObject *parent, const QVariantList & args)
: QObject(parent)
, m_numberOfVolumes(0)
, m_numberOfEntries(0)
, m_waitForFinishedSignal(false)
, m_isHeaderEncryptionEnabled(false)
, m_isCorrupt(false)
......@@ -47,12 +48,26 @@ ReadOnlyArchiveInterface::ReadOnlyArchiveInterface(QObject *parent, const QVaria
{
qCDebug(ARK) << "Created read-only interface for" << args.first().toString();
m_filename = args.first().toString();
connect(this, &ReadOnlyArchiveInterface::entry, this, &ReadOnlyArchiveInterface::onEntry);
connect(this, &ReadOnlyArchiveInterface::entryRemoved, this, &ReadOnlyArchiveInterface::onEntryRemoved);
}
ReadOnlyArchiveInterface::~ReadOnlyArchiveInterface()
{
}
void ReadOnlyArchiveInterface::onEntry(Archive::Entry *archiveEntry)
{
Q_UNUSED(archiveEntry)
m_numberOfEntries++;
}
void ReadOnlyArchiveInterface::onEntryRemoved(const QString &path)
{
Q_UNUSED(path)
m_numberOfEntries--;
}
QString ReadOnlyArchiveInterface::filename() const
{
return m_filename;
......@@ -260,4 +275,9 @@ bool ReadWriteArchiveInterface::isReadOnly() const
}
}
int ReadOnlyArchiveInterface::numberOfEntries() const
{
return m_numberOfEntries;
}
} // namespace Kerfuffle
......@@ -156,6 +156,7 @@ public:
bool isHeaderEncryptionEnabled() const;
virtual QString multiVolumeName() const;
void setMultiVolume(bool value);
int numberOfEntries() const;
signals:
void cancelled();
......@@ -181,6 +182,7 @@ protected:
bool isCorrupt() const;
QString m_comment;
int m_numberOfVolumes;
int m_numberOfEntries;
private:
QString m_filename;
......@@ -189,6 +191,10 @@ private:
bool m_isHeaderEncryptionEnabled;
bool m_isCorrupt;
bool m_isMultiVolume;
private slots:
void onEntry(Archive::Entry *archiveEntry);
void onEntryRemoved(const QString &path);
};
class KERFUFFLE_EXPORT ReadWriteArchiveInterface: public ReadOnlyArchiveInterface
......@@ -204,7 +210,7 @@ public:
bool isReadOnly() const Q_DECL_OVERRIDE;
virtual bool addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions& options) = 0;
virtual bool addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions& options, uint numberOfEntriesToAdd = 0) = 0;
virtual bool moveFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions& options) = 0;
virtual bool copyFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions& options) = 0;
virtual bool deleteFiles(const QVector<Archive::Entry*> &files) = 0;
......
......@@ -106,6 +106,7 @@ bool CliInterface::list()
resetParsing();
cacheParameterList();
m_operationMode = List;
m_numberOfEntries = 0;
const auto args = substituteListVariables(m_param.value(ListArgs).toStringList(), password());
......@@ -168,8 +169,10 @@ bool CliInterface::extractFiles(const QVector<Archive::Entry*> &files, const QSt
return true;
}
bool CliInterface::addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions& options)
bool CliInterface::addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions& options, uint numberOfEntriesToAdd)
{
Q_UNUSED(numberOfEntriesToAdd)
cacheParameterList();
m_operationMode = Add;
......@@ -265,6 +268,7 @@ bool CliInterface::copyFiles(const QVector<Archive::Entry*> &files, Archive::Ent
m_passedFiles = files;
m_passedDestination = destination;
m_passedOptions = options;
m_numberOfEntries = 0;
m_subOperation = Extract;
connect(this, &CliInterface::finished, this, &CliInterface::continueCopying);
......
......@@ -307,7 +307,7 @@ public:
virtual bool list() Q_DECL_OVERRIDE;
virtual bool extractFiles(const QVector<Archive::Entry*> &files, const QString &destinationDirectory, const ExtractionOptions &options) Q_DECL_OVERRIDE;
virtual bool addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions& options) Q_DECL_OVERRIDE;
virtual bool addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions& options, uint numberOfEntriesToAdd = 0) Q_DECL_OVERRIDE;
virtual bool moveFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions& options) Q_DECL_OVERRIDE;
virtual bool copyFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions& options) Q_DECL_OVERRIDE;
virtual bool deleteFiles(const QVector<Archive::Entry*> &files) Q_DECL_OVERRIDE;
......
......@@ -556,7 +556,7 @@ OpenWithJob::OpenWithJob(Archive::Entry *entry, bool passwordProtectedHint, Read
qCDebug(ARK) << "OpenWithJob started";
}
AddJob::AddJob(const QVector<Archive::Entry*> &entries, const Archive::Entry *destination, const CompressionOptions& options , ReadWriteArchiveInterface *interface)
AddJob::AddJob(const QVector<Archive::Entry*> &entries, const Archive::Entry *destination, const CompressionOptions& options, ReadWriteArchiveInterface *interface)
: Job(interface)
, m_entries(entries)
, m_destination(destination)
......@@ -616,7 +616,7 @@ void AddJob::doWork()
}
connectToArchiveInterfaceSignals();
bool ret = m_writeInterface->addFiles(m_entries, m_destination, m_options);
bool ret = m_writeInterface->addFiles(m_entries, m_destination, m_options, totalCount);
if (!archiveInterface()->waitForFinishedSignal()) {
onFinished(ret);
......
......@@ -663,8 +663,6 @@ void ArchiveModel::newEntry(Archive::Entry *receivedEntry, InsertBehaviour behav
// Skip already created entries.
Archive::Entry *existing = m_rootEntry->findByPath(entryFileName.split(QLatin1Char('/')));
if (existing) {
qCDebug(ARK) << "Refreshing entry for" << entryFileName;
existing->setProperty("fullPath", entryFileName);
// Multi-volume files are repeated at least in RAR archives.
// In that case, we need to sum the compressed size for each volume
......
......@@ -22,9 +22,9 @@
#include "cliplugin.h"
#include "ark_debug.h"
#include "kerfuffle/archiveentry.h"
#include "kerfuffle/cliinterface.h"
#include "kerfuffle/kerfuffle_export.h"
#include "kerfuffle/archiveentry.h"
#include <KPluginFactory>
......
......@@ -65,6 +65,7 @@ bool LibarchivePlugin::list()
m_cachedArchiveEntryCount = 0;
m_extractedFilesSize = 0;
m_numberOfEntries = 0;
qulonglong compressedArchiveSize = QFileInfo(filename()).size();
struct archive_entry *aentry;
......@@ -98,11 +99,12 @@ bool LibarchivePlugin::list()
return archive_read_close(m_archiveReader.data()) == ARCHIVE_OK;
}
bool LibarchivePlugin::addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions &options)
bool LibarchivePlugin::addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions &options, uint numberOfEntriesToAdd)
{
Q_UNUSED(files)
Q_UNUSED(destination)
Q_UNUSED(options)
Q_UNUSED(numberOfEntriesToAdd)
return false;
}
......
......@@ -49,7 +49,7 @@ public:
virtual bool doKill() Q_DECL_OVERRIDE;
virtual bool extractFiles(const QVector<Archive::Entry*> &files, const QString &destinationDirectory, const ExtractionOptions &options) Q_DECL_OVERRIDE;
virtual bool addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions &options) Q_DECL_OVERRIDE;
virtual bool addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions &options, uint numberOfEntriesToAdd = 0) Q_DECL_OVERRIDE;
virtual bool moveFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions &options) Q_DECL_OVERRIDE;
virtual bool copyFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions &options) Q_DECL_OVERRIDE;
virtual bool deleteFiles(const QVector<Archive::Entry*> &files) Q_DECL_OVERRIDE;
......
......@@ -47,11 +47,12 @@ ReadWriteLibarchivePlugin::~ReadWriteLibarchivePlugin()
{
}
bool ReadWriteLibarchivePlugin::addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions &options)
bool ReadWriteLibarchivePlugin::addFiles(const QVector<Archive::Entry*> &files, const Archive::Entry *destination, const CompressionOptions &options, uint numberOfEntriesToAdd)
{
qCDebug(ARK) << "Adding" << files.size() << "entries with CompressionOptions" << options;
const bool creatingNewFile = !QFileInfo::exists(filename());
const uint totalCount = m_numberOfEntries + numberOfEntriesToAdd;
m_writtenFiles.clear();
......@@ -81,6 +82,7 @@ bool ReadWriteLibarchivePlugin::addFiles(const QVector<Archive::Entry*> &files,
return false;
}
no_entries++;
emit progress(float(no_entries)/float(totalCount));
// For directories, write all subfiles/folders.
const QString &fullPath = selectedFile->fullPath();
......@@ -109,6 +111,7 @@ bool ReadWriteLibarchivePlugin::addFiles(const QVector<Archive::Entry*> &files,
return false;
}
no_entries++;
emit progress(float(no_entries)/float(totalCount));
}
}
}
......@@ -119,7 +122,7 @@ bool ReadWriteLibarchivePlugin::addFiles(const QVector<Archive::Entry*> &files,
if (!creatingNewFile) {
qCDebug(ARK) << "Copying any old entries";
m_filesPaths = m_writtenFiles;
isSuccessful = processOldEntries(no_entries, Add);
isSuccessful = processOldEntries(no_entries, Add, totalCount);
if (isSuccessful) {
qCDebug(ARK) << "Added" << no_entries << "old entries to archive";
} else {
......@@ -150,7 +153,7 @@ bool ReadWriteLibarchivePlugin::moveFiles(const QVector<Archive::Entry*> &files,
m_filesPaths = entryFullPaths(files);
m_entriesWithoutChildren = entriesWithoutChildren(files).count();
m_destination = destination;
const bool isSuccessful = processOldEntries(no_entries, Move);
const bool isSuccessful = processOldEntries(no_entries, Move, m_numberOfEntries);
if (isSuccessful) {
qCDebug(ARK) << "Moved" << no_entries << "entries within archive";
} else {
......@@ -180,7 +183,7 @@ bool ReadWriteLibarchivePlugin::copyFiles(const QVector<Archive::Entry*> &files,
m_filesPaths = entryFullPaths(files);
m_entriesWithoutChildren = 0; // we don't care
m_destination = destination;
const bool isSuccessful = processOldEntries(no_entries, Copy);
const bool isSuccessful = processOldEntries(no_entries, Copy, m_numberOfEntries);
if (isSuccessful) {
qCDebug(ARK) << "Copied" << no_entries << "entries within archive";
} else {
......@@ -206,7 +209,7 @@ bool ReadWriteLibarchivePlugin::deleteFiles(const QVector<Archive::Entry*> &file
// Copy old elements from previous archive to new archive.
int no_entries = 0;
m_filesPaths = entryFullPaths(files);
const bool isSuccessful = processOldEntries(no_entries, Delete);
const bool isSuccessful = processOldEntries(no_entries, Delete, m_numberOfEntries);
if (isSuccessful) {
qCDebug(ARK) << "Removed" << no_entries << "entries from archive";
} else {
......@@ -386,11 +389,13 @@ void ReadWriteLibarchivePlugin::finish(const bool isSuccessful)
m_tempFile.commit();
}
bool ReadWriteLibarchivePlugin::processOldEntries(int &entriesCounter, OperationMode mode)
bool ReadWriteLibarchivePlugin::processOldEntries(int &entriesCounter, OperationMode mode, uint totalCount)
{
struct archive_entry *entry;
const uint newEntries = entriesCounter;
entriesCounter = 0;
int iteratedEntries = 0;
QMap<QString, QString> pathMap;
if (mode == Move || mode == Copy) {
......@@ -419,7 +424,11 @@ bool ReadWriteLibarchivePlugin::processOldEntries(int &entriesCounter, Operation
}
entriesCounter++;
iteratedEntries--;
// Change entry path.
archive_entry_set_pathname(entry, newPathname.toUtf8());
emitEntryFromArchiveEntry(entry);
}
} else if (m_filesPaths.contains(file)) {
archive_read_data_skip(m_archiveReader.data());
......@@ -427,6 +436,7 @@ bool ReadWriteLibarchivePlugin::processOldEntries(int &entriesCounter, Operation
case Delete:
entriesCounter++;
emit entryRemoved(file);
emit progress(float(newEntries + entriesCounter + iteratedEntries)/float(totalCount));
break;
case Add:
......@@ -440,15 +450,19 @@ bool ReadWriteLibarchivePlugin::processOldEntries(int &entriesCounter, Operation
continue;
}
// Write old entries.