From a9cb7313f7846f8b2bf9f96d19cf28abd7caf7fc Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 16 Sep 2024 10:10:46 +0200 Subject: Fix thinko in relative path change. We have to canonicalise relative paths with respect to the film's directory on load, otherwise we try to use the relative path and it's interpreted against the current working directory. This unfortunately requires the film's directory to be piped into quite a lot of new places. --- src/lib/content.cc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src/lib/content.cc') diff --git a/src/lib/content.cc b/src/lib/content.cc index 067a4cffc..be30ccf43 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -84,10 +84,14 @@ Content::Content (boost::filesystem::path p) } -Content::Content (cxml::ConstNodePtr node) +Content::Content(cxml::ConstNodePtr node, boost::optional film_directory) { for (auto i: node->node_children("Path")) { - _paths.push_back (i->content()); + if (film_directory) { + _paths.push_back(boost::filesystem::weakly_canonical(boost::filesystem::absolute(i->content(), *film_directory))); + } else { + _paths.push_back(i->content()); + } auto const mod = i->optional_number_attribute("mtime"); if (mod) { _last_write_times.push_back (*mod); @@ -147,19 +151,9 @@ Content::as_xml(xmlpp::Element* element, bool with_paths, PathBehaviour path_beh if (with_paths) { for (size_t i = 0; i < _paths.size(); ++i) { auto path = _paths[i]; - switch (path_behaviour) { - case PathBehaviour::MAKE_ABSOLUTE: - DCPOMATIC_ASSERT(film_directory); - if (path.is_relative()) { - path = boost::filesystem::canonical(path, *film_directory); - } - break; - case PathBehaviour::MAKE_RELATIVE: + if (path_behaviour == PathBehaviour::MAKE_RELATIVE) { DCPOMATIC_ASSERT(film_directory); path = boost::filesystem::relative(path, *film_directory); - break; - case PathBehaviour::KEEP: - break; } auto p = cxml::add_child(element, "Path"); p->add_child_text(path.string()); @@ -300,16 +294,16 @@ Content::set_trim_end (ContentTime t) shared_ptr -Content::clone () const +Content::clone() const { /* This is a bit naughty, but I can't think of a compelling reason not to do it ... */ xmlpp::Document doc; auto node = doc.create_root_node ("Content"); - as_xml(node, true, PathBehaviour::KEEP, {}); + as_xml(node, true, PathBehaviour::KEEP_ABSOLUTE, {}); /* notes is unused here (we assume) */ list notes; - return content_factory (make_shared(node), Film::current_state_version, notes); + return content_factory(make_shared(node), {}, Film::current_state_version, notes); } -- cgit v1.2.3