Update process: check sanity of customer repository: are etc/ and

opt/directories contained? If not, remove the repository and clone it
again. This is done without checking the ISMAS-WAIT-button.
This commit is contained in:
Gerhard Hoffmann 2023-10-19 13:41:44 +02:00
parent 4469a23f9c
commit 4bb8e241b6

View File

@ -237,150 +237,184 @@ void Worker::privateUpdate() {
emit disableExit();
m_returnCode = -1;
QDir customerRepository(m_customerRepository);
if (!customerRepository.exists()) {
emit appendText("\nInitializing customer environment ...");
startProgressLoop();
if (m_gc.gitCloneAndCheckoutBranch()) {
stopProgressLoop();
emit replaceLast("Initializing customer environment", UPDATE_STEP_DONE);
QDir customerRepositoryEtc(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/"));
setProgress(5);
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 1: CHECK SANITY OF CUSTOMER REPOSITORY %1...")
.arg(m_customerRepository));
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_SUCCESS,
QString("CLONED AND CHECKED OUT: ") + m_customerRepository);
bool initialClone = false; // the customer repository is cloned without
// checking the ISMAS-trigger (WAIT-)button.
// but if there was a sane repository
// available, then the trigger-button must
// have been activated in ISMAS.
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.cloneAndCheckoutCustomerRepository(
m_updateStatus.m_statusDescription));
setProgress(10);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
setProgress(100);
m_ismasClient.setProgressInPercent(100);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
bool continueUpdate = true; // check if git-clone command has timed-out,
// resulting in a corrupted git-repository, which
// does not contain an ./etc-directory
if (isRepositoryCorrupted()) {
QString s("CORRUPTED CUSTOMER REPOSITORY. REPAIRING...");
if ((continueUpdate = repairCorruptedRepository()) == true) {
Utils::printUpdateStatusMsg(
QStringList() << s <<
QString("CORRUPTED CUSTOMER REPOSITORY. REPAIRING...DONE"));
} else {
stopProgressLoop();
setProgress(0);
emit replaceLast("Initializing customer environment", UPDATE_STEP_FAIL);
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_FAILURE,
QString("CLONE OR CHECKOUT FAILED: ") + m_customerRepository);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.errorGitClone(100, m_updateStatus.m_statusDescription));
m_returnCode = -3;
Utils::printUpdateStatusMsg(
QStringList() << s <<
QString("CORRUPTED CUSTOMER REPOSITORY. REPAIRING...FAIL"));
}
} else {
if (updateTriggerSet(5)) {
if (customerEnvironment(30)) {
m_ismasClient.setProgressInPercent(50);
if (filesToUpdate()) {
// send message to ISMAS about files which have been
// checked in into git repository
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS,
QString("Files to update: ") + m_filesToUpdate.join(','));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAContinues("CHECK-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
if (updateFiles(60)) {
m_ismasClient.setProgressInPercent(70);
if (syncCustomerRepositoryAndFS()) {
m_ismasClient.setProgressInPercent(80);
if (sendIsmasLastVersionNotification()) {
m_ismasClient.setProgressInPercent(90);
sentIsmasLastVersionNotification = true;
if (saveLogFile()) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
}
// mark update as activated -> this resets the WAIT button
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated());
if (continueUpdate) {
m_returnCode = 0;
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 1: CHECKED SANITY OF CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository)
<< QString("STEP 2: FETCH CUSTOMER REPOSITORY %1...")
.arg(m_customerRepository));
if ((continueUpdate = customerRepository.exists()) == false) {
emit appendText("\nInitializing customer environment ...");
startProgressLoop();
for (int i = 0; i < 5; ++i) { // try to checkout git repository
setProgress(i); // and switch to branch
if (m_gc.gitCloneAndCheckoutBranch()) {
if (!isRepositoryCorrupted()) {
emit replaceLast("Initializing customer environment", UPDATE_STEP_DONE);
m_returnCode = sendCloneAndCheckoutSuccess();
continueUpdate = true;
initialClone = true;
Utils::printInfoMsg("INITIAL CLONE DONE");
break;
}
}
QThread::sleep(1); // maybe git needs more time
}
if (continueUpdate == false) {
emit replaceLast("Initializing customer environment", UPDATE_STEP_FAIL);
m_returnCode = sendCloneAndCheckoutFailure();
}
}
}
if (continueUpdate) { // repository is neither not existent nor
// corrupted. check now if the ISMAS-trigger
// (WAIT-BUTTON) is activated even in case of
// initial checkout
if (!initialClone) {
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 2: FETCHED CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository)
<< QString("STEP 3: CHECK ISMAS-UPDATE-TRIGGER FOR WAIT-STATUS..."));
//if ((continueUpdate = updateTriggerSet(10)) == false) {
// m_returnCode = sendIsmasTriggerFailure();
//}
if (updateTriggerSet(10)) {
if (customerEnvironment(30)) {
m_ismasClient.setProgressInPercent(50);
if (filesToUpdate()) {
// send message to ISMAS about files which have been
// checked in into git repository
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS,
QString("Files to update: ") + m_filesToUpdate.join(','));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAContinues("CHECK-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
if (updateFiles(60)) {
m_ismasClient.setProgressInPercent(70);
if (syncCustomerRepositoryAndFS()) {
m_ismasClient.setProgressInPercent(80);
if (sendIsmasLastVersionNotification()) {
m_ismasClient.setProgressInPercent(90);
sentIsmasLastVersionNotification = true;
if (saveLogFile()) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
// mark update as activated -> this resets the WAIT button
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::SAVE_LOG_FILES_FAILED,
QString("Saving log files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"SAVE-LOG-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -11;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::SAVE_LOG_FILES_FAILED,
QString("Saving log files failed"));
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED,
QString("Sending ISMAS last version failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"SAVE-LOG-FILES",
"ISMAS-SEND-LAST-VERSION",
m_updateStatus.m_statusDescription));
m_returnCode = -11;
m_returnCode = -10;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED,
QString("Sending ISMAS last version failed"));
m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_UPDATES_FAILURE,
QString("Syncing files to update failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"ISMAS-SEND-LAST-VERSION",
"RSYNC-UPDATE-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -10;
m_returnCode = -9;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_UPDATES_FAILURE,
QString("Syncing files to update failed"));
m_updateStatus = UpdateStatus(UPDATE_STATUS::PSA_UPDATE_FILES_FAILED,
QString("Updating files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"RSYNC-UPDATE-FILES",
"UPDATE-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -9;
m_returnCode = -8;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::PSA_UPDATE_FILES_FAILED,
QString("Updating files failed"));
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE,
QString("No files to update"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"UPDATE-FILES",
"FETCH-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
m_returnCode = -8;
m_returnCode = -7;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE,
QString("No files to update"));
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE,
QString("Configuring customer environment failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"FETCH-FILES-TO-UPDATE",
"GIT-CHECKOUT-BRANCH",
m_updateStatus.m_statusDescription));
m_returnCode = -7;
m_returnCode = -6;
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE,
QString("Configuring customer environment failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"GIT-CHECKOUT-BRANCH",
m_updateStatus.m_statusDescription));
m_returnCode = -6;
m_returnCode = sendIsmasTriggerFailure();
}
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET_FAILURE,
QString("ISMAS update trigger wrong"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"CHECK-UPDATE-TRIGGER",
m_updateStatus.m_statusDescription));
m_returnCode = -5;
} else { // initialClone
Utils::printUpdateStatusMsg(
QString("STEP 2: FETCHED CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository));
}
}