Skip to content

Commit

Permalink
Mark ~TmpDir() noexcept and log errors as warnings using spdlog
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Oct 16, 2024
1 parent 069ef5f commit 75416d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/libhictk/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

find_package(FMT REQUIRED)
find_package(libdeflate REQUIRED)
find_package(spdlog REQUIRED)
find_package(zstd REQUIRED)

add_library(common INTERFACE)
Expand All @@ -29,5 +30,6 @@ target_link_libraries(
INTERFACE
fmt::fmt-header-only
"libdeflate::libdeflate_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>"
spdlog::spdlog_header_only
"zstd::libzstd_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>"
)
17 changes: 12 additions & 5 deletions src/libhictk/common/include/hictk/tmpdir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

#include <fmt/format.h>
#include <fmt/std.h>
#include <spdlog/spdlog.h>

#include <atomic>
#include <cstdlib>
#include <filesystem>
#include <stdexcept>
#include <utility>

namespace hictk::internal {
Expand All @@ -31,7 +33,7 @@ class TmpDir {

void delete_at_exit() {
if (_delete_on_destruction) {
std::filesystem::remove_all(_path);
std::filesystem::remove_all(_path); // NOLINT
}
}

Expand Down Expand Up @@ -71,15 +73,20 @@ class TmpDir {
TmpDir(const TmpDir& other) = delete;
TmpDir(TmpDir&& other) = delete;

~TmpDir() {
if (get_delete_on_destruction()) {
std::filesystem::remove_all(_path);
// NOLINTNEXTLINE(bugprone-exception-escape)
~TmpDir() noexcept {
try {
delete_at_exit();
} catch (std::exception& e) {
SPDLOG_WARN(FMT_STRING("failed to delete temporary folder \"{}\": {}"), _path, e.what());
} catch (...) {
SPDLOG_WARN(FMT_STRING("failed to delete temporary folder \"{}\""), _path);

Check warning on line 83 in src/libhictk/common/include/hictk/tmpdir.hpp

View check run for this annotation

Codecov / codecov/patch

src/libhictk/common/include/hictk/tmpdir.hpp#L81-L83

Added lines #L81 - L83 were not covered by tests
}
}

[[nodiscard]] const std::filesystem::path& operator()() const noexcept { return _path; }
[[maybe_unused]] [[nodiscard]] bool get_delete_on_destruction() const noexcept {
return _delete_on_destruction;
return _delete_on_destruction.load();

Check warning on line 89 in src/libhictk/common/include/hictk/tmpdir.hpp

View check run for this annotation

Codecov / codecov/patch

src/libhictk/common/include/hictk/tmpdir.hpp#L89

Added line #L89 was not covered by tests
}

[[maybe_unused]] void set_delete_on_destruction(const bool flag) noexcept {
Expand Down

0 comments on commit 75416d2

Please sign in to comment.