From 041394eac5c5480f927599e4b6be0dda2f656a69 Mon Sep 17 00:00:00 2001 From: EndrII Date: Tue, 19 Jan 2021 14:26:11 +0300 Subject: [PATCH] fix recursive moving --- Deploy/Deploy.pro | 2 ++ Deploy/configparser.cpp | 70 ++++++++++++++++++++++++++--------------- Deploy/configparser.h | 3 +- Deploy/deployconfig.cpp | 2 +- Deploy/deployconfig.h | 4 +-- Deploy/filemanager.cpp | 4 +++ Deploy/targetdata.cpp | 1 + Deploy/targetdata.h | 22 +++++++++++++ 8 files changed, 79 insertions(+), 29 deletions(-) create mode 100644 Deploy/targetdata.cpp create mode 100644 Deploy/targetdata.h diff --git a/Deploy/Deploy.pro b/Deploy/Deploy.pro index 3bdad4d..cce480d 100644 --- a/Deploy/Deploy.pro +++ b/Deploy/Deploy.pro @@ -77,6 +77,7 @@ SOURCES += \ qml.cpp \ libinfo.cpp \ qtdir.cpp \ + targetdata.cpp \ targetinfo.cpp \ zipcompresser.cpp @@ -114,6 +115,7 @@ HEADERS += \ qml.h \ libinfo.h \ qtdir.h \ + targetdata.h \ targetinfo.h \ zipcompresser.h diff --git a/Deploy/configparser.cpp b/Deploy/configparser.cpp index d248f7b..dcaf16c 100644 --- a/Deploy/configparser.cpp +++ b/Deploy/configparser.cpp @@ -487,29 +487,32 @@ bool ConfigParser::initPackages() { for (auto& str: tar_packages_array) { - auto pair = str.split(DeployCore::getSeparator(1)); - auto package = PathUtils::fullStripPath(pair.value(0, "")); + auto paramsList = str.split(DeployCore::getSeparator(1)); + auto package = PathUtils::fullStripPath(paramsList.value(0, "")); - auto list = _config.getTargetsListByFilter(pair.value(1, "")); + for (int i = 1; i < paramsList.size(); ++i) { + auto targetPattern = paramsList.value(i); + auto list = _config.getTargetsListByFilter(targetPattern); - if (!list.size()) { - auto warning = QString("You create the %0 package with the %1 pattern, " - "but no matches were found for this pattern. "). - arg(package, pair.value(1, "")); - QuasarAppUtils::Params::log(warning, QuasarAppUtils::Warning); - continue; - } - - for (auto it = list.begin(); it != list.end(); ++it) { - if (!configuredTargets.contains(it.key())) { - configuredTargets.insert(it.key()); - it.value()->setPackage(package); + if (!list.size()) { + auto warning = QString("You create the %0 package with the %1 pattern, " + "but no matches were found for this pattern. "). + arg(package, targetPattern); + QuasarAppUtils::Params::log(warning, QuasarAppUtils::Warning); + continue; } + + for (auto it = list.begin(); it != list.end(); ++it) { + if (!configuredTargets.contains(it.key())) { + configuredTargets.insert(it.key()); + it.value()->setPackage(package); + } + } + + _config.packagesEdit().insert(package, DistroModule{package}); } - _config.packagesEdit().insert(package, DistroModule{package}); - - if (pair.size() != 2) { + if (paramsList.size() < 2) { defaultPackage = package; } } @@ -773,7 +776,10 @@ bool ConfigParser::setTargets(const QStringList &value) { if (targetInfo.isFile()) { - _config.targetsEdit().unite(createTarget(QDir::fromNativeSeparators(i))); + auto target = createTarget(QDir::fromNativeSeparators(i)); + if (!_config.targetsEdit().contains(target.target)) { + _config.targetsEdit().insert(target.target, target.targetInfo); + } isfillList = true; } @@ -825,7 +831,7 @@ bool ConfigParser::setTargetsInDir(const QString &dir, bool recursive) { } bool result = false; - for (const auto &file : list) { + for (const auto &file : qAsConst(list)) { if (file.isDir()) { result |= setTargetsInDir(file.absoluteFilePath(), recursive); @@ -838,9 +844,13 @@ bool ConfigParser::setTargetsInDir(const QString &dir, bool recursive) { if (sufix.isEmpty() || name.contains(".dll", Qt::CaseInsensitive) || name.contains(".so", Qt::CaseInsensitive) || name.contains(".exe", Qt::CaseInsensitive)) { - result = true; - _config.targetsEdit().unite(createTarget(QDir::fromNativeSeparators(file.absoluteFilePath()))); + auto target = createTarget(QDir::fromNativeSeparators(file.absoluteFilePath())); + if (!_config.targetsEdit().contains(target.target)) { + _config.targetsEdit().insert(target.target, target.targetInfo); + } + + result = true; } @@ -849,13 +859,13 @@ bool ConfigParser::setTargetsInDir(const QString &dir, bool recursive) { return result; } -QHash ConfigParser::createTarget(const QString &target) { +TargetData ConfigParser::createTarget(const QString &target) { TargetInfo libinfo; auto key = target; if (_scaner->fillLibInfo(libinfo, key)) { - return {{libinfo.fullPath(), libinfo}}; + return {libinfo.fullPath(), libinfo}; } - return {{key, {}}}; + return {key, {}}; } QHash @@ -1455,6 +1465,16 @@ bool ConfigParser::smartMoveTargets() { bool result = true; for (auto i = _config.targets().cbegin(); i != _config.targets().cend(); ++i) { + if (!i.value().isValid()) { + QuasarAppUtils::Params::log(QString("Interna error ocurred in %0. Target not inited.").arg(__FUNCTION__), + QuasarAppUtils::Error); + QuasarAppUtils::Params::log(QString("If you see this message please create a new issue" + " about this problem on the official github page" + " https://github.com/QuasarApp/CQtDeployer/issues/new/choose. "), + QuasarAppUtils::Error); + return false; + } + QFileInfo target(i.key()); QString targetPath = _config.getTargetDir() + "/" + i.value().getPackage(); diff --git a/Deploy/configparser.h b/Deploy/configparser.h index 6c6f109..899773d 100644 --- a/Deploy/configparser.h +++ b/Deploy/configparser.h @@ -11,6 +11,7 @@ #include "distrostruct.h" #include "envirement.h" #include "ignorerule.h" +#include "targetdata.h" #include "targetinfo.h" #include @@ -100,7 +101,7 @@ private: void readKey(const QString &key, const QJsonObject &obj, const QString &confFileDir) const; void readString(const QString &key, const QString &val, const QString &confFileDir) const; - QHash createTarget(const QString &target); + TargetData createTarget(const QString &target); QHash moveTarget(TargetInfo target, const QString &newLocation); diff --git a/Deploy/deployconfig.cpp b/Deploy/deployconfig.cpp index 8f4ce45..6a1beac 100644 --- a/Deploy/deployconfig.cpp +++ b/Deploy/deployconfig.cpp @@ -52,7 +52,7 @@ DistroModule DeployConfig::getDistroFromPackage(const QString &package) const { return _packages.value(package, DistroModule{package}); } -QMultiHash &DeployConfig::targetsEdit() { +QHash &DeployConfig::targetsEdit() { return _targets; } diff --git a/Deploy/deployconfig.h b/Deploy/deployconfig.h index 8eb4213..5f583ef 100644 --- a/Deploy/deployconfig.h +++ b/Deploy/deployconfig.h @@ -95,7 +95,7 @@ public: const QHash& targets() const; const QHash& packages() const; - QMultiHash &targetsEdit(); + QHash &targetsEdit(); QHash& packagesEdit(); /** @@ -125,7 +125,7 @@ private: * key - path * value - create wrapper */ - QMultiHash _targets; + QHash _targets; /** * @brief packages diff --git a/Deploy/filemanager.cpp b/Deploy/filemanager.cpp index 02d9688..0cb25e4 100644 --- a/Deploy/filemanager.cpp +++ b/Deploy/filemanager.cpp @@ -352,6 +352,10 @@ bool FileManager::cp(const QString &from, bool FileManager::moveFolder(const QString &from, const QString &to, const QString& ignore) { QFileInfo info(from); + if (to.contains(from)) { + return false; + } + if (!info.exists()) return false; diff --git a/Deploy/targetdata.cpp b/Deploy/targetdata.cpp new file mode 100644 index 0000000..2bacb3d --- /dev/null +++ b/Deploy/targetdata.cpp @@ -0,0 +1 @@ +#include "targetdata.h" diff --git a/Deploy/targetdata.h b/Deploy/targetdata.h new file mode 100644 index 0000000..94acaf2 --- /dev/null +++ b/Deploy/targetdata.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2018-2021 QuasarApp. + * Distributed under the lgplv3 software license, see the accompanying + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + */ + +#ifndef TARGETDATA_H +#define TARGETDATA_H + +#include "targetinfo.h" + + +/** + * @brief The TargetData struct simple info structo about target. + */ +struct TargetData { + QString target; + TargetInfo targetInfo; +}; + +#endif // TARGETDATA_H