13 #ifndef __STOUT_OS_POSIX_CHOWN_HPP__ 14 #define __STOUT_OS_POSIX_CHOWN_HPP__ 17 #include <sys/types.h> 32 const std::string&
path,
35 char* path_[] = {
const_cast<char*
>(path.c_str()),
nullptr};
37 FTS* tree = ::fts_open(
38 path_, FTS_NOCHDIR | FTS_PHYSICAL,
nullptr);
40 if (tree ==
nullptr) {
45 while ((node = ::fts_read(tree)) !=
nullptr) {
46 switch (node->fts_info) {
55 if (::lchown(node->fts_path, uid, gid) < 0) {
81 if (node->fts_level == FTS_ROOTLEVEL && !recursive) {
94 const std::string&
user,
95 const std::string&
path,
96 bool recursive =
true)
102 if ((passwd = ::getpwnam(user.c_str())) ==
nullptr) {
104 ?
ErrnoError(
"Failed to get user information for '" + user +
"'")
105 :
Error(
"No such user '" + user +
"'");
113 #endif // __STOUT_OS_POSIX_CHOWN_HPP__
Try< uid_t > uid(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:224
Definition: nothing.hpp:16
Definition: errorbase.hpp:36
UINT uid_t
Definition: windows.hpp:183
Result< std::string > user(Option< uid_t > uid=None())
Definition: su.hpp:284
Definition: errorbase.hpp:50
Definition: posix_signalhandler.hpp:23
gid_t pw_gid
Definition: pwd.hpp:30
uid_t pw_uid
Definition: pwd.hpp:29
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:29
UINT gid_t
Definition: windows.hpp:184