diff --git a/wp-admin/includes/class-wp-filesystem-direct.php b/wp-admin/includes/class-wp-filesystem-direct.php index 94319bce0d..e5d87f24a4 100644 --- a/wp-admin/includes/class-wp-filesystem-direct.php +++ b/wp-admin/includes/class-wp-filesystem-direct.php @@ -193,11 +193,14 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { return $grouparray['name']; } - function copy($source, $destination, $overwrite = false) { + function copy($source, $destination, $overwrite = false, $mode = false) { if ( ! $overwrite && $this->exists($destination) ) return false; - return copy($source, $destination); + $rtval = copy($source, $destination); + if ( $mode ) + $this->chmod($destination, $mode); + return $rtval; } function move($source, $destination, $overwrite = false) { @@ -216,12 +219,12 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { } } - function delete($file, $recursive = false) { + function delete($file, $recursive = false, $type = false) { if ( empty($file) ) //Some filesystems report this as /, which can cause non-expected recursive deletion of all files in the filesystem. return false; $file = str_replace('\\', '/', $file); //for win32, occasional problems deleteing files otherwise - if ( $this->is_file($file) ) + if ( 'f' == $type || $this->is_file($file) ) return @unlink($file); if ( ! $recursive && $this->is_dir($file) ) return @rmdir($file); @@ -233,7 +236,7 @@ class WP_Filesystem_Direct extends WP_Filesystem_Base { $retval = true; if ( is_array($filelist) ) //false if no files, So check first. foreach ($filelist as $filename => $fileinfo) - if ( ! $this->delete($file . $filename, $recursive) ) + if ( ! $this->delete($file . $filename, $recursive, $fileinfo['type']) ) $retval = false; if ( file_exists($file) && ! @rmdir($file) ) diff --git a/wp-admin/includes/class-wp-filesystem-ftpext.php b/wp-admin/includes/class-wp-filesystem-ftpext.php index df4ce0ad50..72325d2157 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpext.php +++ b/wp-admin/includes/class-wp-filesystem-ftpext.php @@ -183,22 +183,22 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { $dir = $this->dirlist($file); return $dir[$file]['group']; } - function copy($source, $destination, $overwrite = false ) { + function copy($source, $destination, $overwrite = false, $mode = false) { if ( ! $overwrite && $this->exists($destination) ) return false; $content = $this->get_contents($source); if ( false === $content) return false; - return $this->put_contents($destination, $content); + return $this->put_contents($destination, $content, $mode); } function move($source, $destination, $overwrite = false) { return ftp_rename($this->link, $source, $destination); } - function delete($file, $recursive = false ) { + function delete($file, $recursive = false, $type = false) { if ( empty($file) ) return false; - if ( $this->is_file($file) ) + if ( 'f' == $type || $this->is_file($file) ) return @ftp_delete($this->link, $file); if ( !$recursive ) return @ftp_rmdir($this->link, $file); @@ -206,7 +206,7 @@ class WP_Filesystem_FTPext extends WP_Filesystem_Base { $filelist = $this->dirlist( trailingslashit($file) ); if ( !empty($filelist) ) foreach ( $filelist as $delete_file ) - $this->delete( trailingslashit($file) . $delete_file['name'], $recursive); + $this->delete( trailingslashit($file) . $delete_file['name'], $recursive, $delete_file['type'] ); return @ftp_rmdir($this->link, $file); } diff --git a/wp-admin/includes/class-wp-filesystem-ftpsockets.php b/wp-admin/includes/class-wp-filesystem-ftpsockets.php index efd19d1f6f..397862609b 100644 --- a/wp-admin/includes/class-wp-filesystem-ftpsockets.php +++ b/wp-admin/includes/class-wp-filesystem-ftpsockets.php @@ -193,7 +193,7 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { return $dir[$file]['group']; } - function copy($source, $destination, $overwrite = false ) { + function copy($source, $destination, $overwrite = false, $mode = false) { if ( ! $overwrite && $this->exists($destination) ) return false; @@ -201,17 +201,17 @@ class WP_Filesystem_ftpsockets extends WP_Filesystem_Base { if ( false === $content ) return false; - return $this->put_contents($destination, $content); + return $this->put_contents($destination, $content, $mode); } function move($source, $destination, $overwrite = false ) { return $this->ftp->rename($source, $destination); } - function delete($file, $recursive = false ) { + function delete($file, $recursive = false, $type = false) { if ( empty($file) ) return false; - if ( $this->is_file($file) ) + if ( 'f' == $type || $this->is_file($file) ) return $this->ftp->delete($file); if ( !$recursive ) return $this->ftp->rmdir($file); diff --git a/wp-admin/includes/class-wp-filesystem-ssh2.php b/wp-admin/includes/class-wp-filesystem-ssh2.php index f5a64021cd..0721a58349 100644 --- a/wp-admin/includes/class-wp-filesystem-ssh2.php +++ b/wp-admin/includes/class-wp-filesystem-ssh2.php @@ -238,28 +238,28 @@ class WP_Filesystem_SSH2 extends WP_Filesystem_Base { return $grouparray['name']; } - function copy($source, $destination, $overwrite = false ) { + function copy($source, $destination, $overwrite = false, $mode = false) { if ( ! $overwrite && $this->exists($destination) ) return false; $content = $this->get_contents($source); if ( false === $content) return false; - return $this->put_contents($destination, $content); + return $this->put_contents($destination, $content, $mode); } function move($source, $destination, $overwrite = false) { return @ssh2_sftp_rename($this->link, $source, $destination); } - function delete($file, $recursive = false) { - if ( $this->is_file($file) ) + function delete($file, $recursive = false, $type = false) { + if ( 'f' == $type || $this->is_file($file) ) return ssh2_sftp_unlink($this->sftp_link, $file); if ( ! $recursive ) return ssh2_sftp_rmdir($this->sftp_link, $file); $filelist = $this->dirlist($file); if ( is_array($filelist) ) { foreach ( $filelist as $filename => $fileinfo) { - $this->delete($file . '/' . $filename, $recursive); + $this->delete($file . '/' . $filename, $recursive, $fileinfo['type']); } } return ssh2_sftp_rmdir($this->sftp_link, $file); diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 20d1361618..f330c3fa2f 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -80,9 +80,9 @@ function get_home_path() { $home = get_option( 'home' ); $siteurl = get_option( 'siteurl' ); if ( $home != '' && $home != $siteurl ) { - $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */ - $pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home); - $home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos); + $wp_path_rel_to_home = str_replace($home, '', $siteurl); /* $siteurl - $home */ + $pos = strpos($_SERVER["SCRIPT_FILENAME"], $wp_path_rel_to_home); + $home_path = substr($_SERVER["SCRIPT_FILENAME"], 0, $pos); $home_path = trailingslashit( $home_path ); } else { $home_path = ABSPATH; @@ -773,13 +773,12 @@ function copy_dir($from, $to) { foreach ( (array) $dirlist as $filename => $fileinfo ) { if ( 'f' == $fileinfo['type'] ) { - if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) ) { + if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) { // If copy failed, chmod file to 0644 and try again. $wp_filesystem->chmod($to . $filename, 0644); - if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true) ) + if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename); } - $wp_filesystem->chmod($to . $filename, FS_CHMOD_FILE); } elseif ( 'd' == $fileinfo['type'] ) { if ( !$wp_filesystem->is_dir($to . $filename) ) { if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )