Skip to content

Commit

Permalink
Fixed an issue where moving between devices would behave differently …
Browse files Browse the repository at this point in the history
…than on the same device
  • Loading branch information
bugdea1er committed Feb 6, 2024
1 parent 0f54f95 commit c9a20bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/tmp/path
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <filesystem>
#include <string_view>
#include <system_error>

namespace tmp {

Expand Down
7 changes: 7 additions & 0 deletions lib/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const fs::copy_options copy_options = fs::copy_options::recursive

/// Creates the parent directory of the given path if it does not exist
/// @param path The path for which the parent directory needs to be created
/// @throws fs::filesystem_error if cannot create the parent
void create_parent(const fs::path& path) {
fs::create_directories(path.parent_path());
}
Expand Down Expand Up @@ -66,6 +67,12 @@ void path::move(const fs::path& to) {
std::error_code ec;
fs::rename(*this, to, ec);
if (ec == std::errc::cross_device_link) {
if (fs::is_regular_file(*this) && fs::is_directory(to)) {
ec = std::make_error_code(std::errc::is_a_directory);
throw fs::filesystem_error("Cannot move temporary file", to, ec);
}

fs::remove_all(to);
fs::copy(*this, to, copy_options, ec);
}

Expand Down

0 comments on commit c9a20bb

Please sign in to comment.