Loading...
Searching...
No Matches
safe_filesystem_entry.hpp
Go to the documentation of this file.
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
#include <cassert>
#include <filesystem>
#include <system_error>
#include <seqan3/core/platform.hpp>
namespace seqan3::detail
{
class safe_filesystem_entry
{
public:
safe_filesystem_entry() = delete;
safe_filesystem_entry(safe_filesystem_entry const &) = delete;
safe_filesystem_entry(safe_filesystem_entry &&) = default;
safe_filesystem_entry & operator=(safe_filesystem_entry const &) = delete;
safe_filesystem_entry & operator=(safe_filesystem_entry &&) = default;
safe_filesystem_entry(std::filesystem::path p) : entry(std::move(p))
{}
~safe_filesystem_entry()
{
std::error_code ec;
std::filesystem::remove_all(entry, ec);
assert(!static_cast<bool>(ec));
}
bool remove()
{
return std::filesystem::remove(entry);
}
bool remove_no_throw() const noexcept
{
std::error_code ec;
return std::filesystem::remove(entry, ec);
}
std::uintmax_t remove_all()
{
return std::filesystem::remove_all(entry);
}
private:
std::filesystem::path entry;
};
} // namespace seqan3::detail
cassert
filesystem
platform.hpp
Provides platform and dependency checks.
std::filesystem::remove_all
T remove_all(T... args)
system_error
Hide me