Skip to content

Commit

Permalink
Add error-code constructors for directory (#143)
Browse files Browse the repository at this point in the history
Add `directory::directory(std::error_code&)` and
`directory::directory(std::string_view, std::error_code&)`
  • Loading branch information
bugdea1er authored Jan 21, 2025
1 parent 859d64e commit f36435c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/tmp/directory
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ namespace tmp {
class TMP_EXPORT directory : public entry {
public:
/// Creates a unique temporary directory
/// @param label A label to attach to the temporary directory path
/// @param[in] label A label to attach to the temporary directory path
/// @throws std::filesystem::filesystem_error if cannot create a directory
/// @throws std::invalid_argument if the label is ill-formatted
explicit directory(std::string_view label = "");

/// Creates a unique temporary directory
/// @param[out] ec Parameter for error reporting
explicit directory(std::error_code& ec);

/// Creates a unique temporary directory
/// @param[in] label A label to attach to the temporary directory path
/// @param[out] ec Parameter for error reporting
explicit directory(std::string_view label, std::error_code& ec);

/// Creates a unique temporary copy recursively from the given path
/// @param path A path to make a temporary copy from
/// @param label A label to attach to the temporary directory path
Expand Down
6 changes: 6 additions & 0 deletions src/directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ constexpr fs::copy_options copy_options =
directory::directory(std::string_view label)
: entry(create_directory(label)) {}

directory::directory(std::error_code& ec)
: entry(create_directory("", ec)) {}

directory::directory(std::string_view label, std::error_code& ec)
: entry(create_directory(label, ec)) {}

directory directory::copy(const fs::path& path, std::string_view label) {
directory tmpdir = directory(label);

Expand Down

0 comments on commit f36435c

Please sign in to comment.