From: Aaron Schulz Date: Mon, 15 Apr 2019 09:30:24 +0000 (-0700) Subject: filebackend: move more files to subdirectories X-Git-Tag: 1.34.0-rc.0~1975 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=950c1c32467c64b87416a00b65ee2caf2f0e2580;p=lhc%2Fweb%2Fwiklou.git filebackend: move more files to subdirectories Change-Id: If965323809c5bfc9cb73ed0f357233d9325d3353 --- diff --git a/autoload.php b/autoload.php index f1668a1e9d..ab36d84157 100644 --- a/autoload.php +++ b/autoload.php @@ -487,10 +487,10 @@ $wgAutoloadLocalClasses = [ 'ExternalUserNames' => __DIR__ . '/includes/user/ExternalUserNames.php', 'FSFile' => __DIR__ . '/includes/libs/filebackend/fsfile/FSFile.php', 'FSFileBackend' => __DIR__ . '/includes/libs/filebackend/FSFileBackend.php', - 'FSFileBackendDirList' => __DIR__ . '/includes/libs/filebackend/FSFileBackendDirList.php', - 'FSFileBackendFileList' => __DIR__ . '/includes/libs/filebackend/FSFileBackendFileList.php', - 'FSFileBackendList' => __DIR__ . '/includes/libs/filebackend/FSFileBackendList.php', - 'FSFileOpHandle' => __DIR__ . '/includes/libs/filebackend/FSFileOpHandle.php', + 'FSFileBackendDirList' => __DIR__ . '/includes/libs/filebackend/fileiteration/FSFileBackendDirList.php', + 'FSFileBackendFileList' => __DIR__ . '/includes/libs/filebackend/fileiteration/FSFileBackendFileList.php', + 'FSFileBackendList' => __DIR__ . '/includes/libs/filebackend/fileiteration/FSFileBackendList.php', + 'FSFileOpHandle' => __DIR__ . '/includes/libs/filebackend/fileophandle/FSFileOpHandle.php', 'FSLockManager' => __DIR__ . '/includes/libs/lockmanager/FSLockManager.php', 'FakeConverter' => __DIR__ . '/languages/FakeConverter.php', 'FakeMaintenance' => __DIR__ . '/maintenance/Maintenance.php', @@ -507,14 +507,14 @@ $wgAutoloadLocalClasses = [ 'FileAwareNodeVisitor' => __DIR__ . '/maintenance/findDeprecated.php', 'FileBackend' => __DIR__ . '/includes/libs/filebackend/FileBackend.php', 'FileBackendDBRepoWrapper' => __DIR__ . '/includes/filerepo/FileBackendDBRepoWrapper.php', - 'FileBackendError' => __DIR__ . '/includes/libs/filebackend/FileBackendError.php', + 'FileBackendError' => __DIR__ . '/includes/libs/filebackend/exception/FileBackendError.php', 'FileBackendGroup' => __DIR__ . '/includes/filebackend/FileBackendGroup.php', 'FileBackendMultiWrite' => __DIR__ . '/includes/libs/filebackend/FileBackendMultiWrite.php', 'FileBackendStore' => __DIR__ . '/includes/libs/filebackend/FileBackendStore.php', - 'FileBackendStoreOpHandle' => __DIR__ . '/includes/libs/filebackend/FileBackendStoreOpHandle.php', - 'FileBackendStoreShardDirIterator' => __DIR__ . '/includes/libs/filebackend/FileBackendStoreShardDirIterator.php', - 'FileBackendStoreShardFileIterator' => __DIR__ . '/includes/libs/filebackend/FileBackendStoreShardFileIterator.php', - 'FileBackendStoreShardListIterator' => __DIR__ . '/includes/libs/filebackend/FileBackendStoreShardListIterator.php', + 'FileBackendStoreOpHandle' => __DIR__ . '/includes/libs/filebackend/fileophandle/FileBackendStoreOpHandle.php', + 'FileBackendStoreShardDirIterator' => __DIR__ . '/includes/libs/filebackend/fileiteration/FileBackendStoreShardDirIterator.php', + 'FileBackendStoreShardFileIterator' => __DIR__ . '/includes/libs/filebackend/fileiteration/FileBackendStoreShardFileIterator.php', + 'FileBackendStoreShardListIterator' => __DIR__ . '/includes/libs/filebackend/fileiteration/FileBackendStoreShardListIterator.php', 'FileBasedSiteLookup' => __DIR__ . '/includes/site/FileBasedSiteLookup.php', 'FileCacheBase' => __DIR__ . '/includes/cache/FileCacheBase.php', 'FileContentHandler' => __DIR__ . '/includes/content/FileContentHandler.php', @@ -1455,10 +1455,10 @@ $wgAutoloadLocalClasses = [ 'SubpageImportTitleFactory' => __DIR__ . '/includes/title/SubpageImportTitleFactory.php', 'SvgHandler' => __DIR__ . '/includes/media/SvgHandler.php', 'SwiftFileBackend' => __DIR__ . '/includes/libs/filebackend/SwiftFileBackend.php', - 'SwiftFileBackendDirList' => __DIR__ . '/includes/libs/filebackend/SwiftFileBackendDirList.php', - 'SwiftFileBackendFileList' => __DIR__ . '/includes/libs/filebackend/SwiftFileBackendFileList.php', - 'SwiftFileBackendList' => __DIR__ . '/includes/libs/filebackend/SwiftFileBackendList.php', - 'SwiftFileOpHandle' => __DIR__ . '/includes/libs/filebackend/SwiftFileOpHandle.php', + 'SwiftFileBackendDirList' => __DIR__ . '/includes/libs/filebackend/fileiteration/SwiftFileBackendDirList.php', + 'SwiftFileBackendFileList' => __DIR__ . '/includes/libs/filebackend/fileiteration/SwiftFileBackendFileList.php', + 'SwiftFileBackendList' => __DIR__ . '/includes/libs/filebackend/fileiteration/SwiftFileBackendList.php', + 'SwiftFileOpHandle' => __DIR__ . '/includes/libs/filebackend/fileophandle/SwiftFileOpHandle.php', 'SwiftVirtualRESTService' => __DIR__ . '/includes/libs/virtualrest/SwiftVirtualRESTService.php', 'SyncFileBackend' => __DIR__ . '/maintenance/syncFileBackend.php', 'TableCleanup' => __DIR__ . '/maintenance/cleanupTable.inc', diff --git a/includes/libs/filebackend/FSFileBackendDirList.php b/includes/libs/filebackend/FSFileBackendDirList.php deleted file mode 100644 index 0545d9ff25..0000000000 --- a/includes/libs/filebackend/FSFileBackendDirList.php +++ /dev/null @@ -1,32 +0,0 @@ -iter->valid() ) { - if ( $this->iter->current()->isDot() || !$this->iter->current()->isDir() ) { - $this->iter->next(); // skip non-directories and dot files - } else { - break; - } - } - } -} diff --git a/includes/libs/filebackend/FSFileBackendFileList.php b/includes/libs/filebackend/FSFileBackendFileList.php deleted file mode 100644 index 980e9999f9..0000000000 --- a/includes/libs/filebackend/FSFileBackendFileList.php +++ /dev/null @@ -1,32 +0,0 @@ -iter->valid() ) { - if ( !$this->iter->current()->isFile() ) { - $this->iter->next(); // skip non-files and dot files - } else { - break; - } - } - } -} diff --git a/includes/libs/filebackend/FSFileBackendList.php b/includes/libs/filebackend/FSFileBackendList.php deleted file mode 100644 index 9194efe131..0000000000 --- a/includes/libs/filebackend/FSFileBackendList.php +++ /dev/null @@ -1,157 +0,0 @@ -suffixStart = strlen( $path ) + 1; // size of "path/to/dir/" - $this->params = $params; - - try { - $this->iter = $this->initIterator( $path ); - } catch ( UnexpectedValueException $e ) { - $this->iter = null; // bad permissions? deleted? - } - } - - /** - * Return an appropriate iterator object to wrap - * - * @param string $dir File system directory - * @return Iterator - */ - protected function initIterator( $dir ) { - if ( !empty( $this->params['topOnly'] ) ) { // non-recursive - # Get an iterator that will get direct sub-nodes - return new DirectoryIterator( $dir ); - } else { // recursive - # Get an iterator that will return leaf nodes (non-directories) - # 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 - ); - } - } - - /** - * @see Iterator::key() - * @return int - */ - public function key() { - return $this->pos; - } - - /** - * @see Iterator::current() - * @return string|bool String or false - */ - public function current() { - return $this->getRelPath( $this->iter->current()->getPathname() ); - } - - /** - * @see Iterator::next() - * @throws FileBackendError - */ - public function next() { - try { - $this->iter->next(); - $this->filterViaNext(); - } catch ( UnexpectedValueException $e ) { // bad permissions? deleted? - throw new FileBackendError( "File iterator gave UnexpectedValueException." ); - } - ++$this->pos; - } - - /** - * @see Iterator::rewind() - * @throws FileBackendError - */ - public function rewind() { - $this->pos = 0; - try { - $this->iter->rewind(); - $this->filterViaNext(); - } catch ( UnexpectedValueException $e ) { // bad permissions? deleted? - throw new FileBackendError( "File iterator gave UnexpectedValueException." ); - } - } - - /** - * @see Iterator::valid() - * @return bool - */ - public function valid() { - return $this->iter && $this->iter->valid(); - } - - /** - * Filter out items by advancing to the next ones - */ - 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 $dir - * @return string - */ - protected function getRelPath( $dir ) { - $path = realpath( $dir ); - if ( $path === false ) { - $path = $dir; - } - - return strtr( substr( $path, $this->suffixStart ), '\\', '/' ); - } -} diff --git a/includes/libs/filebackend/FSFileOpHandle.php b/includes/libs/filebackend/FSFileOpHandle.php deleted file mode 100644 index 2d65c434a1..0000000000 --- a/includes/libs/filebackend/FSFileOpHandle.php +++ /dev/null @@ -1,45 +0,0 @@ -backend = $backend; - $this->params = $params; - $this->call = $call; - $this->cmd = $cmd; - $this->chmodPath = $chmodPath; - } -} diff --git a/includes/libs/filebackend/FileBackendError.php b/includes/libs/filebackend/FileBackendError.php deleted file mode 100644 index e233535102..0000000000 --- a/includes/libs/filebackend/FileBackendError.php +++ /dev/null @@ -1,9 +0,0 @@ -resourcesToClose ); - } -} diff --git a/includes/libs/filebackend/FileBackendStoreShardDirIterator.php b/includes/libs/filebackend/FileBackendStoreShardDirIterator.php deleted file mode 100644 index cd8ebff06c..0000000000 --- a/includes/libs/filebackend/FileBackendStoreShardDirIterator.php +++ /dev/null @@ -1,35 +0,0 @@ -backend->getDirectoryListInternal( - $container, $this->directory, $this->params ); - if ( $list === null ) { - return new ArrayIterator( [] ); - } else { - return is_array( $list ) ? new ArrayIterator( $list ) : $list; - } - } -} diff --git a/includes/libs/filebackend/FileBackendStoreShardFileIterator.php b/includes/libs/filebackend/FileBackendStoreShardFileIterator.php deleted file mode 100644 index d65a5d71a0..0000000000 --- a/includes/libs/filebackend/FileBackendStoreShardFileIterator.php +++ /dev/null @@ -1,35 +0,0 @@ -backend->getFileListInternal( - $container, $this->directory, $this->params ); - if ( $list === null ) { - return new ArrayIterator( [] ); - } else { - return is_array( $list ) ? new ArrayIterator( $list ) : $list; - } - } -} diff --git a/includes/libs/filebackend/FileBackendStoreShardListIterator.php b/includes/libs/filebackend/FileBackendStoreShardListIterator.php deleted file mode 100644 index 5f6b762426..0000000000 --- a/includes/libs/filebackend/FileBackendStoreShardListIterator.php +++ /dev/null @@ -1,94 +0,0 @@ - 1) - - /** - * @param FileBackendStore $backend - * @param string $container Full storage container name - * @param string $dir Storage directory relative to container - * @param array $suffixes List of container shard suffixes - * @param array $params - */ - public function __construct( - FileBackendStore $backend, $container, $dir, array $suffixes, array $params - ) { - $this->backend = $backend; - $this->container = $container; - $this->directory = $dir; - $this->params = $params; - - $iter = new AppendIterator(); - foreach ( $suffixes as $suffix ) { - $iter->append( $this->listFromShard( $this->container . $suffix ) ); - } - - parent::__construct( $iter ); - } - - public function accept() { - $rel = $this->getInnerIterator()->current(); // path relative to given directory - $path = $this->params['dir'] . "/{$rel}"; // full storage path - if ( $this->backend->isSingleShardPathInternal( $path ) ) { - return true; // path is only on one shard; no issue with duplicates - } elseif ( isset( $this->multiShardPaths[$rel] ) ) { - // Don't keep listing paths that are on multiple shards - return false; - } else { - $this->multiShardPaths[$rel] = 1; - - return true; - } - } - - public function rewind() { - parent::rewind(); - $this->multiShardPaths = []; - } - - /** - * Get the list for a given container shard - * - * @param string $container Resolved container name - * @return Iterator - */ - abstract protected function listFromShard( $container ); -} diff --git a/includes/libs/filebackend/SwiftFileBackendDirList.php b/includes/libs/filebackend/SwiftFileBackendDirList.php deleted file mode 100644 index b0b784d389..0000000000 --- a/includes/libs/filebackend/SwiftFileBackendDirList.php +++ /dev/null @@ -1,40 +0,0 @@ -bufferIter ), $this->suffixStart, -1 ); - } - - protected function pageFromList( $container, $dir, &$after, $limit, array $params ) { - return $this->backend->getDirListPageInternal( $container, $dir, $after, $limit, $params ); - } -} diff --git a/includes/libs/filebackend/SwiftFileBackendFileList.php b/includes/libs/filebackend/SwiftFileBackendFileList.php deleted file mode 100644 index 045b8f878c..0000000000 --- a/includes/libs/filebackend/SwiftFileBackendFileList.php +++ /dev/null @@ -1,47 +0,0 @@ -bufferIter ); - $relPath = substr( $path, $this->suffixStart ); - if ( is_array( $stat ) ) { - $storageDir = rtrim( $this->params['dir'], '/' ); - $this->backend->loadListingStatInternal( "$storageDir/$relPath", $stat ); - } - - return $relPath; - } - - protected function pageFromList( $container, $dir, &$after, $limit, array $params ) { - return $this->backend->getFileListPageInternal( $container, $dir, $after, $limit, $params ); - } -} diff --git a/includes/libs/filebackend/SwiftFileBackendList.php b/includes/libs/filebackend/SwiftFileBackendList.php deleted file mode 100644 index bcde8d90a9..0000000000 --- a/includes/libs/filebackend/SwiftFileBackendList.php +++ /dev/null @@ -1,138 +0,0 @@ -backend = $backend; - $this->container = $fullCont; - $this->dir = $dir; - if ( substr( $this->dir, -1 ) === '/' ) { - $this->dir = substr( $this->dir, 0, -1 ); // remove trailing slash - } - if ( $this->dir == '' ) { // whole container - $this->suffixStart = 0; - } else { // dir within container - $this->suffixStart = strlen( $this->dir ) + 1; // size of "path/to/dir/" - } - $this->params = $params; - } - - /** - * @see Iterator::key() - * @return int - */ - public function key() { - return $this->pos; - } - - /** - * @see Iterator::next() - */ - public function next() { - // Advance to the next file in the page - next( $this->bufferIter ); - ++$this->pos; - // Check if there are no files left in this page and - // advance to the next page if this page was not empty. - if ( !$this->valid() && count( $this->bufferIter ) ) { - $this->bufferIter = $this->pageFromList( - $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params - ); // updates $this->bufferAfter - } - } - - /** - * @see Iterator::rewind() - */ - public function rewind() { - $this->pos = 0; - $this->bufferAfter = null; - $this->bufferIter = $this->pageFromList( - $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params - ); // updates $this->bufferAfter - } - - /** - * @see Iterator::valid() - * @return bool - */ - public function valid() { - if ( $this->bufferIter === null ) { - return false; // some failure? - } else { - return ( current( $this->bufferIter ) !== false ); // no paths can have this value - } - } - - /** - * Get the given list portion (page) - * - * @param string $container Resolved container name - * @param string $dir Resolved path relative to container - * @param string &$after - * @param int $limit - * @param array $params - * @return Traversable|array - */ - abstract protected function pageFromList( $container, $dir, &$after, $limit, array $params ); -} diff --git a/includes/libs/filebackend/SwiftFileOpHandle.php b/includes/libs/filebackend/SwiftFileOpHandle.php deleted file mode 100644 index 1119867800..0000000000 --- a/includes/libs/filebackend/SwiftFileOpHandle.php +++ /dev/null @@ -1,44 +0,0 @@ -backend = $backend; - $this->callback = $callback; - $this->httpOp = $httpOp; - } -} diff --git a/includes/libs/filebackend/exception/FileBackendError.php b/includes/libs/filebackend/exception/FileBackendError.php new file mode 100644 index 0000000000..e233535102 --- /dev/null +++ b/includes/libs/filebackend/exception/FileBackendError.php @@ -0,0 +1,9 @@ +iter->valid() ) { + if ( $this->iter->current()->isDot() || !$this->iter->current()->isDir() ) { + $this->iter->next(); // skip non-directories and dot files + } else { + break; + } + } + } +} diff --git a/includes/libs/filebackend/fileiteration/FSFileBackendFileList.php b/includes/libs/filebackend/fileiteration/FSFileBackendFileList.php new file mode 100644 index 0000000000..980e9999f9 --- /dev/null +++ b/includes/libs/filebackend/fileiteration/FSFileBackendFileList.php @@ -0,0 +1,32 @@ +iter->valid() ) { + if ( !$this->iter->current()->isFile() ) { + $this->iter->next(); // skip non-files and dot files + } else { + break; + } + } + } +} diff --git a/includes/libs/filebackend/fileiteration/FSFileBackendList.php b/includes/libs/filebackend/fileiteration/FSFileBackendList.php new file mode 100644 index 0000000000..9194efe131 --- /dev/null +++ b/includes/libs/filebackend/fileiteration/FSFileBackendList.php @@ -0,0 +1,157 @@ +suffixStart = strlen( $path ) + 1; // size of "path/to/dir/" + $this->params = $params; + + try { + $this->iter = $this->initIterator( $path ); + } catch ( UnexpectedValueException $e ) { + $this->iter = null; // bad permissions? deleted? + } + } + + /** + * Return an appropriate iterator object to wrap + * + * @param string $dir File system directory + * @return Iterator + */ + protected function initIterator( $dir ) { + if ( !empty( $this->params['topOnly'] ) ) { // non-recursive + # Get an iterator that will get direct sub-nodes + return new DirectoryIterator( $dir ); + } else { // recursive + # Get an iterator that will return leaf nodes (non-directories) + # 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 + ); + } + } + + /** + * @see Iterator::key() + * @return int + */ + public function key() { + return $this->pos; + } + + /** + * @see Iterator::current() + * @return string|bool String or false + */ + public function current() { + return $this->getRelPath( $this->iter->current()->getPathname() ); + } + + /** + * @see Iterator::next() + * @throws FileBackendError + */ + public function next() { + try { + $this->iter->next(); + $this->filterViaNext(); + } catch ( UnexpectedValueException $e ) { // bad permissions? deleted? + throw new FileBackendError( "File iterator gave UnexpectedValueException." ); + } + ++$this->pos; + } + + /** + * @see Iterator::rewind() + * @throws FileBackendError + */ + public function rewind() { + $this->pos = 0; + try { + $this->iter->rewind(); + $this->filterViaNext(); + } catch ( UnexpectedValueException $e ) { // bad permissions? deleted? + throw new FileBackendError( "File iterator gave UnexpectedValueException." ); + } + } + + /** + * @see Iterator::valid() + * @return bool + */ + public function valid() { + return $this->iter && $this->iter->valid(); + } + + /** + * Filter out items by advancing to the next ones + */ + 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 $dir + * @return string + */ + protected function getRelPath( $dir ) { + $path = realpath( $dir ); + if ( $path === false ) { + $path = $dir; + } + + return strtr( substr( $path, $this->suffixStart ), '\\', '/' ); + } +} diff --git a/includes/libs/filebackend/fileiteration/FileBackendStoreShardDirIterator.php b/includes/libs/filebackend/fileiteration/FileBackendStoreShardDirIterator.php new file mode 100644 index 0000000000..cd8ebff06c --- /dev/null +++ b/includes/libs/filebackend/fileiteration/FileBackendStoreShardDirIterator.php @@ -0,0 +1,35 @@ +backend->getDirectoryListInternal( + $container, $this->directory, $this->params ); + if ( $list === null ) { + return new ArrayIterator( [] ); + } else { + return is_array( $list ) ? new ArrayIterator( $list ) : $list; + } + } +} diff --git a/includes/libs/filebackend/fileiteration/FileBackendStoreShardFileIterator.php b/includes/libs/filebackend/fileiteration/FileBackendStoreShardFileIterator.php new file mode 100644 index 0000000000..d65a5d71a0 --- /dev/null +++ b/includes/libs/filebackend/fileiteration/FileBackendStoreShardFileIterator.php @@ -0,0 +1,35 @@ +backend->getFileListInternal( + $container, $this->directory, $this->params ); + if ( $list === null ) { + return new ArrayIterator( [] ); + } else { + return is_array( $list ) ? new ArrayIterator( $list ) : $list; + } + } +} diff --git a/includes/libs/filebackend/fileiteration/FileBackendStoreShardListIterator.php b/includes/libs/filebackend/fileiteration/FileBackendStoreShardListIterator.php new file mode 100644 index 0000000000..5f6b762426 --- /dev/null +++ b/includes/libs/filebackend/fileiteration/FileBackendStoreShardListIterator.php @@ -0,0 +1,94 @@ + 1) + + /** + * @param FileBackendStore $backend + * @param string $container Full storage container name + * @param string $dir Storage directory relative to container + * @param array $suffixes List of container shard suffixes + * @param array $params + */ + public function __construct( + FileBackendStore $backend, $container, $dir, array $suffixes, array $params + ) { + $this->backend = $backend; + $this->container = $container; + $this->directory = $dir; + $this->params = $params; + + $iter = new AppendIterator(); + foreach ( $suffixes as $suffix ) { + $iter->append( $this->listFromShard( $this->container . $suffix ) ); + } + + parent::__construct( $iter ); + } + + public function accept() { + $rel = $this->getInnerIterator()->current(); // path relative to given directory + $path = $this->params['dir'] . "/{$rel}"; // full storage path + if ( $this->backend->isSingleShardPathInternal( $path ) ) { + return true; // path is only on one shard; no issue with duplicates + } elseif ( isset( $this->multiShardPaths[$rel] ) ) { + // Don't keep listing paths that are on multiple shards + return false; + } else { + $this->multiShardPaths[$rel] = 1; + + return true; + } + } + + public function rewind() { + parent::rewind(); + $this->multiShardPaths = []; + } + + /** + * Get the list for a given container shard + * + * @param string $container Resolved container name + * @return Iterator + */ + abstract protected function listFromShard( $container ); +} diff --git a/includes/libs/filebackend/fileiteration/SwiftFileBackendDirList.php b/includes/libs/filebackend/fileiteration/SwiftFileBackendDirList.php new file mode 100644 index 0000000000..b0b784d389 --- /dev/null +++ b/includes/libs/filebackend/fileiteration/SwiftFileBackendDirList.php @@ -0,0 +1,40 @@ +bufferIter ), $this->suffixStart, -1 ); + } + + protected function pageFromList( $container, $dir, &$after, $limit, array $params ) { + return $this->backend->getDirListPageInternal( $container, $dir, $after, $limit, $params ); + } +} diff --git a/includes/libs/filebackend/fileiteration/SwiftFileBackendFileList.php b/includes/libs/filebackend/fileiteration/SwiftFileBackendFileList.php new file mode 100644 index 0000000000..045b8f878c --- /dev/null +++ b/includes/libs/filebackend/fileiteration/SwiftFileBackendFileList.php @@ -0,0 +1,47 @@ +bufferIter ); + $relPath = substr( $path, $this->suffixStart ); + if ( is_array( $stat ) ) { + $storageDir = rtrim( $this->params['dir'], '/' ); + $this->backend->loadListingStatInternal( "$storageDir/$relPath", $stat ); + } + + return $relPath; + } + + protected function pageFromList( $container, $dir, &$after, $limit, array $params ) { + return $this->backend->getFileListPageInternal( $container, $dir, $after, $limit, $params ); + } +} diff --git a/includes/libs/filebackend/fileiteration/SwiftFileBackendList.php b/includes/libs/filebackend/fileiteration/SwiftFileBackendList.php new file mode 100644 index 0000000000..bcde8d90a9 --- /dev/null +++ b/includes/libs/filebackend/fileiteration/SwiftFileBackendList.php @@ -0,0 +1,138 @@ +backend = $backend; + $this->container = $fullCont; + $this->dir = $dir; + if ( substr( $this->dir, -1 ) === '/' ) { + $this->dir = substr( $this->dir, 0, -1 ); // remove trailing slash + } + if ( $this->dir == '' ) { // whole container + $this->suffixStart = 0; + } else { // dir within container + $this->suffixStart = strlen( $this->dir ) + 1; // size of "path/to/dir/" + } + $this->params = $params; + } + + /** + * @see Iterator::key() + * @return int + */ + public function key() { + return $this->pos; + } + + /** + * @see Iterator::next() + */ + public function next() { + // Advance to the next file in the page + next( $this->bufferIter ); + ++$this->pos; + // Check if there are no files left in this page and + // advance to the next page if this page was not empty. + if ( !$this->valid() && count( $this->bufferIter ) ) { + $this->bufferIter = $this->pageFromList( + $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params + ); // updates $this->bufferAfter + } + } + + /** + * @see Iterator::rewind() + */ + public function rewind() { + $this->pos = 0; + $this->bufferAfter = null; + $this->bufferIter = $this->pageFromList( + $this->container, $this->dir, $this->bufferAfter, self::PAGE_SIZE, $this->params + ); // updates $this->bufferAfter + } + + /** + * @see Iterator::valid() + * @return bool + */ + public function valid() { + if ( $this->bufferIter === null ) { + return false; // some failure? + } else { + return ( current( $this->bufferIter ) !== false ); // no paths can have this value + } + } + + /** + * Get the given list portion (page) + * + * @param string $container Resolved container name + * @param string $dir Resolved path relative to container + * @param string &$after + * @param int $limit + * @param array $params + * @return Traversable|array + */ + abstract protected function pageFromList( $container, $dir, &$after, $limit, array $params ); +} diff --git a/includes/libs/filebackend/fileophandle/FSFileOpHandle.php b/includes/libs/filebackend/fileophandle/FSFileOpHandle.php new file mode 100644 index 0000000000..2d65c434a1 --- /dev/null +++ b/includes/libs/filebackend/fileophandle/FSFileOpHandle.php @@ -0,0 +1,45 @@ +backend = $backend; + $this->params = $params; + $this->call = $call; + $this->cmd = $cmd; + $this->chmodPath = $chmodPath; + } +} diff --git a/includes/libs/filebackend/fileophandle/FileBackendStoreOpHandle.php b/includes/libs/filebackend/fileophandle/FileBackendStoreOpHandle.php new file mode 100644 index 0000000000..c366a0fff7 --- /dev/null +++ b/includes/libs/filebackend/fileophandle/FileBackendStoreOpHandle.php @@ -0,0 +1,46 @@ +resourcesToClose ); + } +} diff --git a/includes/libs/filebackend/fileophandle/SwiftFileOpHandle.php b/includes/libs/filebackend/fileophandle/SwiftFileOpHandle.php new file mode 100644 index 0000000000..1119867800 --- /dev/null +++ b/includes/libs/filebackend/fileophandle/SwiftFileOpHandle.php @@ -0,0 +1,44 @@ +backend = $backend; + $this->callback = $callback; + $this->httpOp = $httpOp; + } +}