summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-10-10 00:40:00 +0200
committerCarl Hetherington <cth@carlh.net>2023-10-10 10:58:39 +0200
commit6d1582f3c4b5afe57bdc3c34dada275a05a961a4 (patch)
tree0b443f98a21ec0c9271e9400506f275211c8a9e9 /src
parentd70c44e87632a69a2b8bc90db7ca4b06b7aa611d (diff)
Implement weakly_canonical for boost versions without it (e.g. the one on Ubuntu 16.04).
Diffstat (limited to 'src')
-rw-r--r--src/filesystem.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/filesystem.cc b/src/filesystem.cc
index 0ebe7cf7..428bb029 100644
--- a/src/filesystem.cc
+++ b/src/filesystem.cc
@@ -144,7 +144,26 @@ dcp::filesystem::canonical(boost::filesystem::path const& path)
boost::filesystem::path
dcp::filesystem::weakly_canonical(boost::filesystem::path const& path)
{
+#ifdef DCPOMATIC_HAVE_WEAKLY_CANONICAL
return dcp::filesystem::unfix_long_path(boost::filesystem::weakly_canonical(dcp::filesystem::fix_long_path(path)));
+#else
+ boost::filesystem::path complete(boost::filesystem::system_complete(dcp::filesystem::fix_long_path(path)));
+ boost::filesystem::path result;
+ for (auto part: complete) {
+ if (part == "..") {
+ boost::system::error_code ec;
+ if (boost::filesystem::is_symlink(result, ec) || result.filename() == "..") {
+ result /= part;
+ } else {
+ result = result.parent_path();
+ }
+ } else if (part != ".") {
+ result /= part;
+ }
+ }
+
+ return dcp::filesystem::unfix_long_path(result.make_preferred());
+#endif
}