Fix canonical path on Windows when accessing mounted DwarFS image

This commit is contained in:
Marcus Holland-Moritz 2023-08-07 23:00:43 +02:00
parent b09dea238c
commit d4d65a4d99
4 changed files with 19 additions and 6 deletions

View File

@ -23,6 +23,7 @@
#include <chrono> #include <chrono>
#include <cstddef> #include <cstddef>
#include <filesystem>
#include <string> #include <string>
#include "dwarfs/types.h" #include "dwarfs/types.h"
@ -49,4 +50,6 @@ size_t utf8_display_width(std::string const& str);
void shorten_path_string(std::string& path, char separator, size_t max_len); void shorten_path_string(std::string& path, char separator, size_t max_len);
std::filesystem::path canonical_path(std::filesystem::path p);
} // namespace dwarfs } // namespace dwarfs

View File

@ -173,4 +173,18 @@ void shorten_path_string(std::string& path, char separator, size_t max_len) {
} }
} }
std::filesystem::path canonical_path(std::filesystem::path p) {
try {
p = std::filesystem::canonical(p);
} catch (std::filesystem::filesystem_error const&) {
p = std::filesystem::absolute(p);
}
#ifdef _WIN32
p = std::filesystem::path(L"\\\\?\\" + p.wstring());
#endif
return p;
}
} // namespace dwarfs } // namespace dwarfs

View File

@ -994,7 +994,7 @@ int option_hdl(void* data, char const* arg, int key,
return 1; return 1;
} }
opts->fsimage = std::filesystem::canonical( opts->fsimage = canonical_path(
std::filesystem::path(reinterpret_cast<char8_t const*>(arg))); std::filesystem::path(reinterpret_cast<char8_t const*>(arg)));
return 0; return 0;

View File

@ -676,11 +676,7 @@ int mkdwarfs_main(int argc, sys_char** argv) {
} }
} }
path = std::filesystem::canonical(path); path = canonical_path(path);
#ifdef _WIN32
path = std::filesystem::path(L"\\\\?\\" + path.wstring());
#endif
bool recompress = vm.count("recompress"); bool recompress = vm.count("recompress");
rewrite_options rw_opts; rewrite_options rw_opts;