aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/rename.ccm
blob: a1b292efe25259465b16984e5b0bcc347c6e9008 (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
24
25
26
27
28
// This source code is released into the public domain.
module;

#include <expected>
#include <filesystem>

export module nihil.posix:rename;

import nihil.error;

namespace nihil {

// Rename a file (or directory).
export [[nodiscard]] auto
rename(std::filesystem::path const &oldp, std::filesystem::path const &newp)
	-> std::expected<void, error>
{
	auto err = std::error_code();

	std::filesystem::rename(oldp, newp, err);

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

	return {};
}

} // namespace nihil