From 7df1ddf89143edb2af1f006a4637c1cdf7c5a626 Mon Sep 17 00:00:00 2001 From: Albert S Date: Fri, 26 Apr 2019 22:46:33 +0200 Subject: [PATCH] FileSaver: count how many files failed, Commands: Show how many failed --- cli/commandadd.cpp | 7 +++++-- cli/commandupdate.cpp | 7 +++++-- cli/filesaver.cpp | 14 +++++++------- cli/filesaver.h | 8 ++++---- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/cli/commandadd.cpp b/cli/commandadd.cpp index c737a1a..d9c66e1 100644 --- a/cli/commandadd.cpp +++ b/cli/commandadd.cpp @@ -51,9 +51,12 @@ int CommandAdd::handle(QStringList arguments) } FileSaver saver(*this->dbService); - if(!saver.addFiles(files.toVector(), keepGoing, verbose)) + int numFilesCount = files.size(); + int processedFilesCount = saver.addFiles(files.toVector(), keepGoing, verbose); + if(processedFilesCount != numFilesCount) { - Logger::error() << "Errors occured while trying to add files to the database" << endl; + Logger::error() << "Errors occured while trying to add files to the database. Processed " << processedFilesCount + << "out of" << numFilesCount << "files" << endl; return 1; } diff --git a/cli/commandupdate.cpp b/cli/commandupdate.cpp index c12c213..ec54162 100644 --- a/cli/commandupdate.cpp +++ b/cli/commandupdate.cpp @@ -93,11 +93,14 @@ int CommandUpdate::handle(QStringList arguments) } } - if(!saver.updateFiles(filePathsToUpdate, keepGoing, verbose)) + int updatedFilesCount = saver.updateFiles(filePathsToUpdate, keepGoing, verbose); + int shouldHaveUpdatedCount = filePathsToUpdate.size(); + if(updatedFilesCount != shouldHaveUpdatedCount) { if(!keepGoing) { - Logger::error() << "Failed to update all files selected for updating" << endl; + Logger::error() << "Failed to update all files selected for updating. Updated" << updatedFilesCount + << "out of" << shouldHaveUpdatedCount << "selected for upating" << endl; return 1; } } diff --git a/cli/filesaver.cpp b/cli/filesaver.cpp index 0cae894..bdfa59b 100644 --- a/cli/filesaver.cpp +++ b/cli/filesaver.cpp @@ -49,21 +49,21 @@ SaveFileResult FileSaver::updateFile(QString path) return saveFile(info); } -bool FileSaver::addFiles(const QVector paths, bool keepGoing, bool verbose) +int FileSaver::addFiles(const QVector paths, bool keepGoing, bool verbose) { return processFiles(paths, std::bind(&FileSaver::addFile, this, std::placeholders::_1), keepGoing, verbose); } -bool FileSaver::updateFiles(const QVector paths, bool keepGoing, bool verbose) +int FileSaver::updateFiles(const QVector paths, bool keepGoing, bool verbose) { return processFiles(paths, std::bind(&FileSaver::updateFile, this, std::placeholders::_1), keepGoing, verbose); } -bool FileSaver::processFiles(const QVector paths, std::function saverFunc, - bool keepGoing, bool verbose) +int FileSaver::processFiles(const QVector paths, std::function saverFunc, + bool keepGoing, bool verbose) { std::atomic terminate{false}; - std::atomic hasError{false}; + std::atomic errorsCount{0}; QtConcurrent::blockingMap(paths, [&](const QString &path) { @@ -78,7 +78,7 @@ bool FileSaver::processFiles(const QVector paths, std::function paths, std::function paths, std::function saverFunc, - bool keepGoing, bool verbose); - bool addFiles(const QVector paths, bool keepGoing, bool verbose); - bool updateFiles(const QVector paths, bool keepGoing, bool verbose); + int processFiles(const QVector paths, std::function saverFunc, + bool keepGoing, bool verbose); + int addFiles(const QVector paths, bool keepGoing, bool verbose); + int updateFiles(const QVector paths, bool keepGoing, bool verbose); ; };