Skip to content

Commit

Permalink
Fixing issue with different behavior of / operator on filesystem paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Aug 19, 2023
1 parent 011ed98 commit 60a9bd0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/archives/archivator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void archivator::decompress(const std::string &filename, const std::string &dest
if (r < ARCHIVE_OK) { throw archive_exception(archive_error_string(a.get())); }

const char *current_file = archive_entry_pathname(entry);
const std::string full_path = (fs::path(destination) / current_file).string();
const std::string full_path = (fs::path(destination) / fs::path(current_file).relative_path()).string();
archive_entry_set_pathname(entry, full_path.c_str());
auto filetype = archive_entry_filetype(entry);
if (filetype == AE_IFREG) {
Expand Down
7 changes: 4 additions & 3 deletions src/fileman/cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cache_manager::cache_manager(const std::string &caching_dir, std::shared_ptr<spd

void cache_manager::get_file(const std::string &src_name, const std::string &dst_path)
{
fs::path source_file = caching_dir_ / src_name;
fs::path source_file = caching_dir_ / fs::path(src_name).relative_path();
fs::path destination_file = dst_path;
logger_->debug("Copying file {} from cache to {}", src_name, dst_path);

Expand All @@ -53,12 +53,13 @@ void cache_manager::get_file(const std::string &src_name, const std::string &dst
void cache_manager::put_file(const std::string &src_name, const std::string &dst_name)
{
fs::path source_file(src_name);
fs::path destination_file = caching_dir_ / dst_name;
fs::path destination_file = caching_dir_ / fs::path(dst_name).relative_path();
fs::path destination_temp_file;

do {
// generate name and check it for existance, if exists... repeat
destination_temp_file = caching_dir_ / (dst_name + "-" + helpers::random_alphanum_string(20) + ".tmp");
fs::path random_name(dst_name + "-" + helpers::random_alphanum_string(20) + ".tmp");
destination_temp_file = caching_dir_ / random_name.relative_path();
} while (fs::exists(destination_temp_file));

logger_->debug("Copying file {} to cache with name {}", src_name, dst_name);
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fs::path helpers::find_path_outside_sandbox(const std::string &inside_path,
auto file_path_string = file_path.string();

// try to find the file in main source directory
auto source_path = fs::path(source_dir) / file_path;
auto source_path = fs::path(source_dir) / file_path.relative_path();
if (fs::exists(source_path)) { return source_path; }

// try to find the file in sandbox bound directories (absolute path in sandbox provided)
Expand All @@ -160,7 +160,7 @@ fs::path helpers::find_path_outside_sandbox(const std::string &inside_path,

if (file_path_string.find(sandbox_dir_string) == 0) {
std::string file_path_end = file_path_string.substr(sandbox_dir_string.length());
return fs::path(std::get<0>(dir)) / fs::path(file_path_end);
return fs::path(std::get<0>(dir)) / fs::path(file_path_end).relative_path();
}
}

Expand Down

0 comments on commit 60a9bd0

Please sign in to comment.