r109659 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109658‎ | r109659 | r109660 >
Date:22:46, 20 January 2012
Author:aaron
Status:ok (Comments)
Tags:filebackend 
Comment:
* 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.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/filerepo/StoreBatchTest.php
@@ -25,26 +25,6 @@
2626
2727 $this->date = gmdate( "YmdHis" );
2828 $this->createdFiles = array();
29 -
30 - // ApiTestUser requires a database connection. Code below does not
31 - // seem to be needed so it is commented out to not make this test
32 - // requires a database connection.
33 - /**
34 - $this->users = array(
35 - 'sysop' => new ApiTestUser(
36 - 'Uploadstashtestsysop',
37 - 'Upload Stash Test Sysop',
38 - 'upload_stash_test_sysop@example.com',
39 - array( 'sysop' )
40 - ),
41 - 'uploader' => new ApiTestUser(
42 - 'Uploadstashtestuser',
43 - 'Upload Stash Test User',
44 - 'upload_stash_test_user@example.com',
45 - array()
46 - )
47 - );
48 - **/
4929 }
5030
5131 /**
@@ -116,8 +96,11 @@
11797
11898 public function tearDown() {
11999 $this->repo->cleanupBatch( $this->createdFiles );
120 - foreach ( array( "temp/0/06", "temp/0", "temp/4/4d", "temp/4", "temp/3/31", "temp/3", "temp", "" ) as $tmp ) {
121 - rmdir( $this->tmpDir . "/" . $tmp );
 100+ foreach ( $this->createdFiles as $tmp ) {
 101+ $tmp = $this->repo->resolveVirtualUrl( $tmp );
 102+ while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
 103+ $this->repo->getBackend()->clean( array( 'dir' => $tmp ) );
 104+ }
122105 }
123106 parent::tearDown();
124107 }
Index: trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php
@@ -2,7 +2,6 @@
33
44 /**
55 * @group FileRepo
6 - * @TODO: fix empty dir leakage
76 */
87 class FileBackendTest extends MediaWikiTestCase {
98 private $backend, $multiBackend;
@@ -940,6 +939,10 @@
941940 }
942941 foreach ( $this->pathsToPrune as $file ) {
943942 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
 943+ $tmp = $file;
 944+ while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
 945+ $this->backend->clean( array( 'dir' => $tmp ) );
 946+ }
944947 }
945948 }
946949
Index: trunk/phase3/includes/filerepo/backend/FileBackend.php
@@ -1245,6 +1245,20 @@
12461246 }
12471247
12481248 /**
 1249+ * Get the parent storage directory of a storage path.
 1250+ * This returns a path like "mwstore://backend/container",
 1251+ * "mwstore://backend/container/...", or false if there is no parent.
 1252+ *
 1253+ * @param $storagePath string
 1254+ * @return string|false
 1255+ */
 1256+ final public static function parentStoragePath( $storagePath ) {
 1257+ $storagePath = dirname( $storagePath );
 1258+ list( $b, $cont, $rel ) = self::splitStoragePath( $storagePath );
 1259+ return ( $rel === null ) ? null : $storagePath;
 1260+ }
 1261+
 1262+ /**
12491263 * Check if a given path is a mwstore:// path.
12501264 * This does not do any actual validation or existence checks.
12511265 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r109664* r109659: actually return the exact type we say we do...aaron00:04, 21 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109641Fix folder leakage.platonides20:15, 20 January 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   22:47, 20 January 2012

Should be "In StoreBatchTest: use proper clean()...", there are no sed matching here :p

#Comment by Hashar (talk | contribs)   10:00, 23 January 2012

Looks like the file backend is missing a recursive deletion function :/

Status & tagging log