2222
2323namespace tmp {
2424namespace {
25-
2625namespace fs = std::filesystem;
2726
2827// / Checks if the given prefix is valid to attach to a temporary directory name
29- // / @param[in] prefix The prefix to check validity for
28+ // / @param prefix The prefix to check validity for
3029// / @returns `true` if the prefix is valid, `false` otherwise
3130bool is_prefix_valid (const fs::path& prefix) {
3231 // We also need to check that the prefix does not contain a root path
@@ -38,7 +37,7 @@ bool is_prefix_valid(const fs::path& prefix) {
3837#ifdef _WIN32
3938// / Creates a temporary path with the given prefix
4039// / @note prefix must be valid
41- // / @param[in] prefix A prefix to attach to the path pattern
40+ // / @param prefix A prefix to attach to the path pattern
4241// / @returns A unique temporary path
4342fs::path make_path (std::string_view prefix) {
4443 GUID guid;
@@ -61,9 +60,10 @@ fs::path make_path(std::string_view prefix) {
6160 return path;
6261}
6362#endif
63+ } // namespace
6464
6565// / Creates a temporary directory in the current user's temporary directory
66- // / @param[in] prefix A prefix to attach to the temporary directory name
66+ // / @param prefix A prefix to attach to the temporary directory name
6767// / @returns A path to the created temporary directory
6868// / @throws fs::filesystem_error if cannot create a temporary directory
6969// / @throws std::invalid_argument if the prefix contains a directory separator
@@ -95,38 +95,20 @@ fs::path create_directory(std::string_view prefix) {
9595 return path;
9696}
9797
98- // / Deletes a directory recursively, ignoring any errors
99- // / @param[in] directory The directory to delete
100- void remove_directory (const directory& directory ) noexcept {
98+ // / Deletes a path recursively, ignoring any errors
99+ // / @param path The path to delete
100+ void remove_all (const fs::path& path ) noexcept {
101101 try {
102- if (!directory. path () .empty ()) {
102+ if (!path.empty ()) {
103103 // Calling the `std::error_code` overload of `fs::remove_all` should be
104104 // more optimal here since it would not require creating
105105 // a `fs::filesystem_error` message before we suppress the exception
106106 std::error_code ec;
107- fs::remove_all (directory , ec);
107+ fs::remove_all (path , ec);
108108 }
109109 } catch (...) {
110110 // Do nothing: if we failed to delete the temporary directory,
111111 // the system should do it later
112112 }
113113}
114- } // namespace
115-
116- directory::directory (std::string_view prefix)
117- : pathobject(create_directory(prefix)) {}
118-
119- directory::~directory () noexcept {
120- remove_directory (*this );
121- }
122-
123- directory::directory (directory&& other) noexcept
124- : pathobject(std::exchange(other.pathobject, fs::path())) {}
125-
126- directory& directory::operator =(directory&& other) noexcept {
127- remove_directory (*this );
128-
129- pathobject = std::exchange (other.pathobject , fs::path ());
130- return *this ;
131- }
132114} // namespace tmp
0 commit comments