Change the SetOwnership function behavior 30/239230/2
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 23 Jul 2020 02:11:55 +0000 (11:11 +0900)
committerilho kim <ilho159.kim@samsung.com>
Fri, 24 Jul 2020 04:07:10 +0000 (04:07 +0000)
If a file is symbolic link, change a symbolic link's ownership, not skip

Change-Id: I8f8be27050b10d07827a4a7a20d6588049304708

src/common/utils/file_util.cc

index dfe7aefbef6abfbe67f00a52c5208adcce495c10..b093532995d671c0ef429cdcd2d81dc403d9f75d 100644 (file)
@@ -98,13 +98,7 @@ FSFlag operator|(FSFlag a, FSFlag b) {
 }
 
 bool SetOwnership(const bf::path& path, uid_t uid, gid_t gid) {
-  int fd = open(path.c_str(), O_RDONLY);
-  if (fd < 0) {
-    LOG(ERROR) << "Can't open directory : " << path;
-    return false;
-  }
-  int ret = fchown(fd, uid, gid);
-  close(fd);
+  int ret = lchown(path.c_str(), uid, gid);
   if (ret != 0) {
     LOG(ERROR) << "Failed to change owner of: " << path;
     return false;
@@ -121,8 +115,6 @@ bool SetOwnershipAll(const bf::path& path, uid_t uid, gid_t gid) {
     iter != bf::recursive_directory_iterator();
     ++iter) {
     bf::path current(iter->path());
-    if (bf::is_symlink(symlink_status(current)))
-      continue;
     if (!SetOwnership(current, uid, gid))
       return false;
   }