Repository: mesos
Updated Branches:
  refs/heads/master ec74a1e3e -> 695a73462


Add alternate os::chown taking uid and gid.

Review: https://reviews.apache.org/r/25655


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/695a7346
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/695a7346
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/695a7346

Branch: refs/heads/master
Commit: 695a734628ba1878cbc6f680ab7f2a68edecbc1f
Parents: ec74a1e
Author: Ian Downes <[email protected]>
Authored: Fri Sep 12 17:29:14 2014 -0700
Committer: Ian Downes <[email protected]>
Committed: Fri Oct 24 15:21:48 2014 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/os.hpp         | 34 +++++++++++++-------
 1 file changed, 22 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/695a7346/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 5d3cbba..ec259cd 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -552,23 +552,17 @@ inline int execvpe(const char* file, char** argv, char** 
envp)
 }
 
 
-// Changes the specified path's user and group ownership to that of
-// the specified user..
 inline Try<Nothing> chown(
-    const std::string& user,
+    uid_t uid,
+    gid_t gid,
     const std::string& path,
-    bool recursive = true)
+    bool recursive)
 {
-  passwd* passwd;
-  if ((passwd = ::getpwnam(user.c_str())) == NULL) {
-    return ErrnoError("Failed to get user information for '" + user + "'");
-  }
-
   if (recursive) {
     // TODO(bmahler): Consider walking the file tree instead. We would need
     // to be careful to not miss dotfiles.
-    std::string command = "chown -R " + stringify(passwd->pw_uid) + ':' +
-      stringify(passwd->pw_gid) + " '" + path + "'";
+    std::string command =
+      "chown -R " + stringify(uid) + ':' + stringify(gid) + " '" + path + "'";
 
     int status = os::system(command);
     if (status != 0) {
@@ -577,7 +571,7 @@ inline Try<Nothing> chown(
           "' (exit status: " + stringify(status) + ")");
     }
   } else {
-    if (::chown(path.c_str(), passwd->pw_uid, passwd->pw_gid) < 0) {
+    if (::chown(path.c_str(), uid, gid) < 0) {
       return ErrnoError();
     }
   }
@@ -586,6 +580,22 @@ inline Try<Nothing> chown(
 }
 
 
+// Changes the specified path's user and group ownership to that of
+// the specified user.
+inline Try<Nothing> chown(
+    const std::string& user,
+    const std::string& path,
+    bool recursive = true)
+{
+  passwd* passwd;
+  if ((passwd = ::getpwnam(user.c_str())) == NULL) {
+    return ErrnoError("Failed to get user information for '" + user + "'");
+  }
+
+  return chown(passwd->pw_uid, passwd->pw_gid, path, recursive);
+}
+
+
 inline Try<Nothing> chmod(const std::string& path, int mode)
 {
   if (::chmod(path.c_str(), mode) < 0) {

Reply via email to