13 #ifndef __STOUT_OS_POSIX_CHOWN_HPP__
14 #define __STOUT_OS_POSIX_CHOWN_HPP__
17 #include <sys/types.h>
33 const std::string& path,
36 char* path_[] = {
const_cast<char*
>(path.c_str()),
nullptr};
38 FTS* tree = ::fts_open(
39 path_, FTS_NOCHDIR | FTS_PHYSICAL,
nullptr);
41 if (tree ==
nullptr) {
46 while ((node = ::fts_read(tree)) !=
nullptr) {
47 switch (node->fts_info) {
56 if (::lchown(node->fts_path, uid, gid) < 0) {
82 if (node->fts_level == FTS_ROOTLEVEL && !recursive) {
95 const std::string&
user,
96 const std::string& path,
97 bool recursive =
true)
103 if ((passwd = ::getpwnam(user.c_str())) ==
nullptr) {
105 ?
ErrnoError(
"Failed to get user information for '" + user +
"'")
106 :
Error(
"No such user '" + user +
"'");
114 #endif // __STOUT_OS_POSIX_CHOWN_HPP__
Try< uid_t > uid(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:182
Definition: nothing.hpp:16
Definition: errorbase.hpp:35
Result< std::string > user(Option< uid_t > uid=None())
Definition: su.hpp:277
Definition: errorbase.hpp:49
gid_t pw_gid
Definition: pwd.hpp:30
uid_t pw_uid
Definition: pwd.hpp:29
int uid_t
Definition: windows.hpp:189
std::string error(const std::string &msg, uint32_t code)
Try< Nothing > chown(uid_t uid, gid_t gid, const std::string &path, bool recursive)
Definition: chown.hpp:30
int gid_t
Definition: windows.hpp:190