summaryrefslogtreecommitdiff
path: root/src/lib/content.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-09-16 10:10:46 +0200
committerCarl Hetherington <cth@carlh.net>2024-09-18 10:41:19 +0200
commita9cb7313f7846f8b2bf9f96d19cf28abd7caf7fc (patch)
tree020b1ed7922e97c9711641209efdab845cdf65fc /src/lib/content.cc
parent5c5da23c412e9b922154f8934e16f3a51ff48bdc (diff)
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.
Diffstat (limited to 'src/lib/content.cc')
-rw-r--r--src/lib/content.cc26
1 files changed, 10 insertions, 16 deletions
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<boost::filesystem::path> 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<time_t>("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>
-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<string> notes;
- return content_factory (make_shared<cxml::Node>(node), Film::current_state_version, notes);
+ return content_factory(make_shared<cxml::Node>(node), {}, Film::current_state_version, notes);
}