aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/ensure_dir.ccm
blob: 9ae6d8018bf61af5c73e692b854fe6405dda5590 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// This source code is released into the public domain.
export module nihil.posix:ensure_dir;

import nihil.std;
import nihil.util;

namespace nihil {

// Create the given directory and any parent directories.
export [[nodiscard]] auto
ensure_dir(std::filesystem::path const &dir) -> std::expected<void, error>
{
	auto err = std::error_code();

	std::filesystem::create_directories(dir, err);

	if (err)
		return std::unexpected(error(err));

	return {};
}

} // namespace nihil