Extract part of the content change job to Content.
authorCarl Hetherington <cth@carlh.net>
Sat, 27 Nov 2021 00:04:37 +0000 (01:04 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 28 Nov 2021 20:08:08 +0000 (21:08 +0100)
src/lib/check_content_change_job.cc
src/lib/content.cc
src/lib/content.h

index 216cf3e51cf6ae8a809666c25a800369df5b0484..9400406bc07287a04a28b97d44d0a9501d6affe6 100644 (file)
@@ -67,23 +67,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) {
index 064bae553a4511cd7c2c52d07312e486b0f47b7c..a56891689c201f2d23e1f8eec6c20ae2d3c4e788 100644 (file)
@@ -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());
+}
index 550b3cd9cf52770e7a9acb7786a86dac3829130d..d17b0d0e5a22f86360e8a678073add3a620f9084 100644 (file)
@@ -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;