Skip to content

Commit

Permalink
Remove the entry managed path in close function
Browse files Browse the repository at this point in the history
  • Loading branch information
bugdea1er committed Jan 17, 2025
1 parent 1c123d4 commit 57142ec
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,8 @@ const entry::native_handle_type invalid_handle = INVALID_HANDLE_VALUE;
constexpr entry::native_handle_type invalid_handle = -1;
#endif

/// Closes the given entry, ignoring any errors
/// @param entry The entry to close
void close(const entry& entry) noexcept {
#ifdef _WIN32
CloseHandle(entry.native_handle());
#else
::close(entry.native_handle());
#endif
}

/// Deletes the given path recursively, ignoring any errors
/// @param path The path to delete
/// @param[in] path The path to delete
void remove(const fs::path& path) noexcept {
if (!path.empty()) {
try {
Expand All @@ -61,6 +51,19 @@ void remove(const fs::path& path) noexcept {
}
}

/// Closes the given entry, ignoring any errors
/// @note Also deletes the managed path
/// @param[in] entry The entry to close
void close(const entry& entry) noexcept {
remove(entry);

#ifdef _WIN32
CloseHandle(entry.native_handle());
#else
::close(entry.native_handle());
#endif
}

/// Moves the filesystem object as if by `std::filesystem::rename`
/// even when moving between filesystems
/// @param[in] from The path to move
Expand Down Expand Up @@ -127,7 +130,6 @@ entry::entry(entry&& other) noexcept

entry& entry::operator=(entry&& other) noexcept {
close(*this);
remove(*this);

pathobject = std::move(other.pathobject);
other.pathobject.clear();
Expand All @@ -140,7 +142,6 @@ entry& entry::operator=(entry&& other) noexcept {

entry::~entry() noexcept {
close(*this);
remove(*this);
}

entry::operator const fs::path&() const noexcept {
Expand Down

0 comments on commit 57142ec

Please sign in to comment.