X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilebackend%2FFSFileBackend.php;h=993e2bac49420e04301374a7a5bdcb3d60b21135;hb=34a4bcbd48bf7af458eb110cc383c5bbb6989a31;hp=6d6421627ebf78f7024d1f9e6ebffa77fe3a9776;hpb=7113a5d0a5592c016f6dd57e1de002b8263c0bc9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filebackend/FSFileBackend.php b/includes/filebackend/FSFileBackend.php index 6d6421627e..993e2bac49 100644 --- a/includes/filebackend/FSFileBackend.php +++ b/includes/filebackend/FSFileBackend.php @@ -39,14 +39,22 @@ * @since 1.19 */ class FSFileBackend extends FileBackendStore { - protected $basePath; // string; directory holding the container directories - /** @var Array Map of container names to root paths */ - protected $containerPaths = array(); // for custom container paths - protected $fileMode; // integer; file permission mode - protected $fileOwner; // string; required OS username to own files - protected $currentUser; // string; OS username running this script - - /** @var Array */ + /** @var string Directory holding the container directories */ + protected $basePath; + + /** @var array Map of container names to root paths for custom container paths */ + protected $containerPaths = array(); + + /** @var int File permission mode */ + protected $fileMode; + + /** @var string Required OS username to own files */ + protected $fileOwner; + + /** @var string OS username running this script */ + protected $currentUser; + + /** @var array */ protected $hadWarningErrors = array(); /** @@ -90,6 +98,7 @@ class FSFileBackend extends FileBackendStore { return $relStoragePath; } } + return null; } @@ -125,6 +134,7 @@ class FSFileBackend extends FileBackendStore { } elseif ( isset( $this->basePath ) ) { return "{$this->basePath}/{$fullCont}"; } + return null; // no container base path defined } @@ -144,6 +154,7 @@ class FSFileBackend extends FileBackendStore { if ( $relPath != '' ) { $fsPath .= "/{$relPath}"; } + return $fsPath; } @@ -174,6 +185,7 @@ class FSFileBackend extends FileBackendStore { $dest = $this->resolveToFSPath( $params['dst'] ); if ( $dest === null ) { $status->fatal( 'backend-fail-invalidpath', $params['dst'] ); + return $status; } @@ -181,6 +193,7 @@ class FSFileBackend extends FileBackendStore { $tempFile = TempFSFile::factory( 'create_', 'tmp' ); if ( !$tempFile ) { $status->fatal( 'backend-fail-create', $params['dst'] ); + return $status; } $this->trapWarnings(); @@ -188,6 +201,7 @@ class FSFileBackend extends FileBackendStore { $this->untrapWarnings(); if ( $bytes === false ) { $status->fatal( 'backend-fail-create', $params['dst'] ); + return $status; } $cmd = implode( ' ', array( @@ -203,6 +217,7 @@ class FSFileBackend extends FileBackendStore { $this->untrapWarnings(); if ( $bytes === false ) { $status->fatal( 'backend-fail-create', $params['dst'] ); + return $status; } $this->chmod( $dest ); @@ -227,6 +242,7 @@ class FSFileBackend extends FileBackendStore { $dest = $this->resolveToFSPath( $params['dst'] ); if ( $dest === null ) { $status->fatal( 'backend-fail-invalidpath', $params['dst'] ); + return $status; } @@ -248,6 +264,7 @@ class FSFileBackend extends FileBackendStore { trigger_error( __METHOD__ . ": copy() failed but returned true." ); } $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] ); + return $status; } $this->chmod( $dest ); @@ -272,12 +289,14 @@ class FSFileBackend extends FileBackendStore { $source = $this->resolveToFSPath( $params['src'] ); if ( $source === null ) { $status->fatal( 'backend-fail-invalidpath', $params['src'] ); + return $status; } $dest = $this->resolveToFSPath( $params['dst'] ); if ( $dest === null ) { $status->fatal( 'backend-fail-invalidpath', $params['dst'] ); + return $status; } @@ -285,6 +304,7 @@ class FSFileBackend extends FileBackendStore { if ( empty( $params['ignoreMissingSource'] ) ) { $status->fatal( 'backend-fail-copy', $params['src'] ); } + return $status; // do nothing; either OK or bad status } @@ -308,6 +328,7 @@ class FSFileBackend extends FileBackendStore { trigger_error( __METHOD__ . ": copy() failed but returned true." ); } $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] ); + return $status; } $this->chmod( $dest ); @@ -332,12 +353,14 @@ class FSFileBackend extends FileBackendStore { $source = $this->resolveToFSPath( $params['src'] ); if ( $source === null ) { $status->fatal( 'backend-fail-invalidpath', $params['src'] ); + return $status; } $dest = $this->resolveToFSPath( $params['dst'] ); if ( $dest === null ) { $status->fatal( 'backend-fail-invalidpath', $params['dst'] ); + return $status; } @@ -345,6 +368,7 @@ class FSFileBackend extends FileBackendStore { if ( empty( $params['ignoreMissingSource'] ) ) { $status->fatal( 'backend-fail-move', $params['src'] ); } + return $status; // do nothing; either OK or bad status } @@ -362,6 +386,7 @@ class FSFileBackend extends FileBackendStore { clearstatcache(); // file no longer at source if ( !$ok ) { $status->fatal( 'backend-fail-move', $params['src'], $params['dst'] ); + return $status; } } @@ -385,6 +410,7 @@ class FSFileBackend extends FileBackendStore { $source = $this->resolveToFSPath( $params['src'] ); if ( $source === null ) { $status->fatal( 'backend-fail-invalidpath', $params['src'] ); + return $status; } @@ -392,6 +418,7 @@ class FSFileBackend extends FileBackendStore { if ( empty( $params['ignoreMissingSource'] ) ) { $status->fatal( 'backend-fail-delete', $params['src'] ); } + return $status; // do nothing; either OK or bad status } @@ -407,6 +434,7 @@ class FSFileBackend extends FileBackendStore { $this->untrapWarnings(); if ( !$ok ) { $status->fatal( 'backend-fail-delete', $params['src'] ); + return $status; } } @@ -424,6 +452,12 @@ class FSFileBackend extends FileBackendStore { } } + /** + * @param string $fullCont + * @param $dirRel + * @param array $params + * @return Status + */ protected function doPrepareInternal( $fullCont, $dirRel, array $params ) { $status = Status::newGood(); list( , $shortCont, ) = FileBackend::splitStoragePath( $params['dir'] ); @@ -444,6 +478,7 @@ class FSFileBackend extends FileBackendStore { if ( is_dir( $dir ) && !$existed ) { $status->merge( $this->doSecureInternal( $fullCont, $dirRel, $params ) ); } + return $status; } @@ -471,6 +506,7 @@ class FSFileBackend extends FileBackendStore { $status->fatal( 'backend-fail-create', "{$storeDir}/.htaccess" ); } } + return $status; } @@ -498,6 +534,7 @@ class FSFileBackend extends FileBackendStore { } $this->untrapWarnings(); } + return $status; } @@ -511,6 +548,7 @@ class FSFileBackend extends FileBackendStore { rmdir( $dir ); // remove directory if empty } $this->untrapWarnings(); + return $status; } @@ -557,7 +595,10 @@ class FSFileBackend extends FileBackendStore { /** * @see FileBackendStore::getDirectoryListInternal() - * @return Array|null + * @param string $fullCont + * @param string $dirRel + * @param array $params + * @return array|null */ public function getDirectoryListInternal( $fullCont, $dirRel, array $params ) { list( , $shortCont, ) = FileBackend::splitStoragePath( $params['dir'] ); @@ -566,17 +607,23 @@ class FSFileBackend extends FileBackendStore { $exists = is_dir( $dir ); if ( !$exists ) { wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" ); + return array(); // nothing under this dir } elseif ( !is_readable( $dir ) ) { wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" ); + return null; // bad permissions? } + return new FSFileBackendDirList( $dir, $params ); } /** * @see FileBackendStore::getFileListInternal() - * @return Array|FSFileBackendFileList|null + * @param string $fullCont + * @param string $dirRel + * @param array $params + * @return array|FSFileBackendFileList|null */ public function getFileListInternal( $fullCont, $dirRel, array $params ) { list( , $shortCont, ) = FileBackend::splitStoragePath( $params['dir'] ); @@ -585,11 +632,14 @@ class FSFileBackend extends FileBackendStore { $exists = is_dir( $dir ); if ( !$exists ) { wfDebug( __METHOD__ . "() given directory does not exist: '$dir'\n" ); + return array(); // nothing under this dir } elseif ( !is_readable( $dir ) ) { wfDebug( __METHOD__ . "() given directory is unreadable: '$dir'\n" ); + return null; // bad permissions? } + return new FSFileBackendFileList( $dir, $params ); } @@ -718,8 +768,6 @@ class FSFileBackend extends FileBackendStore { /** * Listen for E_WARNING errors and track whether any happen - * - * @return void */ protected function trapWarnings() { $this->hadWarningErrors[] = false; // push to stack @@ -737,7 +785,7 @@ class FSFileBackend extends FileBackendStore { } /** - * @param integer $errno + * @param int $errno * @param string $errstr * @return bool * @access private @@ -745,6 +793,7 @@ class FSFileBackend extends FileBackendStore { public function handleWarning( $errno, $errstr ) { wfDebugLog( 'FSFileBackend', $errstr ); // more detailed error logging $this->hadWarningErrors[count( $this->hadWarningErrors ) - 1] = true; + return true; // suppress from PHP handler } } @@ -761,7 +810,7 @@ class FSFileOpHandle extends FileBackendStoreOpHandle { * @param array $params * @param string $call * @param string $cmd - * @param integer|null $chmodPath + * @param int|null $chmodPath */ public function __construct( FSFileBackend $backend, array $params, $call, $cmd, $chmodPath = null @@ -784,9 +833,14 @@ class FSFileOpHandle extends FileBackendStoreOpHandle { abstract class FSFileBackendList implements Iterator { /** @var Iterator */ protected $iter; - protected $suffixStart; // integer - protected $pos = 0; // integer - /** @var Array */ + + /** @var int */ + protected $suffixStart; + + /** @var int */ + protected $pos = 0; + + /** @var array */ protected $params = array(); /** @@ -823,6 +877,7 @@ abstract class FSFileBackendList implements Iterator { # RecursiveDirectoryIterator extends FilesystemIterator. # FilesystemIterator::SKIP_DOTS default is inconsistent in PHP 5.3.x. $flags = FilesystemIterator::CURRENT_AS_SELF | FilesystemIterator::SKIP_DOTS; + return new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $dir, $flags ), RecursiveIteratorIterator::CHILD_FIRST // include dirs @@ -832,7 +887,7 @@ abstract class FSFileBackendList implements Iterator { /** * @see Iterator::key() - * @return integer + * @return int */ public function key() { return $this->pos; @@ -848,7 +903,7 @@ abstract class FSFileBackendList implements Iterator { /** * @see Iterator::next() - * @return void + * @throws FileBackendError */ public function next() { try { @@ -862,7 +917,7 @@ abstract class FSFileBackendList implements Iterator { /** * @see Iterator::rewind() - * @return void + * @throws FileBackendError */ public function rewind() { $this->pos = 0; @@ -885,13 +940,14 @@ abstract class FSFileBackendList implements Iterator { /** * Filter out items by advancing to the next ones */ - protected function filterViaNext() {} + protected function filterViaNext() { + } /** * Return only the relative path and normalize slashes to FileBackend-style. * Uses the "real path" since the suffix is based upon that. * - * @param string $path + * @param string $dir * @return string */ protected function getRelPath( $dir ) { @@ -899,6 +955,7 @@ abstract class FSFileBackendList implements Iterator { if ( $path === false ) { $path = $dir; } + return strtr( substr( $path, $this->suffixStart ), '\\', '/' ); } }