Direct file system manip fixes, should fix .svn upgrade problem. Hat tip: DD32.
git-svn-id: http://svn.automattic.com/wordpress/trunk@7641 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
81370476f4
commit
43c3c8ef36
|
@ -26,8 +26,7 @@ class WP_Filesystem_Direct{
|
||||||
return @file($file);
|
return @file($file);
|
||||||
}
|
}
|
||||||
function put_contents($file,$contents,$mode=false,$type=''){
|
function put_contents($file,$contents,$mode=false,$type=''){
|
||||||
$fp=@fopen($file,'w'.$type);
|
if ( ! ($fp = @fopen($file,'w'.$type)) )
|
||||||
if (!$fp)
|
|
||||||
return false;
|
return false;
|
||||||
@fwrite($fp,$contents);
|
@fwrite($fp,$contents);
|
||||||
@fclose($fp);
|
@fclose($fp);
|
||||||
|
@ -37,6 +36,9 @@ class WP_Filesystem_Direct{
|
||||||
function cwd(){
|
function cwd(){
|
||||||
return @getcwd();
|
return @getcwd();
|
||||||
}
|
}
|
||||||
|
function chdir($dir){
|
||||||
|
return @chdir($dir);
|
||||||
|
}
|
||||||
function chgrp($file,$group,$recursive=false){
|
function chgrp($file,$group,$recursive=false){
|
||||||
if( ! $this->exists($file) )
|
if( ! $this->exists($file) )
|
||||||
return false;
|
return false;
|
||||||
|
@ -45,10 +47,11 @@ class WP_Filesystem_Direct{
|
||||||
if( ! $this->is_dir($file) )
|
if( ! $this->is_dir($file) )
|
||||||
return @chgrp($file,$group);
|
return @chgrp($file,$group);
|
||||||
//Is a directory, and we want recursive
|
//Is a directory, and we want recursive
|
||||||
|
$file = trailingshashit($file);
|
||||||
$filelist = $this->dirlist($file);
|
$filelist = $this->dirlist($file);
|
||||||
foreach($filelist as $filename){
|
foreach($filelist as $filename)
|
||||||
$this->chgrp($file.'/'.$filename,$group,$recursive);
|
$this->chgrp($file . $filename, $group, $recursive);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function chmod($file,$mode=false,$recursive=false){
|
function chmod($file,$mode=false,$recursive=false){
|
||||||
|
@ -61,10 +64,11 @@ class WP_Filesystem_Direct{
|
||||||
if( ! $this->is_dir($file) )
|
if( ! $this->is_dir($file) )
|
||||||
return @chmod($file,$mode);
|
return @chmod($file,$mode);
|
||||||
//Is a directory, and we want recursive
|
//Is a directory, and we want recursive
|
||||||
|
$file = trailingshashit($file);
|
||||||
$filelist = $this->dirlist($file);
|
$filelist = $this->dirlist($file);
|
||||||
foreach($filelist as $filename){
|
foreach($filelist as $filename)
|
||||||
$this->chmod($file.'/'.$filename,$mode,$recursive);
|
$this->chmod($file . $filename, $mode, $recursive);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function chown($file,$owner,$recursive=false){
|
function chown($file,$owner,$recursive=false){
|
||||||
|
@ -82,12 +86,12 @@ class WP_Filesystem_Direct{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function owner($file){
|
function owner($file){
|
||||||
$owneruid=@fileowner($file);
|
$owneruid = @fileowner($file);
|
||||||
if( ! $owneruid )
|
if( ! $owneruid )
|
||||||
return false;
|
return false;
|
||||||
if( !function_exists('posix_getpwuid') )
|
if( !function_exists('posix_getpwuid') )
|
||||||
return $owneruid;
|
return $owneruid;
|
||||||
$ownerarray=posix_getpwuid($owneruid);
|
$ownerarray = posix_getpwuid($owneruid);
|
||||||
return $ownerarray['name'];
|
return $ownerarray['name'];
|
||||||
}
|
}
|
||||||
function getchmod($file){
|
function getchmod($file){
|
||||||
|
@ -163,12 +167,12 @@ class WP_Filesystem_Direct{
|
||||||
return $newmode;
|
return $newmode;
|
||||||
}
|
}
|
||||||
function group($file){
|
function group($file){
|
||||||
$gid=@filegroup($file);
|
$gid = @filegroup($file);
|
||||||
if( ! $gid )
|
if( ! $gid )
|
||||||
return false;
|
return false;
|
||||||
if( !function_exists('posix_getgrgid') )
|
if( !function_exists('posix_getgrgid') )
|
||||||
return $gid;
|
return $gid;
|
||||||
$grouparray=posix_getgrgid($gid);
|
$grouparray = posix_getgrgid($gid);
|
||||||
return $grouparray['name'];
|
return $grouparray['name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +183,7 @@ class WP_Filesystem_Direct{
|
||||||
}
|
}
|
||||||
|
|
||||||
function move($source,$destination,$overwrite=false){
|
function move($source,$destination,$overwrite=false){
|
||||||
//Possible to use rename()
|
//Possible to use rename()?
|
||||||
if( $this->copy($source,$destination,$overwrite) && $this->exists($destination) ){
|
if( $this->copy($source,$destination,$overwrite) && $this->exists($destination) ){
|
||||||
$this->delete($source);
|
$this->delete($source);
|
||||||
return true;
|
return true;
|
||||||
|
@ -188,24 +192,24 @@ class WP_Filesystem_Direct{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($file,$recursive=false){
|
function delete($file, $recursive=false){
|
||||||
$file = str_replace('\\','/',$file); //for win32, occasional problems deleteing files otherwise
|
$file = str_replace('\\','/',$file); //for win32, occasional problems deleteing files otherwise
|
||||||
|
|
||||||
if( $this->is_file($file) )
|
if( $this->is_file($file) )
|
||||||
return @unlink($file);
|
return @unlink($file);
|
||||||
|
|
||||||
if( !$recursive && $this->is_dir($file) )
|
if( !$recursive && $this->is_dir($file) )
|
||||||
return @rmdir($file);
|
return @rmdir($file);
|
||||||
|
|
||||||
$filelist = $this->dirlist($file);
|
//At this point its a folder, and we're in recursive mode
|
||||||
if( ! $filelist )
|
$file = trailingslashit($file);
|
||||||
return true; //No files exist, Say we've deleted them
|
$filelist = $this->dirlist($file, true);
|
||||||
|
|
||||||
$retval = true;
|
$retval = true;
|
||||||
foreach($filelist as $filename=>$fileinfo){
|
if( is_array($filelist) ) //false if no files, So check first.
|
||||||
if( ! $this->delete($file.'/'.$filename,$recursive) )
|
foreach($filelist as $filename=>$fileinfo)
|
||||||
$retval = false;
|
if( ! $this->delete($file . $filename, $recursive) )
|
||||||
}
|
$retval = false;
|
||||||
|
|
||||||
if( ! @rmdir($file) )
|
if( ! @rmdir($file) )
|
||||||
return false;
|
return false;
|
||||||
return $retval;
|
return $retval;
|
||||||
|
@ -224,7 +228,7 @@ class WP_Filesystem_Direct{
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_readable($file){
|
function is_readable($file){
|
||||||
return @is_readable($file);
|
return @is_readable($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_writable($file){
|
function is_writable($file){
|
||||||
|
@ -242,15 +246,15 @@ class WP_Filesystem_Direct{
|
||||||
return @filesize($file);
|
return @filesize($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
function touch($file,$time=0,$atime=0){
|
function touch($file, $time = 0, $atime = 0){
|
||||||
if($time==0)
|
if($time == 0)
|
||||||
$time = time();
|
$time = time();
|
||||||
if($atime==0)
|
if($atime == 0)
|
||||||
$atime = time();
|
$atime = time();
|
||||||
return @touch($file,$time,$atime);
|
return @touch($file,$time,$atime);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
|
function mkdir($path, $chmod = false, $chown = false, $chgrp = false){
|
||||||
if( ! $chmod)
|
if( ! $chmod)
|
||||||
$chmod = $this->permission;
|
$chmod = $this->permission;
|
||||||
|
|
||||||
|
@ -264,6 +268,7 @@ class WP_Filesystem_Direct{
|
||||||
}
|
}
|
||||||
|
|
||||||
function rmdir($path,$recursive=false){
|
function rmdir($path,$recursive=false){
|
||||||
|
//Currently unused and untested, Use delete() instead.
|
||||||
if( ! $recursive )
|
if( ! $recursive )
|
||||||
return @rmdir($path);
|
return @rmdir($path);
|
||||||
//recursive:
|
//recursive:
|
||||||
|
@ -292,6 +297,8 @@ class WP_Filesystem_Direct{
|
||||||
$struc = array();
|
$struc = array();
|
||||||
$struc['name'] = $entry;
|
$struc['name'] = $entry;
|
||||||
|
|
||||||
|
if( '.' == $struc['name'] || '..' == $struc['name'] )
|
||||||
|
continue; //Do not care about these folders.
|
||||||
if( '.' == $struc['name'][0] && !$incdot)
|
if( '.' == $struc['name'][0] && !$incdot)
|
||||||
continue;
|
continue;
|
||||||
if( $limitFile && $struc['name'] != $limitFile)
|
if( $limitFile && $struc['name'] != $limitFile)
|
||||||
|
@ -307,22 +314,15 @@ class WP_Filesystem_Direct{
|
||||||
$struc['lastmod'] = date('M j',$struc['lastmodunix']);
|
$struc['lastmod'] = date('M j',$struc['lastmodunix']);
|
||||||
$struc['time'] = date('h:i:s',$struc['lastmodunix']);
|
$struc['time'] = date('h:i:s',$struc['lastmodunix']);
|
||||||
$struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f';
|
$struc['type'] = $this->is_dir($path.'/'.$entry) ? 'd' : 'f';
|
||||||
if ('d' == $struc['type'] ){
|
|
||||||
$struc['files'] = array();
|
|
||||||
|
|
||||||
if( $incdot ){
|
if ('d' == $struc['type'] ){
|
||||||
//We're including the doted starts
|
if( $recursive )
|
||||||
if( '.' != $struc['name'] && '..' != $struc['name'] ){ //Ok, It isnt a special folder
|
$struc['files'] = $this->dirlist($path.'/'.$struc['name'], $incdot, $recursive);
|
||||||
if ($recursive)
|
else
|
||||||
$struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
|
$struc['files'] = array();
|
||||||
}
|
|
||||||
} else { //No dots
|
|
||||||
if ($recursive)
|
|
||||||
$struc['files'] = $this->dirlist($path.'/'.$struc['name'],$incdot,$recursive);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//File
|
|
||||||
$ret[$struc['name']] = $struc;
|
$ret[ $struc['name'] ] = $struc;
|
||||||
}
|
}
|
||||||
$dir->close();
|
$dir->close();
|
||||||
unset($dir);
|
unset($dir);
|
||||||
|
|
Loading…
Reference in New Issue