From 2d1d7f644bb50983381590765cb03b1bececcbb0 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 22 Jan 2012 00:06:18 +0000 Subject: [PATCH] * Fixed bugs in SwiftFileBackend file listing code * Clear container cache in SwiftFileBackend when clearCache() is called * Updated a comment and fixed a comment typo --- includes/filerepo/FileRepo.php | 2 +- includes/filerepo/backend/FileBackend.php | 2 +- includes/filerepo/backend/SwiftFileBackend.php | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 7e92b4db12..e7608ca4f2 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -1084,7 +1084,7 @@ class FileRepo { 'dst' => $archivePath, // We may have 2+ identical files being deleted, // all of which will map to the same destination file - 'overwriteSame' => true + 'overwriteSame' => true // also see bug 31792 ); } diff --git a/includes/filerepo/backend/FileBackend.php b/includes/filerepo/backend/FileBackend.php index 97ab13d3ac..0e07923485 100644 --- a/includes/filerepo/backend/FileBackend.php +++ b/includes/filerepo/backend/FileBackend.php @@ -1300,7 +1300,7 @@ abstract class FileBackend extends FileBackendBase { // This accounts for Swift and S3 restrictions while leaving room // for things like '.xxx' (hex shard chars) or '.seg' (segments). // Note that matching strings URL encode to the same string; - // in Swift, the length resriction is *after* URL encoding. + // in Swift, the length restriction is *after* URL encoding. return preg_match( '/^[a-z0-9][a-z0-9-_]{0,199}$/i', $container ); } diff --git a/includes/filerepo/backend/SwiftFileBackend.php b/includes/filerepo/backend/SwiftFileBackend.php index 29c0fa8c62..9c9a551442 100644 --- a/includes/filerepo/backend/SwiftFileBackend.php +++ b/includes/filerepo/backend/SwiftFileBackend.php @@ -508,7 +508,8 @@ class SwiftFileBackend extends FileBackend { try { $container = $this->getContainer( $fullCont ); - $files = $container->list_objects( $limit, $after, "{$dir}/" ); + $prefix = ( $dir == '' ) ? null : "{$dir}/"; + $files = $container->list_objects( $limit, $after, $prefix ); } catch ( NoSuchContainerException $e ) { } catch ( NoSuchObjectException $e ) { } catch ( InvalidResponseException $e ) { @@ -685,6 +686,13 @@ class SwiftFileBackend extends FileBackend { return $this->conn; } + /** + * @see FileBackend::doClearCache() + */ + protected function doClearCache( array $paths = null ) { + $this->connContainers = array(); // clear container object cache + } + /** * Get a Swift container object, possibly from process cache. * Use $reCache if the file count or byte count is needed. @@ -784,7 +792,11 @@ class SwiftFileBackendFileList implements Iterator { if ( substr( $this->dir, -1 ) === '/' ) { $this->dir = substr( $this->dir, 0, -1 ); // remove trailing slash } - $this->suffixStart = strlen( $dir ) + 1; // size of "path/to/dir/" + if ( $this->dir == '' ) { // whole container + $this->suffixStart = 0; + } else { // dir within container + $this->suffixStart = strlen( $dir ) + 1; // size of "path/to/dir/" + } } public function current() { -- 2.20.1