Commit 48d180b6 authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

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`.
parent 9eebadb9
......@@ -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;
......
......@@ -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;
}
......
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