fix: sanitize paths on Windows (gh #241)

This commit is contained in:
Marcus Holland-Moritz 2024-10-20 22:20:09 +02:00
parent 09d4748e87
commit 75300dbfc6
6 changed files with 10 additions and 9 deletions

View File

@ -124,7 +124,7 @@ file_stat::file_stat(fs::path const& path) {
status.type() == fs::file_type::not_found
? "file not found"
: "unknown file type",
u8string_to_string(path.u8string())));
path_to_utf8_string_sanitized(path)));
}
valid_fields_ = file_stat::mode_valid;

View File

@ -94,7 +94,7 @@ class incompressible_categorizer_job_ : public sequential_categorizer_job {
auto stats = [this] {
return fmt::format("{} -> incompressible blocks: {}/{}, overall "
"compression ratio: {:.2f}%",
u8string_to_string(path_.u8string()),
path_to_utf8_string_sanitized(path_),
incompressible_blocks_, total_blocks_,
100.0 * total_output_size_ / total_input_size_);
};

View File

@ -101,7 +101,7 @@ fs::path entry::fs_path() const {
}
std::string entry::path_as_string() const {
return u8string_to_string(fs_path().u8string());
return path_to_utf8_string_sanitized(fs_path());
}
std::string entry::dpath() const {
@ -409,7 +409,7 @@ void dir::remove_empty_dirs(progress& prog) {
}
std::shared_ptr<entry> dir::find(fs::path const& path) {
auto name = u8string_to_string(path.filename().u8string());
auto name = path_to_utf8_string_sanitized(path.filename());
if (!lookup_ && entries_.size() >= 16) {
populate_lookup_table();
@ -449,7 +449,7 @@ const std::string& link::linkname() const { return link_; }
void link::accept(entry_visitor& v, bool) { v.visit(this); }
void link::scan(os_access const& os, progress& prog) {
link_ = u8string_to_string(os.read_symlink(fs_path()).u8string());
link_ = path_to_utf8_string_sanitized(os.read_symlink(fs_path()));
prog.original_size += size();
prog.symlink_size += size();
}

View File

@ -351,7 +351,7 @@ class inode_ : public inode {
if (mm) {
if (auto size = mm->size(); size >= min_size) {
return prog.create_context<scanner_progress>(
context, u8string_to_string(mm->path().u8string()), size);
context, path_to_utf8_string_sanitized(mm->path()), size);
}
}
return nullptr;

View File

@ -189,7 +189,7 @@ template <typename LoggerPolicy>
void rule_based_entry_filter_<LoggerPolicy>::set_root_path(
fs::path const& path) {
// TODO: this whole thing needs to be windowsized
root_path_ = u8string_to_string(path.u8string());
root_path_ = path_to_utf8_string_sanitized(path);
if constexpr (kLocalPathSeparator != '/') {
// Both '/' and '\\' are, surprisingly, valid path separators on Windows,

View File

@ -467,7 +467,7 @@ scanner_<LoggerPolicy>::add_entry(std::filesystem::path const& name,
default:
LOG_ERROR << "unsupported entry type: " << int(pe->type()) << " ("
<< pe->fs_path() << ")";
<< pe->path_as_string() << ")";
prog.errors++;
break;
}
@ -552,7 +552,8 @@ scanner_<LoggerPolicy>::scan_tree(std::filesystem::path const& path,
prog.dirs_scanned++;
} catch (const std::system_error& e) {
LOG_ERROR << "cannot read directory `" << ppath
LOG_ERROR << "cannot read directory `"
<< path_to_utf8_string_sanitized(ppath)
<< "`: " << exception_str(e);
prog.errors++;
}