From b2d850326af5c9ffc6486e4cc40bef6e1c051a6f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 27 Nov 2021 01:04:37 +0100 Subject: [PATCH] Extract part of the content change job to Content. --- src/lib/check_content_change_job.cc | 20 +++----------------- src/lib/content.cc | 15 +++++++++++++++ src/lib/content.h | 3 +++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/lib/check_content_change_job.cc b/src/lib/check_content_change_job.cc index 216cf3e51..9400406bc 100644 --- a/src/lib/check_content_change_job.cc +++ b/src/lib/check_content_change_job.cc @@ -67,23 +67,9 @@ CheckContentChangeJob::run () { set_progress_unknown (); - list> changed; - - for (auto i: _film->content()) { - bool ic = false; - for (size_t j = 0; j < i->number_of_paths(); ++j) { - if (boost::filesystem::last_write_time(i->path(j)) != i->last_write_time(j)) { - ic = true; - break; - } - } - if (!ic && i->calculate_digest() != i->digest()) { - ic = true; - } - if (ic) { - changed.push_back (i); - } - } + auto content = _film->content(); + std::vector> changed; + std::copy_if (content.begin(), content.end(), std::back_inserter(changed), [](shared_ptr c) { return c->changed(); }); if (!changed.empty()) { if (_gui) { diff --git a/src/lib/content.cc b/src/lib/content.cc index 064bae553..a56891689 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -543,3 +543,18 @@ Content::add_path (boost::filesystem::path p) auto last_write = boost::filesystem::last_write_time(p, ec); _last_write_times.push_back (ec ? 0 : last_write); } + + +bool +Content::changed () const +{ + bool write_time_changed = false; + for (auto i = 0U; i < _paths.size(); ++i) { + if (boost::filesystem::last_write_time(_paths[i]) != last_write_time(i)) { + write_time_changed = true; + break; + } + } + + return (write_time_changed || calculate_digest() != digest()); +} diff --git a/src/lib/content.h b/src/lib/content.h index 550b3cd9c..d17b0d0e5 100644 --- a/src/lib/content.h +++ b/src/lib/content.h @@ -202,6 +202,9 @@ public: std::shared_ptr only_text () const; std::shared_ptr text_of_original_type (TextType type) const; + /** @return true if this content has changed since it was last examined */ + bool changed () const; + protected: virtual void add_properties (std::shared_ptr film, std::list &) const; -- 2.30.2