mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 04:19:10 -04:00
Fix canonical path on Windows when accessing mounted DwarFS image
This commit is contained in:
parent
b09dea238c
commit
d4d65a4d99
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user