From 61c847102d09fd4af8a56384bcc0377bc7061c1e Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 29 Jun 2023 12:42:16 +0200 Subject: [PATCH] Open/empty update_log.csv/.csv.copy at start. Added some debug-output --- update.cpp | 52 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/update.cpp b/update.cpp index 1fe145e..6557ce8 100644 --- a/update.cpp +++ b/update.cpp @@ -92,31 +92,55 @@ Update::Update(hwinf *hw, , m_maintenanceMode(maintenanceMode) , m_init(true) { - execUpdateScript(); - - if (!m_update_ctrl_file.exists()) { + // make sure the files are empty + if (m_update_ctrl_file.exists()) { + if (m_update_ctrl_file.open(QIODevice::ReadWrite | + QIODevice::Truncate | + QIODevice::Text)) { + m_update_ctrl_file.close(); + } + } else { qCritical() << "Update-file" << m_update_ctrl_file.fileName() << "does not exist"; m_init = false; } - if (!m_update_ctrl_file_copy.exists()) { + if (m_update_ctrl_file_copy.exists()) { + if (m_update_ctrl_file_copy.open(QIODevice::ReadWrite | + QIODevice::Truncate | + QIODevice::Text)) { + m_update_ctrl_file_copy.close(); + } + } else { qCritical() << "Update-file-copy" << m_update_ctrl_file_copy.fileName() << "does not exist"; m_init = false; } - if (!m_update_ctrl_file.open(QIODevice::ReadWrite | QIODevice::Text)) { - qCritical() << "can not open " << m_update_ctrl_file.fileName(); - m_init = false; + + // execute update_psa-script + if (m_init) { + if ((m_init = execUpdateScript()) == false) { + qCritical() << "UPDATE_SCRIPT FAILED"; + } else { + if (!m_update_ctrl_file.open(QIODevice::ReadWrite | QIODevice::Text)) { + qCritical() << "CAN NOT OPEN" << m_update_ctrl_file.fileName(); + m_init = false; + } else { + qDebug() << "OPENED" << m_update_ctrl_file.fileName(); + } + if (!m_update_ctrl_file_copy.open(QIODevice::ReadWrite | QIODevice::Text)) { + qCritical() << "CAN NOT OPEN" << m_update_ctrl_file_copy.fileName(); + m_init = false; + } else { + qDebug() << "OPENED" << m_update_ctrl_file_copy.fileName(); + } + } } - qDebug() << "Opened" << m_update_ctrl_file.fileName(); - if (!m_update_ctrl_file_copy.open(QIODevice::ReadWrite | QIODevice::Text)) { - qCritical() << "can not open " << m_update_ctrl_file_copy.fileName(); - m_init = false; - } - qDebug() << "Opened" << m_update_ctrl_file_copy.fileName(); } Update::~Update() { + // make sure the files are closed + m_update_ctrl_file.close(); + m_update_ctrl_file_copy.close(); } bool Update::execUpdateScript() { @@ -602,6 +626,7 @@ bool Update::doUpdate() { */ if (!m_init) { + qCritical() << "DO UPDATE: INITIALIZATION OR UPDATE-SCRIPT FAILED"; return false; } @@ -612,6 +637,7 @@ bool Update::doUpdate() { qCritical() << "No lines to handle in" << m_update_ctrl_file.fileName(); return true; } + qDebug() << "open lines..."; for (int i=0; i< linesToWorkOn.size(); ++i) { qDebug() << "line" << i << ":" << linesToWorkOn.at(i).trimmed();