Skip to content

Commit

Permalink
fix: sanitize paths on Windows (gh #241)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Oct 20, 2024
1 parent cab7246 commit e5a972f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/file_stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/writer/categorizer/incompressible_categorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
};
Expand Down
6 changes: 3 additions & 3 deletions src/writer/internal/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -412,7 +412,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();
Expand Down Expand Up @@ -452,7 +452,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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/writer/internal/inode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/writer/rule_based_entry_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/writer/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,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;
}
Expand Down Expand Up @@ -553,7 +553,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++;
}
Expand Down

0 comments on commit e5a972f

Please sign in to comment.