]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/class-wp-filesystem-direct.php
Wordpress 3.0
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-filesystem-direct.php
index 88e4a902a5982eb92b7d35a8a0e65f9c08b15d6e..538a683e8261c688ea94d29d859c3d1b0e4d05c0 100644 (file)
@@ -54,14 +54,13 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
        /**
         * Write a string to a file
         *
-        * @param $file string Path to the file where to write the data.
+        * @param $file string Remote path to the file where to write the data.
         * @param $contents string The data to write.
         * @param $mode int (optional) The file permissions as octal number, usually 0644.
-        * @param $type string (optional) Specifies additional type of access you require to the file.
         * @return bool False upon failure.
         */
-       function put_contents($file, $contents, $mode = false, $type = '') {
-               if ( ! ($fp = @fopen($file, 'w' . $type)) )
+       function put_contents($file, $contents, $mode = false ) {
+               if ( ! ($fp = @fopen($file, 'w')) )
                        return false;
                @fwrite($fp, $contents);
                @fclose($fp);
@@ -117,9 +116,6 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
         * @return bool Returns true on success or false on failure.
         */
        function chmod($file, $mode = false, $recursive = false) {
-               if ( ! $this->exists($file) )
-                       return false;
-
                if ( ! $mode ) {
                        if ( $this->is_file($file) )
                                $mode = FS_CHMOD_FILE;
@@ -129,14 +125,12 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
                                return false;
                }
 
-               if ( ! $recursive )
-                       return @chmod($file, $mode);
-               if ( ! $this->is_dir($file) )
+               if ( ! $recursive || ! $this->is_dir($file) )
                        return @chmod($file, $mode);
                //Is a directory, and we want recursive
                $file = trailingslashit($file);
                $filelist = $this->dirlist($file);
-               foreach ($filelist as $filename)
+               foreach ( (array)$filelist as $filename => $filemeta)
                        $this->chmod($file . $filename, $mode, $recursive);
 
                return true;
@@ -202,11 +196,18 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
        function copy($source, $destination, $overwrite = false) {
                if ( ! $overwrite && $this->exists($destination) )
                        return false;
+
                return copy($source, $destination);
        }
 
        function move($source, $destination, $overwrite = false) {
-               //Possible to use rename()?
+               if ( ! $overwrite && $this->exists($destination) )
+                       return false;
+
+               // try using rename first.  if that fails (for example, source is read only) try copy
+               if ( @rename($source, $destination) )
+                       return true;
+
                if ( $this->copy($source, $destination, $overwrite) && $this->exists($destination) ) {
                        $this->delete($source);
                        return true;
@@ -280,6 +281,11 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
        }
 
        function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
+               // safe mode fails with a trailing slash under certain PHP versions.
+               $path = untrailingslashit($path);
+               if ( empty($path) )
+                       $path = '/';
+
                if ( ! $chmod )
                        $chmod = FS_CHMOD_DIR;
 
@@ -294,17 +300,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base {
        }
 
        function rmdir($path, $recursive = false) {
-               //Currently unused and untested, Use delete() instead.
-               if ( ! $recursive )
-                       return @rmdir($path);
-               //recursive:
-               $filelist = $this->dirlist($path);
-               foreach ($filelist as $filename => $det) {
-                       if ( '/' == substr($filename, -1, 1) )
-                               $this->rmdir($path . '/' . $filename, $recursive);
-                       @rmdir($filename);
-               }
-               return @rmdir($path);
+               return $this->delete($path, $recursive);
        }
 
        function dirlist($path, $include_hidden = true, $recursive = false) {