FileSaver: count how many files failed, Commands: Show how many failed
This commit is contained in:
parent
098cd96dd2
commit
7df1ddf891
@ -51,9 +51,12 @@ int CommandAdd::handle(QStringList arguments)
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileSaver saver(*this->dbService);
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,21 +49,21 @@ SaveFileResult FileSaver::updateFile(QString path)
|
|||||||
return saveFile(info);
|
return saveFile(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileSaver::addFiles(const QVector<QString> paths, bool keepGoing, bool verbose)
|
int FileSaver::addFiles(const QVector<QString> paths, bool keepGoing, bool verbose)
|
||||||
{
|
{
|
||||||
return processFiles(paths, std::bind(&FileSaver::addFile, this, std::placeholders::_1), keepGoing, verbose);
|
return processFiles(paths, std::bind(&FileSaver::addFile, this, std::placeholders::_1), keepGoing, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileSaver::updateFiles(const QVector<QString> paths, bool keepGoing, bool verbose)
|
int FileSaver::updateFiles(const QVector<QString> paths, bool keepGoing, bool verbose)
|
||||||
{
|
{
|
||||||
return processFiles(paths, std::bind(&FileSaver::updateFile, this, std::placeholders::_1), keepGoing, verbose);
|
return processFiles(paths, std::bind(&FileSaver::updateFile, this, std::placeholders::_1), keepGoing, verbose);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileSaver::processFiles(const QVector<QString> paths, std::function<SaveFileResult(QString path)> saverFunc,
|
int FileSaver::processFiles(const QVector<QString> paths, std::function<SaveFileResult(QString path)> saverFunc,
|
||||||
bool keepGoing, bool verbose)
|
bool keepGoing, bool verbose)
|
||||||
{
|
{
|
||||||
std::atomic<bool> terminate{false};
|
std::atomic<bool> terminate{false};
|
||||||
std::atomic<bool> hasError{false};
|
std::atomic<int> errorsCount{0};
|
||||||
QtConcurrent::blockingMap(paths,
|
QtConcurrent::blockingMap(paths,
|
||||||
[&](const QString &path)
|
[&](const QString &path)
|
||||||
{
|
{
|
||||||
@ -78,7 +78,7 @@ bool FileSaver::processFiles(const QVector<QString> paths, std::function<SaveFil
|
|||||||
SaveFileResult result = saverFunc(path);
|
SaveFileResult result = saverFunc(path);
|
||||||
if(result == DBFAIL || result == PROCESSFAIL)
|
if(result == DBFAIL || result == PROCESSFAIL)
|
||||||
{
|
{
|
||||||
hasError = true;
|
errorsCount++;
|
||||||
Logger::error() << "Failed to process " << path << endl;
|
Logger::error() << "Failed to process " << path << endl;
|
||||||
if(!keepGoing)
|
if(!keepGoing)
|
||||||
{
|
{
|
||||||
@ -98,7 +98,7 @@ bool FileSaver::processFiles(const QVector<QString> paths, std::function<SaveFil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return !hasError.load();
|
return paths.size() - errorsCount.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
SaveFileResult FileSaver::saveFile(const QFileInfo &fileInfo)
|
||||||
|
@ -19,10 +19,10 @@ class FileSaver
|
|||||||
public:
|
public:
|
||||||
FileSaver(SqliteDbService &dbService);
|
FileSaver(SqliteDbService &dbService);
|
||||||
SaveFileResult saveFile(const QFileInfo &fileInfo);
|
SaveFileResult saveFile(const QFileInfo &fileInfo);
|
||||||
bool processFiles(const QVector<QString> paths, std::function<SaveFileResult(QString path)> saverFunc,
|
int processFiles(const QVector<QString> paths, std::function<SaveFileResult(QString path)> saverFunc,
|
||||||
bool keepGoing, bool verbose);
|
bool keepGoing, bool verbose);
|
||||||
bool addFiles(const QVector<QString> paths, bool keepGoing, bool verbose);
|
int addFiles(const QVector<QString> paths, bool keepGoing, bool verbose);
|
||||||
bool updateFiles(const QVector<QString> paths, bool keepGoing, bool verbose);
|
int updateFiles(const QVector<QString> paths, bool keepGoing, bool verbose);
|
||||||
|
|
||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user