From eb92ac5557c973a78cf4664459c73eb323faf70a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 20 Jan 2012 22:46:35 +0000 Subject: [PATCH] * Added FileBackend::parentStoragePath() convenience function for getting parent directories. * 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 | 14 ++++++++++ .../includes/filerepo/FileBackendTest.php | 5 +++- .../includes/filerepo/StoreBatchTest.php | 27 ++++--------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/includes/filerepo/backend/FileBackend.php b/includes/filerepo/backend/FileBackend.php index 77018ab765..1e9455d840 100644 --- a/includes/filerepo/backend/FileBackend.php +++ b/includes/filerepo/backend/FileBackend.php @@ -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. diff --git a/tests/phpunit/includes/filerepo/FileBackendTest.php b/tests/phpunit/includes/filerepo/FileBackendTest.php index 2e479d8357..cd72530805 100644 --- a/tests/phpunit/includes/filerepo/FileBackendTest.php +++ b/tests/phpunit/includes/filerepo/FileBackendTest.php @@ -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 ) ); + } } } diff --git a/tests/phpunit/includes/filerepo/StoreBatchTest.php b/tests/phpunit/includes/filerepo/StoreBatchTest.php index 73f6abed78..e45cae8481 100644 --- a/tests/phpunit/includes/filerepo/StoreBatchTest.php +++ b/tests/phpunit/includes/filerepo/StoreBatchTest.php @@ -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(); } -- 2.20.1