From 55727ad7129b904a1164634653096e16f55e14e2 Mon Sep 17 00:00:00 2001 From: hama Date: Tue, 19 Apr 2016 22:06:37 +0100 Subject: [PATCH] ignoring more than 200 errors --- appl/rebackgui/BackupEngine.cpp | 14 ++++++- appl/rebackgui/main.cpp | 1 + appl/rebackgui/mainwindow.cpp | 71 +++++++++++++++++++++++++++++++-- appl/rebackgui/mainwindow.hpp | 6 +++ appl/rebackgui/mainwindow.ui | 11 ++++- base/ReFileUtils.cpp | 7 +++- base/ReFileUtils.hpp | 1 + gui/ReGuiQueue.hpp | 16 ++++++++ 8 files changed, 119 insertions(+), 8 deletions(-) diff --git a/appl/rebackgui/BackupEngine.cpp b/appl/rebackgui/BackupEngine.cpp index f723be5..eb4f80f 100644 --- a/appl/rebackgui/BackupEngine.cpp +++ b/appl/rebackgui/BackupEngine.cpp @@ -231,6 +231,9 @@ void BackupTask::run() else relPath = info.mid(1, pos - 1); node = info.mid(pos + 1); + if (m_searchReady){ + m_mainWindow->setLastFile(relPath, node); + } copyFile(index, relPath, node); if (m_verboseLevel > VerboseQuiet){ qint64 duration = QDateTime::currentMSecsSinceEpoch() - start.toMSecsSinceEpoch(); @@ -421,6 +424,9 @@ void ChecksumOfTargetTask::run() node = info.mid(pos + 1, pos2 - pos - 1); QString sourceChecksum = info.mid(pos2 + 1); + if (m_searchReady){ + m_mainWindow->setLastFile(relPath, node); + } QByteArray checksum = buildChecksum(false, index, relPath, node); count++; if (! checksum.isEmpty()){ @@ -486,7 +492,7 @@ void CleanTask::run() QString relPath, node; QString info; QDateTime start = QDateTime::currentDateTime(); - int processedFiles, hotFiles; + int processedFiles = 0, hotFiles = 0; while (! m_shouldStop){ m_mutex.lock(); if (m_files.size() == 0) @@ -514,6 +520,8 @@ void CleanTask::run() relPath = info.mid(1, pos - 1); Command command = (Command) info.at(pos + 1).unicode(); node = info.mid(pos + 2); + if (m_searchReady) + m_mainWindow->setLastFile(relPath, node); switch(command){ case CmdRemove: if (_unlink(I18N::s2b(relPath)) != 0){ @@ -651,6 +659,7 @@ void SearchTask::run() void SearchTask::searchOneDirectory(const QString& source, const QString& target, int index){ QDirIterator it(source); + m_mainWindow->setLastDirectory(source); QString info, node; int lengthBase = m_sourceDirs.at(index).length(); assert(index < MAX_INDEX); @@ -673,6 +682,7 @@ void SearchTask::searchOneDirectory(const QString& source, } it.next(); node = it.fileName(); + m_mainWindow->setLastFile(node); FILETRACE_IT(s_traceSearch, (s_traceSearch.m_fp, "?%s\n", node.toLocal8Bit().constData())); QFileInfo fileInfo = it.fileInfo(); @@ -857,12 +867,14 @@ void SearchTargetTask::searchOneDirectory(const QString& target, } else { prefix = QChar(1 + index) + m_separatorString; } + m_mainWindow->setLastDirectory(source); while (it.hasNext()){ if (m_shouldStop){ break; } it.next(); node = it.fileName(); + m_mainWindow->setLastFile(node); QFileInfo fileInfo = it.fileInfo(); if (! fileInfo.isSymLink() && fileInfo.isDir()){ // nothing to do diff --git a/appl/rebackgui/main.cpp b/appl/rebackgui/main.cpp index 2c2fcde..4d9b8a2 100644 --- a/appl/rebackgui/main.cpp +++ b/appl/rebackgui/main.cpp @@ -16,6 +16,7 @@ char** g_argv; int main(int argc, char* argv[]) { g_argv = argv; + ReFileUtils::m_ignoreSetUidError = true; QString homeDir = argc > 1 ? argv[1] : ""; QApplication::setSetuidAllowed(true); QApplication a(argc, argv); diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index 8489f9c..2050c66 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -37,7 +37,11 @@ MainWindow::MainWindow(QApplication& application, const QString& homeDir, m_searchTargetTask(NULL), m_cleanTask(NULL), m_errors(0), - m_maxListSize(1000) + m_maxListSize(100), + m_mutexLastFile(), + m_lastFile(""), + m_lastDirectory("") + { initializeGui(); } @@ -134,7 +138,10 @@ void MainWindow::onGuiTimerUpdate() switch(item.m_type){ case ReGuiQueueItem::ListEnd: case ReGuiQueueItem::ListAppendToCurrent: - maxItems = m_maxListSize * 2; + maxItems = m_maxListSize; + break; + case ReGuiQueueItem::LogError: + maxItems = max(100, m_maxListSize); break; default: break; @@ -153,7 +160,8 @@ void MainWindow::onGuiTimerUpdate() say(LOG_INFO, item.m_value); break; case ReGuiQueueItem::LogError: - say(LOG_ERROR, item.m_value); + if (m_guiQueue.countOfType(ReGuiQueueItem::LogError) <= maxItems) + say(LOG_ERROR, item.m_value); break; case ReGuiQueueItem::StatusLine: if (++countStatusMessage % 200 != 0) @@ -177,6 +185,9 @@ void MainWindow::onGuiTimerUpdate() item.apply(m_guiQueue, 0); item.m_type = ReGuiQueueItem::Undef; } + m_mutexLastFile.lock(); + ui->labelLastFile->setText(m_lastDirectory + m_lastFile); + m_mutexLastFile.unlock(); if (!statusMessage.isEmpty()) setStatusMessage(LOG_INFO, statusMessage); @@ -380,6 +391,7 @@ void MainWindow::onAutosaveToggled(bool newState){ * Starts the backup. */ void MainWindow::onChecksums(){ + setLastFile("", ""); int row = ui->tableWidget->currentRow(); if (row < 0){ say(LOG_ERROR, tr("no backup item selected")); @@ -414,6 +426,7 @@ void MainWindow::onChecksums(){ */ void MainWindow::onClean() { + setLastFile("", ""); int row = ui->tableWidget->currentRow(); if (row < 0){ say(LOG_ERROR, tr("no backup item selected")); @@ -607,6 +620,7 @@ void MainWindow::onSelectTarget(){ * Starts the backup. */ void MainWindow::onStart(){ + setLastFile("", ""); int row = ui->tableWidget->currentRow(); if (row < 0){ say(LOG_ERROR, tr("no backup item selected")); @@ -636,6 +650,11 @@ void MainWindow::onStart(){ */ void MainWindow::onStop(){ BackupEngine::m_shouldStop = true; + QString message = tr("Aborted by the user"); + m_mutexGuiQueue.lock(); + m_guiQueue.clear(); + m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ReadyMessage, NULL, message)); + m_mutexGuiQueue.unlock(); } /** @@ -725,6 +744,9 @@ void MainWindow::startStop(bool isStart){ ui->actionClean->setEnabled(! isStart); if (isStart) BackupEngine::m_verboseLevel = (ReVerbose_t) ui->comboBoxVerbose->currentIndex(); + if (! isStart) + setStatusMessage(LOG_INFO, ""); + } /** @@ -747,6 +769,49 @@ void MainWindow::onUpdateConfig(){ } } +/** + * Set the last processed file. + * + * Note: thread safe + * + * @param lastFile the last processed file + */ +void MainWindow::setLastDirectory(const QString& lastDirectory) +{ + m_mutexLastFile.lock(); + m_lastDirectory = lastDirectory; + m_mutexLastFile.unlock(); +} + +/** + * Set the last processed file. + * + * Note: thread safe + * + * @param lastFile the last processed file + */ +void MainWindow::setLastFile(const QString& lastFile) +{ + m_mutexLastFile.lock(); + m_lastFile = lastFile; + m_mutexLastFile.unlock(); +} + +/** + * Set the last processed file. + * + * Note: thread safe + * + * @param lastFile the last processed file + */ +void MainWindow::setLastFile(const QString& lastDir, const QString& lastFile) +{ + m_mutexLastFile.lock(); + m_lastFile = lastFile; + m_lastDirectory = lastDir; + m_mutexLastFile.unlock(); +} + /** * Shows the data of a given backup item in the gui elements. * diff --git a/appl/rebackgui/mainwindow.hpp b/appl/rebackgui/mainwindow.hpp index 6883a4b..0b16df3 100644 --- a/appl/rebackgui/mainwindow.hpp +++ b/appl/rebackgui/mainwindow.hpp @@ -34,6 +34,9 @@ public: virtual bool say(ReLoggerLevel level, const QString& message); void startStop(bool isStart); void restoreState(); + void setLastDirectory(const QString& lastFile); + void setLastFile(const QString& lastFile); + void setLastFile(const QString& lastDir, const QString& lastFile); void saveState(); protected slots: private: @@ -88,6 +91,9 @@ private: CleanTask* m_cleanTask; int m_errors; int m_maxListSize; + QMutex m_mutexLastFile; + QString m_lastFile; + QString m_lastDirectory; }; #endif // MAINWINDOW_HPP diff --git a/appl/rebackgui/mainwindow.ui b/appl/rebackgui/mainwindow.ui index 8fb4ae9..4beba49 100644 --- a/appl/rebackgui/mainwindow.ui +++ b/appl/rebackgui/mainwindow.ui @@ -170,7 +170,7 @@ Verbose level - 2 + 1 @@ -777,6 +777,13 @@ + + + + + + + @@ -785,7 +792,7 @@ 0 0 839 - 29 + 31 diff --git a/base/ReFileUtils.cpp b/base/ReFileUtils.cpp index 6f9b56f..f52fe2c 100644 --- a/base/ReFileUtils.cpp +++ b/base/ReFileUtils.cpp @@ -22,6 +22,7 @@ enum { LOC_SET_TIMES_2, // 12507 }; int ReFileUtils::m_maxCharSet = 128; +bool ReFileUtils::m_ignoreSetUidError = false; QDateTime ReFileUtils::m_undefinedTime; @@ -248,8 +249,10 @@ QString ReFileUtils::copy(const QString& source, const QString& target, #ifdef __linux__ if (setUser){ if (chown(target2.constData(), sourceInfo->ownerId(), - sourceInfo->groupId()) != 0 && rc.isEmpty()){ - rc = QObject::tr("cannot set user/gid (%1): %2") + sourceInfo->groupId()) != 0 + && ! m_ignoreSetUidError && rc.isEmpty()){ + rc = QObject::tr("cannot set user/gid [%1/%2] (%3): %4") + .arg(sourceInfo->ownerId()).arg(sourceInfo->groupId()) .arg(errno).arg(target); } } diff --git a/base/ReFileUtils.hpp b/base/ReFileUtils.hpp index 3c8a7b1..94dc5ea 100644 --- a/base/ReFileUtils.hpp +++ b/base/ReFileUtils.hpp @@ -125,6 +125,7 @@ public: static QDateTime m_undefinedTime; /// see modifyToNonExisting() static int m_maxCharSet; + static bool m_ignoreSetUidError; }; #endif // REFILEUTILS_HPP diff --git a/gui/ReGuiQueue.hpp b/gui/ReGuiQueue.hpp index 4af30aa..a5c0c7c 100644 --- a/gui/ReGuiQueue.hpp +++ b/gui/ReGuiQueue.hpp @@ -83,9 +83,25 @@ public: int count() const; ReGuiQueueItem popFront(); void pushBack(const ReGuiQueueItem& item); + /** + * Delete all elements. + */ + inline void clear(){ + QList::clear(); + } + /** + * Returns the count of items with a given type + * @param type the type to search + * @return the count of items with a given type + */ inline int countOfType(ReGuiQueueItem::WidgetType type) const { return m_countOfType[type]; } + /** + * Returns the last of the items with a given type read from the queue. + * @param type the type to search + * @return the last of the items with a given type read from the queue + */ inline ReGuiQueueItem& lastOfType(ReGuiQueueItem::WidgetType type){ return m_lastOfType[type]; } -- 2.39.5