summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-16 13:39:57 (GMT)
committerElvis Angelaccio <elvis.angelaccio@kde.org>2016-10-16 13:39:57 (GMT)
commit48d180b6660f2ad4daf43d43848fd69aeefe0d52 (patch)
tree5f166db4fd6f34be61a903ee05230264de934a53
parent9eebadb9f8fb2eefefdf4e7c2e5f52d3a2e38bab (diff)
clizip: fix processing of destination when moving files
We need to check whether the destination path is already a single folder, otherwise we would wrongly replace e.g. `dir/` to `d`.
-rw-r--r--kerfuffle/cliinterface.cpp3
-rw-r--r--plugins/clizipplugin/cliplugin.cpp26
2 files changed, 20 insertions, 9 deletions
diff --git a/kerfuffle/cliinterface.cpp b/kerfuffle/cliinterface.cpp
index 84fae96..87c281d 100644
--- a/kerfuffle/cliinterface.cpp
+++ b/kerfuffle/cliinterface.cpp
@@ -182,6 +182,9 @@ bool CliInterface::addFiles(const QVector<Archive::Entry*> &files, const Archive
const QString destinationPath = (destination == Q_NULLPTR)
? QString()
: destination->fullPath();
+
+ qCDebug(ARK) << "Adding" << files.count() << "file(s) to destination:" << destinationPath;
+
if (!destinationPath.isEmpty()) {
m_extractTempDir = new QTemporaryDir();
const QString absoluteDestinationPath = m_extractTempDir->path() + QLatin1Char('/') + destinationPath;
diff --git a/plugins/clizipplugin/cliplugin.cpp b/plugins/clizipplugin/cliplugin.cpp
index c98e786..a4f0d35 100644
--- a/plugins/clizipplugin/cliplugin.cpp
+++ b/plugins/clizipplugin/cliplugin.cpp
@@ -202,6 +202,8 @@ bool CliPlugin::readListLine(const QString &line)
bool CliPlugin::moveFiles(const QVector<Archive::Entry*> &files, Archive::Entry *destination, const CompressionOptions &options)
{
+ qCDebug(ARK) << "Moving" << files.count() << "file(s) to destination:" << destination;
+
m_oldWorkingDir = QDir::currentPath();
m_tempExtractDir = new QTemporaryDir();
m_tempAddDir = new QTemporaryDir();
@@ -268,15 +270,21 @@ bool CliPlugin::setMovingAddedFiles()
// We have to exclude file name from destination path in order to pass it to addFiles method.
const QString destinationPath = m_passedDestination->fullPath();
- int destinationLength = destinationPath.count();
- bool iteratedChar = false;
- do {
- destinationLength--;
- if (destinationPath.at(destinationLength) != QLatin1Char('/')) {
- iteratedChar = true;
- }
- } while (destinationLength > 0 && !(iteratedChar && destinationPath.at(destinationLength) == QLatin1Char('/')));
- m_passedDestination->setProperty("fullPath", destinationPath.left(destinationLength + 1));
+ if (!destinationPath.endsWith(QLatin1Char('/')) || destinationPath.count(QLatin1Char('/')) > 1) {
+ int destinationLength = destinationPath.count();
+ bool iteratedChar = false;
+ do {
+ destinationLength--;
+ if (destinationPath.at(destinationLength) != QLatin1Char('/')) {
+ iteratedChar = true;
+ }
+ } while (destinationLength > 0 && !(iteratedChar && destinationPath.at(destinationLength) == QLatin1Char('/')));
+ m_passedDestination->setProperty("fullPath", destinationPath.left(destinationLength + 1));
+ } else {
+ // ...unless the destination path is already a single folder, e.g. "dir/".
+ // In this case we're going to add to the root, so we just need to set a null destination.
+ m_passedDestination = Q_NULLPTR;
+ }
return true;
}