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 <cstddef>
#include <filesystem>
#include <string>
#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);
std::filesystem::path canonical_path(std::filesystem::path p);
} // 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

View File

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

View File

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