summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-03-04 23:24:59 +0100
committerCarl Hetherington <cth@carlh.net>2025-03-05 23:52:14 +0100
commitab766096598188759d29829043bf28e63379b730 (patch)
tree1fb8fb9eb22c275834db2671395e7b3558e7aac4
parent2719964f89431a0598ef617326158309afe5ba43 (diff)
Replace Content::paths_valid() with a free utility function.
-rw-r--r--src/lib/content.cc13
-rw-r--r--src/lib/content.h2
-rw-r--r--src/lib/empty.cc2
-rw-r--r--src/lib/make_dcp.cc2
-rw-r--r--src/lib/player.cc2
-rw-r--r--src/lib/util.cc6
-rw-r--r--src/lib/util.h1
-rw-r--r--src/wx/content_menu.cc2
-rw-r--r--src/wx/content_panel.cc4
-rw-r--r--test/find_missing_test.cc20
-rw-r--r--test/relative_paths_test.cc2
11 files changed, 24 insertions, 32 deletions
diff --git a/src/lib/content.cc b/src/lib/content.cc
index c5f82a375..60073f860 100644
--- a/src/lib/content.cc
+++ b/src/lib/content.cc
@@ -337,19 +337,6 @@ Content::identifier() const
}
-bool
-Content::paths_valid() const
-{
- for (auto i: _paths) {
- if (!dcp::filesystem::exists(i)) {
- return false;
- }
- }
-
- return true;
-}
-
-
void
Content::set_paths(vector<boost::filesystem::path> paths)
{
diff --git a/src/lib/content.h b/src/lib/content.h
index cf24bde00..aca5abea5 100644
--- a/src/lib/content.h
+++ b/src/lib/content.h
@@ -144,8 +144,6 @@ public:
return _last_write_times[i];
}
- bool paths_valid() const;
-
/** @return Digest of the content's file(s). Note: this is
* not a complete MD5-or-whatever hash, but a sort of poor
* man's version (see comments in examine()).
diff --git a/src/lib/empty.cc b/src/lib/empty.cc
index a75066395..7a7833941 100644
--- a/src/lib/empty.cc
+++ b/src/lib/empty.cc
@@ -42,7 +42,7 @@ Empty::Empty (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist,
{
list<DCPTimePeriod> full;
for (auto i: playlist->content()) {
- if (part(i) && i->paths_valid()) {
+ if (part(i) && paths_exist(i->paths())) {
full.push_back(i->period(film));
}
}
diff --git a/src/lib/make_dcp.cc b/src/lib/make_dcp.cc
index b72756194..5fb93a618 100644
--- a/src/lib/make_dcp.cc
+++ b/src/lib/make_dcp.cc
@@ -69,7 +69,7 @@ make_dcp (shared_ptr<Film> film, TranscodeJob::ChangedBehaviour behaviour)
}
for (auto i: film->content()) {
- if (!i->paths_valid()) {
+ if (!paths_exist(i->paths())) {
throw runtime_error (_("Some of your content is missing"));
}
auto dcp = dynamic_pointer_cast<const DCPContent>(i);
diff --git a/src/lib/player.cc b/src/lib/player.cc
index b5ee280ae..fd99e7732 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -283,7 +283,7 @@ Player::setup_pieces()
for (auto content: playlist()->content()) {
- if (!content->paths_valid()) {
+ if (!paths_exist(content->paths())) {
continue;
}
diff --git a/src/lib/util.cc b/src/lib/util.cc
index bcb39c482..df15e1abb 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -1226,3 +1226,9 @@ rfc_2822_date(time_t time)
}
+bool
+paths_exist(vector<boost::filesystem::path> const& paths)
+{
+ return std::all_of(paths.begin(), paths.end(), [](boost::filesystem::path const& path) { return dcp::filesystem::exists(path); });
+}
+
diff --git a/src/lib/util.h b/src/lib/util.h
index 67c759b57..525deeb75 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -103,6 +103,7 @@ extern void setup_grok_library_path();
#endif
extern std::string join_strings(std::vector<std::string> const& in, std::string const& separator = " ");
extern std::string rfc_2822_date(time_t time);
+bool paths_exist(std::vector<boost::filesystem::path> const& paths);
template <class T>
diff --git a/src/wx/content_menu.cc b/src/wx/content_menu.cc
index e2dfdaf97..dadd1877f 100644
--- a/src/wx/content_menu.cc
+++ b/src/wx/content_menu.cc
@@ -155,7 +155,7 @@ ContentMenu::popup (weak_ptr<Film> film, ContentList c, TimelineContentViewList
_join->Enable (n > 1);
- _find_missing->Enable (_content.size() == 1 && !_content.front()->paths_valid ());
+ _find_missing->Enable(_content.size() == 1 && !paths_exist(_content.front()->paths()));
_properties->Enable (_content.size() == 1);
_advanced->Enable (_content.size() == 1);
_re_examine->Enable (!_content.empty ());
diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc
index 8938ef0fd..826481216 100644
--- a/src/wx/content_panel.cc
+++ b/src/wx/content_panel.cc
@@ -482,7 +482,7 @@ ContentPanel::check_selection ()
optional<DCPTime> go_to;
for (auto content: selected()) {
- if (content->paths_valid()) {
+ if (paths_exist(content->paths())) {
auto position = content->position();
if (auto text_content = dynamic_pointer_cast<StringTextFileContent>(content)) {
/* Rather special case; if we select a text subtitle file jump to its
@@ -896,7 +896,7 @@ ContentPanel::setup ()
vector<ContentListCtrl::Item> items;
for (auto i: content) {
- bool const valid = i->paths_valid ();
+ bool const valid = paths_exist(i->paths());
auto dcp = dynamic_pointer_cast<DCPContent> (i);
bool const needs_kdm = dcp && dcp->needs_kdm ();
diff --git a/test/find_missing_test.cc b/test/find_missing_test.cc
index 94c2fc53b..f455be19d 100644
--- a/test/find_missing_test.cc
+++ b/test/find_missing_test.cc
@@ -63,14 +63,14 @@ BOOST_AUTO_TEST_CASE (find_missing_test_with_single_files)
/* That should make the content paths invalid */
for (auto content: film->content()) {
- BOOST_CHECK (!content->paths_valid());
+ BOOST_CHECK(!paths_exist(content->paths()));
}
/* Fix the missing files and check the result */
dcpomatic::find_missing (film->content(), moved / "A.png");
for (auto content: film->content()) {
- BOOST_CHECK (content->paths_valid());
+ BOOST_CHECK(paths_exist(content->paths()));
}
}
@@ -100,14 +100,14 @@ BOOST_AUTO_TEST_CASE (find_missing_test_with_multiple_files)
/* That should make the content paths invalid */
for (auto content: film->content()) {
- BOOST_CHECK (!content->paths_valid());
+ BOOST_CHECK(!paths_exist(content->paths()));
}
/* Fix the missing files and check the result */
dcpomatic::find_missing (film->content(), moved / "foo");
for (auto content: film->content()) {
- BOOST_CHECK (content->paths_valid());
+ BOOST_CHECK(paths_exist(content->paths()));
}
}
@@ -144,14 +144,14 @@ BOOST_AUTO_TEST_CASE (find_missing_test_with_multiple_files_one_incorrect)
/* The film's contents should be invalid */
for (auto content: film->content()) {
- BOOST_CHECK (!content->paths_valid());
+ BOOST_CHECK(!paths_exist(content->paths()));
}
dcpomatic::find_missing (film->content(), moved / "foo");
/* And even after find_missing there should still be missing content */
for (auto content: film->content()) {
- BOOST_CHECK (!content->paths_valid());
+ BOOST_CHECK(!paths_exist(content->paths()));
}
}
@@ -184,7 +184,7 @@ BOOST_AUTO_TEST_CASE(find_missing_test_with_rename)
/* That should make one of the content paths invalid */
auto content_list = film->content();
int const valid = std::count_if(content_list.begin(), content_list.end(), [](shared_ptr<const Content> content) {
- return content->paths_valid();
+ return paths_exist(content->paths());
});
BOOST_CHECK_EQUAL(valid, 2);
@@ -192,7 +192,7 @@ BOOST_AUTO_TEST_CASE(find_missing_test_with_rename)
dcpomatic::find_missing(content_list, content_dir / "bogus.png");
for (auto content: content_list) {
- BOOST_CHECK(content->paths_valid());
+ BOOST_CHECK(paths_exist(content->paths()));
}
}
@@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(test_film_saved_on_windows)
dcpomatic::find_missing(film->content(), TestPaths::private_data());
for (auto content: film->content()) {
- BOOST_CHECK(content->paths_valid());
+ BOOST_CHECK(paths_exist(content->paths()));
}
}
@@ -217,6 +217,6 @@ BOOST_AUTO_TEST_CASE(test_film_saved_on_posix)
dcpomatic::find_missing(film->content(), TestPaths::private_data());
for (auto content: film->content()) {
- BOOST_CHECK(content->paths_valid());
+ BOOST_CHECK(paths_exist(content->paths()));
}
}
diff --git a/test/relative_paths_test.cc b/test/relative_paths_test.cc
index cf40a8465..6028c1435 100644
--- a/test/relative_paths_test.cc
+++ b/test/relative_paths_test.cc
@@ -39,6 +39,6 @@ BOOST_AUTO_TEST_CASE(relative_paths_test)
auto film2 = std::make_shared<Film>(boost::filesystem::path("build/test/relative_paths_test"));
film2->read_metadata();
BOOST_REQUIRE_EQUAL(film2->content().size(), 1U);
- BOOST_REQUIRE(film2->content()[0]->paths_valid());
+ BOOST_REQUIRE(paths_exist(film2->content()[0]->paths()));
}