diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-11-27 01:04:37 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-11-28 21:12:00 +0100 |
| commit | 07b21bb92a8d54c6c03de9aadc63ab93b65d9bc5 (patch) | |
| tree | 5054e3da62eab53c31a01962d982fd1a89112751 /src/lib | |
| parent | 121988b23c485ccb5ac8220c1776d10cb33e0db7 (diff) | |
Extract part of the content change job to Content.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/check_content_change_job.cc | 20 | ||||
| -rw-r--r-- | src/lib/content.cc | 15 | ||||
| -rw-r--r-- | 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 c4d050c0e..967291bb3 100644 --- a/src/lib/check_content_change_job.cc +++ b/src/lib/check_content_change_job.cc @@ -63,23 +63,9 @@ CheckContentChangeJob::run () { set_progress_unknown (); - list<shared_ptr<Content> > 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<shared_ptr<Content>> changed; + std::copy_if (content.begin(), content.end(), std::back_inserter(changed), [](shared_ptr<Content> c) { return c->changed(); }); if (!changed.empty()) { if (_gui) { diff --git a/src/lib/content.cc b/src/lib/content.cc index b6f7ebbaa..370139d12 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -545,3 +545,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<TextContent> only_text () const; std::shared_ptr<TextContent> 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<const Film> film, std::list<UserProperty> &) const; |
