Compare commits

...

4 Commits

Author SHA1 Message Date
cbe1fd387d After "rsync", compare etc/psa_tariff and /etc/psa_tariff, if they contain the
same traiff-files (as they should).
2023-08-22 12:31:15 +02:00
1620b73d01 Added sameFilesInDirs(): check for two different directories if the contain the
same files (comparison by name and by git-blob).
2023-08-22 12:29:52 +02:00
4ebdcf56a0 Clear message before showing a new one. 2023-08-22 12:21:17 +02:00
99b9419150 Made gitBlob() static and execute in /tmp as this command can be executed
for every file not only the files contained in a git repository.
2023-08-22 12:19:25 +02:00
6 changed files with 101 additions and 7 deletions

View File

@ -330,7 +330,7 @@ QString GitClient::gitBlob(QString fileName) {
if (fi.exists()) { if (fi.exists()) {
QString const gitCommand = QString("git hash-object %1").arg(fileName); QString const gitCommand = QString("git hash-object %1").arg(fileName);
Command c(gitCommand); Command c(gitCommand);
if (c.execute(m_workingDirectory)) { if (c.execute("/tmp")) {
return c.getCommandResult().trimmed(); return c.getCommandResult().trimmed();
} }
} }

View File

@ -51,7 +51,7 @@ class GitClient : public QObject {
QString gitLastCommit(QString fileName); QString gitLastCommit(QString fileName);
QStringList gitShowReason(); QStringList gitShowReason();
QString gitBlob(QString fileName); static QString gitBlob(QString fileName);
QString gitCommitForBlob(QString blob); QString gitCommitForBlob(QString blob);
bool gitIsFileTracked(QString file2name); bool gitIsFileTracked(QString file2name);
}; };

View File

@ -224,6 +224,7 @@ void MainWindow::onReplaceLast(QString text, QString suffix) {
} }
void MainWindow::onShowErrorMessage(QString title, QString text) { void MainWindow::onShowErrorMessage(QString title, QString text) {
this->statusBar()->showMessage( // timeout: 5000 this->statusBar()->clearMessage();
QString(title + ": " + text).leftJustified(80, ' '), 20000); this->statusBar()->showMessage( // timeout: 10000
QString(title + ": " + text).leftJustified(80, ' '), 10000);
} }

View File

@ -1,5 +1,6 @@
#include "utils.h" #include "utils.h"
#include "message_handler.h" #include "message_handler.h"
#include "git/git_client.h"
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
@ -86,3 +87,85 @@ QString Utils::rstrip(QString const &str) {
} }
return ""; return "";
} }
bool Utils::sameFilesInDirs(QDir const &dir1, QDir const &dir2,
QStringList const &nameFilters) {
if (!dir1.exists()) {
printCriticalErrorMsg(dir1.dirName() + " DOES NOT EXIST");
return false;
}
if (!dir2.exists()) {
printCriticalErrorMsg(dir2.dirName() + " DOES NOT EXIST");
return false;
}
if (dir1.absolutePath() == dir2.absolutePath()) {
printCriticalErrorMsg(dir1.dirName() + " AND "+ dir2.dirName() + " HAVE SAME PATH");
return false;
}
// files, sorted by name
QFileInfoList const &lst1 = dir1.entryInfoList(nameFilters, QDir::Files, QDir::Name);
QFileInfoList const &lst2 = dir2.entryInfoList(nameFilters, QDir::Files, QDir::Name);
QStringList fileNameLst1{};
QStringList fileNameLst2{};
QListIterator<QFileInfo> i1(lst1);
while (i1.hasNext()) {
fileNameLst1 << i1.next().fileName();
}
QListIterator<QFileInfo> i2(lst2);
while (i2.hasNext()) {
fileNameLst2 << i2.next().fileName();
}
if (fileNameLst1.isEmpty()) {
qCritical() << "DIR1" << dir1.dirName() << " DOES NOT CONTAIN EXPECTED FILES";
return false;
}
if (fileNameLst2.isEmpty()) {
qCritical() << "DIR1" << dir2.dirName() << " DOES NOT CONTAIN EXPECTED FILES";
return false;
}
if (fileNameLst1 != fileNameLst2) {
printCriticalErrorMsg(dir1.dirName() + " AND " + dir2.dirName()
+ " DIFFER: [" + fileNameLst1.join(',') + "],["
+ fileNameLst2.join(',') + "]");
return false;
} else {
printInfoMsg(dir1.dirName() + " AND " + dir2.dirName()
+ " ARE EQUAL: [" + fileNameLst1.join(',') + "]");
}
QStringList gitBlobLst1{};
QStringList gitBlobLst2{};
QListIterator<QFileInfo> i3(lst1);
while (i3.hasNext()) {
gitBlobLst1 << GitClient::gitBlob(i3.next().fileName());
}
QListIterator<QFileInfo> i4(lst2);
while (i4.hasNext()) {
gitBlobLst2 << GitClient::gitBlob(i4.next().fileName());
}
if (gitBlobLst1.isEmpty()) {
qCritical() << "DIR1" << dir1.dirName() << " DOES NOT CONTAIN EXPECTED FILES";
return false;
}
if (gitBlobLst2.isEmpty()) {
qCritical() << "DIR1" << dir2.dirName() << " DOES NOT CONTAIN EXPECTED FILES";
return false;
}
if (gitBlobLst1 != gitBlobLst2) {
printCriticalErrorMsg(dir1.dirName() + " AND " + dir2.dirName()
+ " DIFFER: [" + gitBlobLst1.join(',') + "],["
+ gitBlobLst2.join(',') + "]");
return false;
} else {
printInfoMsg(dir1.dirName() + " AND " + dir2.dirName()
+ " CONTAIN SAME GIT-BLOBS FOR FILES: [" + fileNameLst1.join(',') + "]");
}
return true;
}

View File

@ -7,6 +7,7 @@
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QDateTime> #include <QDateTime>
#include <QDir>
namespace Utils { namespace Utils {
int read1stLineOfFile(QString fileName); int read1stLineOfFile(QString fileName);
@ -16,6 +17,8 @@ namespace Utils {
void printLineEditInfo(QStringList const &lines); void printLineEditInfo(QStringList const &lines);
QString getTariffLoadTime(QString fileName); QString getTariffLoadTime(QString fileName);
QString rstrip(QString const &str); QString rstrip(QString const &str);
bool sameFilesInDirs(QDir const &dir1, QDir const &dir2,
QStringList const &nameFilters = {"*.json"});
} }
#endif // UTILS_H_INCLUDED #endif // UTILS_H_INCLUDED

View File

@ -1001,9 +1001,16 @@ bool Worker::syncCustomerRepositoryAndFS() {
progress += 5; progress += 5;
setProgress(progress); setProgress(progress);
if (!error) { if (!error) {
setProgress(100); // now check tariff-files in etc and /etc/psa_tariff
emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_DONE); QDir dir1(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/psa_tariff"));
return true; QDir dir2("/etc/psa_tariff");
if (Utils::sameFilesInDirs(dir1, dir2)) {
setProgress(100);
emit replaceLast(QString("Sync customer environment with filesystem ..."), UPDATE_STEP_DONE);
return true;
} else {
// TODO: send message to ISMAS
}
} }
} }
} }