[Jaws-commits] r13480 - trunk/jaws/html/include/Jaws

afz at jaws-project.com afz at jaws-project.com
Fri Aug 17 11:45:22 UTC 2012


Author: afz
Date: 2012-08-17 11:45:22 +0000 (Fri, 17 Aug 2012)
New Revision: 13480

Modified:
   trunk/jaws/html/include/Jaws/Utils.php
Log:
[Jaws_Utils]: Improve copy/mkdir/chmod methods

Modified: trunk/jaws/html/include/Jaws/Utils.php
===================================================================
--- trunk/jaws/html/include/Jaws/Utils.php	2012-08-17 11:44:55 UTC (rev 13479)
+++ trunk/jaws/html/include/Jaws/Utils.php	2012-08-17 11:45:22 UTC (rev 13480)
@@ -177,7 +177,10 @@
     {
         $res = @file_put_contents($file, $data, $flags, $resource_context);
         if ($res !== false) {
-            Jaws_Utils::chmod($file);
+            $mode = @fileperms(dirname($file));
+            if (!empty($mode)) {
+                Jaws_Utils::chmod($file, '0775');
+            }
         }
 
         return $res;
@@ -204,6 +207,7 @@
             }
         }
 
+        $mode = is_int($mode)? $mode : octdec($mode);
         $mask = umask(0);
         /* Take care of the safe mode limitations if safe_mode=1 */
         if (ini_get('safe_mode')) {
@@ -229,8 +233,8 @@
      * Make directory
      *
      * @access  public
-     * @param   string  $path directory path
-     * @param   integer $mode see php chmod() function
+     * @param   string  $path   Path to the directory
+     * @param   integer $mode   see php chmod() function
      * @return  boolean True/False
      */
     function mkdir($path, $recursive = 0, $mode = null)
@@ -244,7 +248,11 @@
             $result = @mkdir($path);
         }
 
-        if ($result) {
+        if (empty($mode)) {
+            $mode = @fileperms(dirname($path));
+        }
+
+        if ($result && !empty($mode)) {
             Jaws_Utils::chmod($path, $mode);
         }
 
@@ -257,26 +265,41 @@
      * @access  public
      * @param   text    $source Path to the source file or directory
      * @param   text    $dest   The destination path
+     * @param   integer $mode   see php chmod() function
      * @see http://www.php.net/copy
      */
-    function copy($source, $dest) {
-        $hDir = opendir($source);
-        Jaws_Utils::mkdir($dest);
-        while(false !== ($file = @readdir($hDir))) {
-            if($file == '.' || $file == '..') {
-                continue;
-            }
+    function copy($source, $dest, $mode = null)
+    {
+        $result = false;
+        if (file_exists($source)) {
+            if (is_dir($source)) {
+                if (false !== $hDir = @opendir($source)) {
+                    if ($result = Jaws_Utils::mkdir($dest, 0, $mode)) {
+                        while(false !== ($file = @readdir($hDir))) {
+                            if($file == '.' || $file == '..') {
+                                continue;
+                            }
 
-            if (is_dir($source. DIRECTORY_SEPARATOR . $file)) {
-                Jaws_Utils::copy($source. DIRECTORY_SEPARATOR . $file,
-                                 $dest. DIRECTORY_SEPARATOR . $file);
+                            $result = Jaws_Utils::copy($source. DIRECTORY_SEPARATOR . $file,
+                                                       $dest. DIRECTORY_SEPARATOR . $file,
+                                                       $mode);
+                            if (!$result) {
+                                break;
+                            }
+                        }
+                    }
+
+                    closedir($hDir);
+                }
             } else {
-                @copy($source. DIRECTORY_SEPARATOR . $file,
-                      $dest. DIRECTORY_SEPARATOR . $file);
+                $result = @copy($source, $dest);
+                if ($result && !empty($mode)) {
+                    Jaws_Utils::chmod($dest, $mode);
+                }
             }
         }
 
-        closedir($hDir);
+        return $result;
     }
 
     /**
@@ -302,14 +325,15 @@
             return @unlink($path);
         }
 
-        $files = scandir($path);
-        foreach ($files as $file) {
-            if($file == '.' || $file == '..') {
-                continue;
-            }
+        if (false !== $files = @scandir($path)) {
+            foreach ($files as $file) {
+                if($file == '.' || $file == '..') {
+                    continue;
+                }
 
-            if (!Jaws_Utils::delete($path. DIRECTORY_SEPARATOR. $file, $dirs_include)) {
-                return false;
+                if (!Jaws_Utils::delete($path. DIRECTORY_SEPARATOR. $file, $dirs_include)) {
+                    return false;
+                }
             }
         }
 



More information about the Jaws-commits mailing list