* Fixed bugs in SwiftFileBackend file listing code
authorAaron Schulz <aaron@users.mediawiki.org>
Sun, 22 Jan 2012 00:06:18 +0000 (00:06 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Sun, 22 Jan 2012 00:06:18 +0000 (00:06 +0000)
* Clear container cache in SwiftFileBackend when clearCache() is called
* Updated a comment and fixed a comment typo

includes/filerepo/FileRepo.php
includes/filerepo/backend/FileBackend.php
includes/filerepo/backend/SwiftFileBackend.php

index 7e92b4d..e7608ca 100644 (file)
@@ -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
                        );
                }
 
index 97ab13d..0e07923 100644 (file)
@@ -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 );
        }
 
index 29c0fa8..9c9a551 100644 (file)
@@ -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() {