Be more defensive when calling boost::filesystem::last_write_time.
authorCarl Hetherington <cth@carlh.net>
Sun, 7 Feb 2021 21:31:43 +0000 (22:31 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 7 Feb 2021 21:31:43 +0000 (22:31 +0100)
src/lib/content.cc
src/lib/types.cc

index 0171563ae5d041d1fb9ee97812bd17e8b2c2bf6f..1682b863d8d5ac3154f9a0a0b523042922775bff 100644 (file)
@@ -96,10 +96,10 @@ Content::Content (cxml::ConstNodePtr node)
                auto const mod = i->optional_number_attribute<time_t>("mtime");
                if (mod) {
                        _last_write_times.push_back (*mod);
-               } else if (boost::filesystem::exists(i->content())) {
-                       _last_write_times.push_back (boost::filesystem::last_write_time(i->content()));
                } else {
-                       _last_write_times.push_back (0);
+                       boost::system::error_code ec;
+                       auto last_write = boost::filesystem::last_write_time(i->content(), ec);
+                       _last_write_times.push_back (ec ? 0 : last_write);
                }
        }
        _digest = node->optional_string_child ("Digest").get_value_or ("X");
@@ -192,7 +192,9 @@ Content::examine (shared_ptr<const Film>, shared_ptr<Job> job)
 
        _last_write_times.clear ();
        for (auto i: _paths) {
-               _last_write_times.push_back (boost::filesystem::last_write_time(i));
+               boost::system::error_code ec;
+               auto last_write = boost::filesystem::last_write_time(i, ec);
+               _last_write_times.push_back (ec ? 0 : last_write);
        }
 }
 
@@ -345,7 +347,9 @@ Content::set_paths (vector<boost::filesystem::path> paths)
                _paths = paths;
                _last_write_times.clear ();
                for (auto i: _paths) {
-                       _last_write_times.push_back (boost::filesystem::last_write_time(i));
+                       boost::system::error_code ec;
+                       auto last_write = boost::filesystem::last_write_time(i, ec);
+                       _last_write_times.push_back (ec ? 0 : last_write);
                }
        }
 }
@@ -508,5 +512,7 @@ Content::add_path (boost::filesystem::path p)
 {
        boost::mutex::scoped_lock lm (_mutex);
        _paths.push_back (p);
-       _last_write_times.push_back (boost::filesystem::last_write_time(p));
+       boost::system::error_code ec;
+       auto last_write = boost::filesystem::last_write_time(p, ec);
+       _last_write_times.push_back (ec ? 0 : last_write);
 }
index 3586cdb935b67bc065a55a99592611967eb13706..b7632a9842a07afb6315b63ca64aef0699893f3d 100644 (file)
@@ -220,7 +220,9 @@ CPLSummary::CPLSummary (boost::filesystem::path p)
                }
        }
 
-       last_write_time = boost::filesystem::last_write_time (p);
+       boost::system::error_code ec;
+       auto last_write = boost::filesystem::last_write_time (p, ec);
+       last_write_time = ec ? 0 : last_write;
 }