X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Ffilesystem.cc;h=428bb0298b881502eded019302193deb4dc06ef0;hb=6d1582f3c4b5afe57bdc3c34dada275a05a961a4;hp=0ebe7cf71681badc22aedbeda8132a4f8497d87b;hpb=d70c44e87632a69a2b8bc90db7ca4b06b7aa611d;p=libdcp.git 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 }