Add recursive option to chmod(), chown() 49/76849/1
authorSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 27 Jun 2016 10:24:00 +0000 (19:24 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 27 Jun 2016 10:37:08 +0000 (19:37 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: Id600f3dac8af2ae40b7b27040b770c69c3108748

common/filesystem.cpp
common/filesystem.h

index 2a3b575..748f30f 100755 (executable)
@@ -481,18 +481,34 @@ void File::makeDirectory(bool recursive, uid_t uid, gid_t gid)
     }
 }
 
-void File::chown(uid_t uid, gid_t gid)
+void File::chown(uid_t uid, gid_t gid, bool recursive)
 {
     if (::chown(path.getPathname().c_str(), uid, gid) != 0) {
         throw runtime::Exception(runtime::GetSystemErrorMessage());
     }
+
+    if (recursive && isDirectory()) {
+        DirectoryIterator iter(path), end;
+        while (iter != end) {
+            iter->chown(uid, gid, true);
+            ++iter;
+        }
+    }
 }
 
-void File::chmod(mode_t mode)
+void File::chmod(mode_t mode, bool recursive)
 {
     if (::chmod(path.getPathname().c_str(), mode) != 0) {
         throw runtime::Exception(runtime::GetSystemErrorMessage());
     }
+
+    if (recursive && isDirectory()) {
+        DirectoryIterator iter(path), end;
+        while (iter != end) {
+            iter->chmod(mode, true);
+            ++iter;
+        }
+    }
 }
 
 void File::lock() const
index 3211372..48e6f7b 100644 (file)
@@ -152,8 +152,8 @@ public:
     void lock() const;
     void unlock() const;
 
-    void chown(uid_t uid, gid_t gid);
-    void chmod(mode_t mode);
+    void chown(uid_t uid, gid_t gid, bool recursive = false);
+    void chmod(mode_t mode, bool recursive = false);
 
     std::string toString() const;