From 106b72bf0ece52b3878448584884f9578cdcbdcb Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 12 Aug 2017 21:33:57 +0100 Subject: [PATCH] Skip mime errors if user passed --ignore-errors. --- include/dindexer-machinery/scantask/mime.hpp | 3 ++- src/machinery/scantask/mime.cpp | 16 +++++++++++----- src/scan/main.cpp | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/dindexer-machinery/scantask/mime.hpp b/include/dindexer-machinery/scantask/mime.hpp index 1bccde7..7065040 100644 --- a/include/dindexer-machinery/scantask/mime.hpp +++ b/include/dindexer-machinery/scantask/mime.hpp @@ -31,7 +31,7 @@ namespace mchlib { public: using DirTreeTaskPtr = std::shared_ptr>>; - explicit Mime ( DirTreeTaskPtr parDirTree ); + Mime (DirTreeTaskPtr parDirTree, bool parIgnoreErrors); virtual ~Mime ( void ) noexcept; private: @@ -39,6 +39,7 @@ namespace mchlib { virtual std::vector& on_data_get ( void ) override; DirTreeTaskPtr m_file_tree_task; + bool m_ignore_errors; }; } //namespace scantask } //namespace mchlib diff --git a/src/machinery/scantask/mime.cpp b/src/machinery/scantask/mime.cpp index 110d0c4..5bd20cf 100644 --- a/src/machinery/scantask/mime.cpp +++ b/src/machinery/scantask/mime.cpp @@ -25,8 +25,9 @@ namespace mchlib { } //unnamed namespace namespace scantask { - Mime::Mime (DirTreeTaskPtr parDirTree) : - m_file_tree_task(parDirTree) + Mime::Mime (DirTreeTaskPtr parDirTree, bool parIgnoreErrors) : + m_file_tree_task(parDirTree), + m_ignore_errors(parIgnoreErrors) { assert(m_file_tree_task); } @@ -39,9 +40,14 @@ namespace mchlib { auto& list = m_file_tree_task->get_or_create(); for (auto& itm : list) { - itm.mime_full = mime.analyze(itm.abs_path); - auto mime_pair = split_mime(itm.mime_full); - itm.set_mime_parts(mime_pair.first, mime_pair.second); + try { + itm.mime_full = mime.analyze(itm.abs_path); + auto mime_pair = split_mime(itm.mime_full); + itm.set_mime_parts(mime_pair.first, mime_pair.second); + } + catch (const std::runtime_error&) { + itm.mime_full = ""; + } } } diff --git a/src/scan/main.cpp b/src/scan/main.cpp index 207feec..36e7bcb 100644 --- a/src/scan/main.cpp +++ b/src/scan/main.cpp @@ -91,7 +91,7 @@ int main (int parArgc, char* parArgv[]) { std::shared_ptr media_type(new stask::MediaType(setbasic, def_media_type, vm.count("type"), search_path)); std::shared_ptr hashing(new stask::Hashing(scan_dirtree, ignore_read_errors)); std::shared_ptr content_type(new stask::ContentType(setbasic, scan_dirtree, media_type)); - std::shared_ptr mime(new stask::Mime(scan_dirtree)); + std::shared_ptr mime(new stask::Mime(scan_dirtree, ignore_read_errors)); std::shared_ptr filerecdata(new FileRecordDataFiller(mime, hashing)); std::shared_ptr setrecdata(new SetRecordDataFiller(media_type, content_type));