]> source.dussan.org Git - nextcloud-server.git/commitdiff
move chmodr to OC_HELPER
authorRobin Appelman <icewind1991@gmail.com>
Sat, 16 Apr 2011 08:23:15 +0000 (10:23 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Sat, 16 Apr 2011 08:23:15 +0000 (10:23 +0200)
lib/base.php
lib/helper.php

index 9df61da78c321a60ddc5a64738494a150ad1e26e..c84d61b3214875c41c48c5e375489ded4e540e8b 100644 (file)
@@ -256,7 +256,7 @@ class OC_UTIL {
                        }
                        $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
                        if(substr($prems,-1)!='0'){
-                               chmodr($CONFIG_DATADIRECTORY_ROOT,0770);
+                               OC_HELPER::chmodr($CONFIG_DATADIRECTORY_ROOT,0770);
                                clearstatcache();
                                $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
                                if(substr($prems,2,1)!='0'){
@@ -266,7 +266,7 @@ class OC_UTIL {
                        if($CONFIG_ENABLEBACKUP){
                                $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
                                if(substr($prems,-1)!='0'){
-                                       chmodr($CONFIG_BACKUPDIRECTORY,0770);
+                                       OC_HELPER::chmodr($CONFIG_BACKUPDIRECTORY,0770);
                                        clearstatcache();
                                        $prems=substr(decoct(fileperms($CONFIG_BACKUPDIRECTORY)),-3);
                                        if(substr($prems,2,1)!='0'){
@@ -349,27 +349,4 @@ class OC_HOOK{
                return true;
        }
 }
-
-function chmodr($path, $filemode) {
-//      echo "$path<br/>";
-       if (!is_dir($path))
-               return chmod($path, $filemode);
-       $dh = opendir($path);
-       while (($file = readdir($dh)) !== false) {
-               if($file != '.' && $file != '..') {
-                       $fullpath = $path.'/'.$file;
-                       if(is_link($fullpath))
-                               return FALSE;
-                       elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode))
-                                       return FALSE;
-                       elseif(!chmodr($fullpath, $filemode))
-                               return FALSE;
-               }
-       }
-       closedir($dh);
-       if(chmod($path, $filemode))
-               return TRUE;
-       else
-               return FALSE;
-}
 ?>
index 982da7b6cc3aa8c92882bcd6f7d412a3c34e0518..c51629f21cbb1374c2b8e61a3ec2083438aa9151 100644 (file)
@@ -113,6 +113,35 @@ class OC_HELPER {
                $bytes = round( $bytes / 1024, 1 );
                return "$bytes GB";
        }
+       
+       /**
+        * @brief Recusive editing of file permissions
+        * @param $path path to file or folder
+        * @param $filemode unix style file permissions as integer
+        *
+        * Makes 2048 to 2 kB.
+        */
+       function chmodr($path, $filemode) {
+               if (!is_dir($path))
+                       return chmod($path, $filemode);
+               $dh = opendir($path);
+               while (($file = readdir($dh)) !== false) {
+                       if($file != '.' && $file != '..') {
+                               $fullpath = $path.'/'.$file;
+                               if(is_link($fullpath))
+                                       return FALSE;
+                               elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode))
+                                               return FALSE;
+                               elseif(!chmodr($fullpath, $filemode))
+                                       return FALSE;
+                       }
+               }
+               closedir($dh);
+               if(chmod($path, $filemode))
+                       return TRUE;
+               else
+                       return FALSE;
+       }
 }
 
 ?>