SeqAn3  3.0.1
The Modern C++ library for sequence analysis.
safe_filesystem_entry.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <cassert>
16 #include <system_error>
17 
18 #include <seqan3/core/platform.hpp>
19 #include <seqan3/std/filesystem>
20 
21 namespace seqan3::detail
22 {
23 
37 class safe_filesystem_entry
38 {
39 public:
43  safe_filesystem_entry() = delete;
44  safe_filesystem_entry(safe_filesystem_entry const &) = delete;
45  safe_filesystem_entry(safe_filesystem_entry &&) = default;
46  safe_filesystem_entry & operator=(safe_filesystem_entry const &) = delete;
47  safe_filesystem_entry & operator=(safe_filesystem_entry &&) = default;
48 
52  safe_filesystem_entry(std::filesystem::path p) : entry(std::move(p))
53  {}
54 
56  ~safe_filesystem_entry()
57  {
58  std::error_code ec;
59  std::filesystem::remove_all(entry, ec);
60 
61  assert(!static_cast<bool>(ec));
62  }
64 
73  bool remove()
74  {
75  return std::filesystem::remove(entry);
76  }
77 
79  bool remove_no_throw() const noexcept
80  {
81  std::error_code ec;
82  return std::filesystem::remove(entry, ec);
83  }
84 
95  {
96  return std::filesystem::remove_all(entry);
97  }
98 
99 private:
100 
102  std::filesystem::path entry;
103 };
104 
105 } // namespace seqan3::detail
system_error
seqan3::views::move
const auto move
A view that turns lvalue-references into rvalue-references.
Definition: move.hpp:68
filesystem
This header includes C++17 filesystem support and imports it into namespace seqan3::filesystem (indep...
std::filesystem::path
std::error_code
std::uintmax_t
std::filesystem::remove_all
T remove_all(T... args)
platform.hpp
Provides platform and dependency checks.
std
SeqAn specific customisations in the standard namespace.
cassert