mirror of
https://github.com/QuasarApp/CQtDeployer.git
synced 2025-04-28 02:34:34 +00:00
added tests to flag always-overwrite and fixed it
This commit is contained in:
parent
290dc32160
commit
459f30873f
@ -52,8 +52,6 @@ bool CQT::parseParams() {
|
||||
|
||||
DeployCore::_config = &_config;
|
||||
|
||||
smartMoveTargets();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -72,13 +72,13 @@ private:
|
||||
|
||||
QStringList getDirsRecursive(const QString &path);
|
||||
|
||||
bool smartMoveTargets();
|
||||
|
||||
void writeKey(const QString &key, QJsonObject &) const;
|
||||
void readKey(const QString &key, const QJsonObject &obj) const;
|
||||
public:
|
||||
CQT(FileManager *filemanager);
|
||||
bool parseParams();
|
||||
bool smartMoveTargets();
|
||||
|
||||
const DeployConfig* config() const;
|
||||
friend class deploytest;
|
||||
|
@ -45,7 +45,7 @@ bool Deploy::prepare() {
|
||||
return false;
|
||||
}
|
||||
|
||||
_extracter = new Extracter(_fileManager);
|
||||
_extracter = new Extracter(_fileManager, _paramsParser);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -169,6 +169,8 @@ void Extracter::deploy() {
|
||||
QuasarAppUtils::Params::isEndable("force-clear"));
|
||||
}
|
||||
|
||||
_cqt->smartMoveTargets();
|
||||
|
||||
scaner.setEnvironment(DeployCore::_config->envirement.deployEnvironment());
|
||||
|
||||
for (auto i = DeployCore::_config->targets.cbegin(); i != DeployCore::_config->targets.cend(); ++i) {
|
||||
@ -406,9 +408,11 @@ void Extracter::extract(const QString &file) {
|
||||
|
||||
}
|
||||
|
||||
Extracter::Extracter(FileManager *fileManager):
|
||||
_fileManager(fileManager) {
|
||||
Extracter::Extracter(FileManager *fileManager, CQT *cqt):
|
||||
_fileManager(fileManager),
|
||||
_cqt(cqt) {
|
||||
|
||||
assert(_cqt);
|
||||
assert(_fileManager);
|
||||
assert(DeployCore::_config);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "filemanager.h"
|
||||
#include "qml.h"
|
||||
|
||||
class CQT;
|
||||
|
||||
class DEPLOYSHARED_EXPORT Extracter {
|
||||
private:
|
||||
@ -24,6 +25,7 @@ class DEPLOYSHARED_EXPORT Extracter {
|
||||
|
||||
DependenciesScanner scaner;
|
||||
FileManager *_fileManager;
|
||||
CQT *_cqt;
|
||||
|
||||
void extract(const QString &file);
|
||||
bool copyTranslations(QStringList list);
|
||||
@ -45,7 +47,7 @@ class DEPLOYSHARED_EXPORT Extracter {
|
||||
|
||||
|
||||
public:
|
||||
explicit Extracter(FileManager *fileManager);
|
||||
explicit Extracter(FileManager *fileManager, CQT * cqt);
|
||||
bool createRunScript(const QString &target);
|
||||
void deploy();
|
||||
|
||||
|
@ -33,8 +33,8 @@ void FileManager::loadDeployemendFiles(const QString &targetDir) {
|
||||
auto settings = QuasarAppUtils::Settings::get();
|
||||
QStringList deployedFiles = settings->getValue(targetDir, {}).toStringList();
|
||||
|
||||
_deployedFiles.clear();
|
||||
_deployedFiles.fromList(deployedFiles);
|
||||
// _deployedFiles.clear();
|
||||
_deployedFiles.unite(QSet<QString>::fromList(deployedFiles));
|
||||
}
|
||||
|
||||
|
||||
@ -155,19 +155,33 @@ bool FileManager::fileActionPrivate(const QString &file, const QString &target,
|
||||
" Qt error: " + sourceFile.errorString(),
|
||||
QuasarAppUtils::Warning);
|
||||
|
||||
std::ifstream src(file.toStdString(),
|
||||
std::ios::binary);
|
||||
std::ofstream dst((target + QDir::separator() + name).toStdString(),
|
||||
std::ios::binary);
|
||||
|
||||
dst << src.rdbuf();
|
||||
|
||||
if (!QFileInfo::exists(target + QDir::separator() + name)) {
|
||||
QuasarAppUtils::Params::verboseLog("std Operation fail file not copied. "
|
||||
"Сheck if you have access to the target dir",
|
||||
QuasarAppUtils::Error);
|
||||
if (QuasarAppUtils::Params::isEndable("always-overwrite") ||
|
||||
!QFileInfo(target + QDir::separator() + name).exists()) {
|
||||
std::ifstream src(file.toStdString(),
|
||||
std::ios::binary);
|
||||
|
||||
std::ofstream dst((target + QDir::separator() + name).toStdString(),
|
||||
std::ios::binary);
|
||||
|
||||
dst << src.rdbuf();
|
||||
|
||||
if (!QFileInfo::exists(target + QDir::separator() + name)) {
|
||||
QuasarAppUtils::Params::verboseLog("std Operation fail file not copied. "
|
||||
"Сheck if you have access to the target dir",
|
||||
QuasarAppUtils::Error);
|
||||
return false;
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
if (QFileInfo(target + QDir::separator() + name).exists()) {
|
||||
qInfo() << target + QDir::separator() + name << " already exists!";
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,13 +202,13 @@ bool FileManager::smartCopyFile(const QString &file, const QString &target,
|
||||
if (!copyFile(file, target, mask)) {
|
||||
qCritical() << "not copy target to bin dir " << file;
|
||||
return false;
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!copyFile(file, target, mask)) {
|
||||
qCritical() << "not copy target to bin dir " << file;
|
||||
return false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -262,7 +276,6 @@ void FileManager::clear(const QString& targetDir, bool force) {
|
||||
QuasarAppUtils::Warning);
|
||||
}
|
||||
|
||||
;
|
||||
QMap<int, QFileInfo> sortedOldData;
|
||||
for (auto& i : _deployedFiles) {
|
||||
sortedOldData.insertMulti(i.size(), QFileInfo(i));
|
||||
|
@ -31,6 +31,15 @@ QSet<QString> TestUtils::getTree(const QString &path) {
|
||||
return result;
|
||||
}
|
||||
|
||||
QSet<QString> TestUtils::createTree(const QStringList &tree) {
|
||||
QSet<QString> res;
|
||||
for (auto &i : tree) {
|
||||
res.insert(QFileInfo(i).absoluteFilePath());
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
QHash<QString, int> TestUtils::compareTree(const QSet<QString> &leftTree, const QSet<QString> &rightTree) {
|
||||
QHash<QString, int> result;
|
||||
|
||||
|
@ -8,6 +8,8 @@ class TestUtils
|
||||
public:
|
||||
TestUtils();
|
||||
QSet<QString> getTree( const QString& path);
|
||||
QSet<QString> createTree( const QStringList& tree);
|
||||
|
||||
/**
|
||||
* @brief compareTree - compare 2 tree
|
||||
* @param leftTree
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <qml.h>
|
||||
#include <deploy.h>
|
||||
#include <cqt.h>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
#include <QMap>
|
||||
#include <QByteArray>
|
||||
@ -71,6 +72,8 @@ private slots:
|
||||
// end old tests
|
||||
|
||||
void testHelp();
|
||||
void testOverwrite();
|
||||
|
||||
void testMSVC();
|
||||
|
||||
};
|
||||
@ -557,6 +560,59 @@ void deploytest::testHelp() {
|
||||
|
||||
}
|
||||
|
||||
void deploytest::testOverwrite() {
|
||||
TestUtils utils;
|
||||
|
||||
auto comapareTree = utils.createTree(
|
||||
{"./Distro/bin/TestOnlyC",
|
||||
"./Distro/TestOnlyC.sh"});
|
||||
|
||||
runTestParams({"-bin", "./../../../tests/build/TestOnlyC", "clear"}, &comapareTree);
|
||||
|
||||
|
||||
QFile f("./Distro/bin/TestOnlyC");
|
||||
|
||||
QVERIFY(f.open(QIODevice::ReadOnly));
|
||||
auto hashBefor = QCryptographicHash::hash(f.readAll(), QCryptographicHash::Md5);
|
||||
f.close();
|
||||
|
||||
QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Append));
|
||||
f.write(QByteArray(10, '1'));
|
||||
f.close();
|
||||
|
||||
QVERIFY(f.open(QIODevice::ReadOnly));
|
||||
auto hashAfter = QCryptographicHash::hash(f.readAll(), QCryptographicHash::Md5);
|
||||
f.close();
|
||||
|
||||
QVERIFY(hashAfter != hashBefor);
|
||||
|
||||
comapareTree = utils.createTree(
|
||||
{"./Distro/bin/TestOnlyC",
|
||||
"./Distro/TestOnlyC.sh"});
|
||||
|
||||
runTestParams({"-bin", "./../../../tests/build/TestOnlyC"}, &comapareTree);
|
||||
|
||||
QVERIFY(f.open(QIODevice::ReadOnly));
|
||||
hashAfter = QCryptographicHash::hash(f.readAll(), QCryptographicHash::Md5);
|
||||
f.close();
|
||||
|
||||
QVERIFY(hashAfter != hashBefor);
|
||||
|
||||
|
||||
comapareTree = utils.createTree(
|
||||
{"./Distro/bin/TestOnlyC",
|
||||
"./Distro/TestOnlyC.sh"});
|
||||
|
||||
runTestParams({"-bin", "./../../../tests/build/TestOnlyC", "always-overwrite"}, &comapareTree);
|
||||
|
||||
QVERIFY(f.open(QIODevice::ReadOnly));
|
||||
hashAfter = QCryptographicHash::hash(f.readAll(), QCryptographicHash::Md5);
|
||||
f.close();
|
||||
|
||||
QVERIFY(hashAfter == hashBefor);
|
||||
|
||||
}
|
||||
|
||||
bool deploytest::mainTestOnlyC() {
|
||||
#ifdef WITH_ALL_TESTS
|
||||
int argc = 5;
|
||||
|
Loading…
x
Reference in New Issue
Block a user