summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRagnar Thomsen <rthomsen6@gmail.com>2016-11-07 17:59:50 (GMT)
committerRagnar Thomsen <rthomsen6@gmail.com>2016-11-07 17:59:50 (GMT)
commitce4bec203b8a6c26c085a1f8df66b44676f3715a (patch)
tree1e04b76ddc176ad62e1a87d9ddd549eb7413ca00
parent9aaeb99c3c5028cf27d52913d73cb04e58258520 (diff)
Fix entry counter in libarchiveplugin when overwriting entries
When adding files to an archive with libarchiveplugin and the destination files already exist (so they get overwritten), the entry signal is still emitted and hence m_numberOfEntries gets wrongfully incremented. This diff decrements the counter when an entry already exists. Overwriting of entries is disabled for CopyJob and MoveJob, so there is no problem in those cases. Differential Revision: D3273
-rw-r--r--autotests/kerfuffle/addtest.cpp9
-rw-r--r--autotests/kerfuffle/data/a.txt1
-rw-r--r--plugins/libarchive/readwritelibarchiveplugin.cpp5
3 files changed, 15 insertions, 0 deletions
diff --git a/autotests/kerfuffle/addtest.cpp b/autotests/kerfuffle/addtest.cpp
index 8306d18..0175716 100644
--- a/autotests/kerfuffle/addtest.cpp
+++ b/autotests/kerfuffle/addtest.cpp
@@ -116,6 +116,15 @@ void AddTest::testAdding_data()
QStringLiteral("empty_dir/testdir2/testdir/testfile2.txt")
},
17);
+
+ setupRows(QStringLiteral("overwriting an existing entry"),
+ QStringLiteral("test"),
+ QVector<Archive::Entry*> {
+ new Archive::Entry(this, QStringLiteral("a.txt")),
+ },
+ new Archive::Entry(this),
+ QStringList(),
+ 13);
}
void AddTest::testAdding()
diff --git a/autotests/kerfuffle/data/a.txt b/autotests/kerfuffle/data/a.txt
new file mode 100644
index 0000000..4c29271
--- /dev/null
+++ b/autotests/kerfuffle/data/a.txt
@@ -0,0 +1 @@
+A simple text file (new).
diff --git a/plugins/libarchive/readwritelibarchiveplugin.cpp b/plugins/libarchive/readwritelibarchiveplugin.cpp
index aa76216..dd54609 100644
--- a/plugins/libarchive/readwritelibarchiveplugin.cpp
+++ b/plugins/libarchive/readwritelibarchiveplugin.cpp
@@ -397,6 +397,7 @@ bool ReadWriteLibarchivePlugin::processOldEntries(int &entriesCounter, Operation
entriesCounter = 0;
int iteratedEntries = 0;
+ // Create a map that contains old path as key and new path as value.
QMap<QString, QString> pathMap;
if (mode == Move || mode == Copy) {
m_filesPaths.sort();
@@ -416,6 +417,7 @@ bool ReadWriteLibarchivePlugin::processOldEntries(int &entriesCounter, Operation
const QString newPathname = pathMap.value(file);
if (!newPathname.isEmpty()) {
if (mode == Copy) {
+ // Write the old entry.
if (!writeEntry(entry)) {
return false;
}
@@ -441,6 +443,9 @@ bool ReadWriteLibarchivePlugin::processOldEntries(int &entriesCounter, Operation
case Add:
qCDebug(ARK) << file << "is already present in the new archive, skipping.";
+ // When overwriting entries, we need to decrement the counter manually,
+ // because entry was emitted.
+ m_numberOfEntries--;
break;
default: