* Added FileBackend::parentStoragePath() convenience function for getting parent...
authorAaron Schulz <aaron@users.mediawiki.org>
Fri, 20 Jan 2012 22:46:35 +0000 (22:46 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Fri, 20 Jan 2012 22:46:35 +0000 (22:46 +0000)
* In StoreBatchTest: sed proper clean() function to remove temp dirs (follows up r109641). Also removed some commented out code.
* Fixed temp dir leakage in FileBackendTest.

includes/filerepo/backend/FileBackend.php
tests/phpunit/includes/filerepo/FileBackendTest.php
tests/phpunit/includes/filerepo/StoreBatchTest.php

index 77018ab..1e9455d 100644 (file)
@@ -1244,6 +1244,20 @@ abstract class FileBackend extends FileBackendBase {
                }
        }
 
+       /**
+        * Get the parent storage directory of a storage path.
+        * This returns a path like "mwstore://backend/container",
+        * "mwstore://backend/container/...", or false if there is no parent.
+        * 
+        * @param $storagePath string
+        * @return string|false
+        */
+       final public static function parentStoragePath( $storagePath ) {
+               $storagePath = dirname( $storagePath );
+               list( $b, $cont, $rel ) = self::splitStoragePath( $storagePath );
+               return ( $rel === null ) ? null : $storagePath;
+       }
+
        /**
         * Check if a given path is a mwstore:// path.
         * This does not do any actual validation or existence checks.
index 2e479d8..cd72530 100644 (file)
@@ -2,7 +2,6 @@
 
 /**
  * @group FileRepo
- * @TODO: fix empty dir leakage
  */
 class FileBackendTest extends MediaWikiTestCase {
        private $backend, $multiBackend;
@@ -940,6 +939,10 @@ class FileBackendTest extends MediaWikiTestCase {
                }
                foreach ( $this->pathsToPrune as $file ) {
                        $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
+                       $tmp = $file;
+                       while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
+                               $this->backend->clean( array( 'dir' => $tmp ) );
+                       }
                }
        }
 
index 73f6abe..e45cae8 100644 (file)
@@ -25,26 +25,6 @@ class StoreBatchTest extends MediaWikiTestCase {
 
                $this->date = gmdate( "YmdHis" );
                $this->createdFiles = array();
-
-               // ApiTestUser requires a database connection. Code below does not
-               // seem to be needed so it is commented out to not make this test
-               // requires a database connection.
-               /**
-               $this->users = array(
-                       'sysop' => new ApiTestUser(
-                               'Uploadstashtestsysop',
-                               'Upload Stash Test Sysop',
-                               'upload_stash_test_sysop@example.com',
-                               array( 'sysop' )
-                       ),
-                       'uploader' => new ApiTestUser(
-                               'Uploadstashtestuser',
-                               'Upload Stash Test User',
-                               'upload_stash_test_user@example.com',
-                               array()
-                       )
-               );
-               **/
        }
 
        /**
@@ -116,8 +96,11 @@ class StoreBatchTest extends MediaWikiTestCase {
 
        public function tearDown() {
                $this->repo->cleanupBatch( $this->createdFiles );
-               foreach ( array( "temp/0/06", "temp/0", "temp/4/4d", "temp/4", "temp/3/31", "temp/3", "temp", "" ) as $tmp ) {
-                       rmdir( $this->tmpDir . "/" . $tmp );
+               foreach ( $this->createdFiles as $tmp ) {
+                       $tmp = $this->repo->resolveVirtualUrl( $tmp );
+                       while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
+                               $this->repo->getBackend()->clean( array( 'dir' => $tmp ) );
+                       }
                }
                parent::tearDown();
        }