r113413 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113412‎ | r113413 | r113414 >
Date:22:34, 8 March 2012
Author:aaron
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.19wmf1 (modified) (history)
  • /branches/wmf/1.19wmf1/includes (modified) (history)
  • /branches/wmf/1.19wmf1/includes/filerepo/backend/FileBackend.php (modified) (history)
  • /branches/wmf/1.19wmf1/includes/filerepo/backend/FileOp.php (modified) (history)
  • /branches/wmf/1.19wmf1/tests/phpunit/includes/filerepo/FileBackendTest.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.19wmf1/tests/phpunit/includes/filerepo/FileBackendTest.php
@@ -1032,6 +1032,16 @@
10331033 $this->doTestDoOperations();
10341034 $this->tearDownFiles();
10351035
 1036+ $this->backend = $this->singleBackend;
 1037+ $this->tearDownFiles();
 1038+ $this->doTestDoOperationsFailing();
 1039+ $this->tearDownFiles();
 1040+
 1041+ $this->backend = $this->multiBackend;
 1042+ $this->tearDownFiles();
 1043+ $this->doTestDoOperationsFailing();
 1044+ $this->tearDownFiles();
 1045+
10361046 // @TODO: test some cases where the ops should fail
10371047 }
10381048
@@ -1055,9 +1065,9 @@
10561066
10571067 $status = $this->backend->doOperations( array(
10581068 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1059 - // Now: A:<A>, B:<B>, C:<A>, D:<D> (file:<orginal contents>)
 1069+ // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
10601070 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1061 - // Now: A:<A>, B:<B>, C:<A>, D:<D>
 1071+ // Now: A:<A>, B:<B>, C:<A>, D:<empty>
10621072 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
10631073 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
10641074 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
@@ -1107,6 +1117,68 @@
11081118 "Correct file SHA-1 of $fileC" );
11091119 }
11101120
 1121+ function doTestDoOperationsFailing() {
 1122+ $base = $this->baseStorePath();
 1123+
 1124+ $fileA = "$base/unittest-cont2/a/b/fileA.txt";
 1125+ $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
 1126+ $fileB = "$base/unittest-cont2/a/b/fileB.txt";
 1127+ $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
 1128+ $fileC = "$base/unittest-cont2/a/b/fileC.txt";
 1129+ $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
 1130+ $fileD = "$base/unittest-cont2/a/b/fileD.txt";
 1131+
 1132+ $this->prepare( array( 'dir' => dirname( $fileA ) ) );
 1133+ $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
 1134+ $this->prepare( array( 'dir' => dirname( $fileB ) ) );
 1135+ $this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
 1136+ $this->prepare( array( 'dir' => dirname( $fileC ) ) );
 1137+ $this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
 1138+
 1139+ $status = $this->backend->doOperations( array(
 1140+ array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
 1141+ // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
 1142+ array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
 1143+ // Now: A:<A>, B:<B>, C:<A>, D:<empty>
 1144+ array( 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ),
 1145+ // Now: A:<A>, B:<B>, C:<A>, D:<B>
 1146+ array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ),
 1147+ // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
 1148+ array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ),
 1149+ // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
 1150+ array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ),
 1151+ // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
 1152+ array( 'op' => 'delete', 'src' => $fileD ),
 1153+ // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
 1154+ array( 'op' => 'null' ),
 1155+ // Does nothing
 1156+ ), array( 'force' => 1 ) );
 1157+
 1158+ $this->assertNotEquals( array(), $status->errors, "Operation had warnings" );
 1159+ $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
 1160+ $this->assertEquals( 8, count( $status->success ),
 1161+ "Operation batch has correct success array" );
 1162+
 1163+ $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
 1164+ "File does not exist at $fileB" );
 1165+ $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
 1166+ "File does not exist at $fileD" );
 1167+
 1168+ $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileA ) ),
 1169+ "File does not exist at $fileA" );
 1170+ $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
 1171+ "File exists at $fileC" );
 1172+ $this->assertEquals( $fileBContents,
 1173+ $this->backend->getFileContents( array( 'src' => $fileA ) ),
 1174+ "Correct file contents of $fileA" );
 1175+ $this->assertEquals( strlen( $fileBContents ),
 1176+ $this->backend->getFileSize( array( 'src' => $fileA ) ),
 1177+ "Correct file size of $fileA" );
 1178+ $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
 1179+ $this->backend->getFileSha1Base36( array( 'src' => $fileA ) ),
 1180+ "Correct file SHA-1 of $fileA" );
 1181+ }
 1182+
11111183 public function testGetFileList() {
11121184 $this->backend = $this->singleBackend;
11131185 $this->tearDownFiles();
Index: branches/wmf/1.19wmf1/includes/filerepo/backend/FileOp.php
@@ -81,6 +81,10 @@
8282 * 'allowStale' : Don't require the latest available data.
8383 * This can increase performance for non-critical writes.
8484 * This has no effect unless the 'force' flag is set.
 85+ *
 86+ * The resulting Status will be "OK" unless:
 87+ * a) unexpected operation errors occurred (network partitions, disk full...)
 88+ * b) significant operation errors occured and 'force' was not set
8589 *
8690 * @param $performOps Array List of FileOp operations
8791 * @param $opts Array Batch operation options
@@ -115,6 +119,11 @@
116120 }
117121 }
118122
 123+ if ( $ignoreErrors ) {
 124+ # Treat all precheck() fatals as merely warnings
 125+ $status->setResult( true, $status->value );
 126+ }
 127+
119128 // Restart PHP's execution timer and set the timeout to safe amount.
120129 // This handles cases where the operations take a long time or where we are
121130 // already running low on time left. The old timeout is restored afterwards.
Index: branches/wmf/1.19wmf1/includes/filerepo/backend/FileBackend.php
@@ -180,8 +180,9 @@
181181 * Return value:
182182 * This returns a Status, which contains all warnings and fatals that occured
183183 * during the operation. The 'failCount', 'successCount', and 'success' members
184 - * will reflect each operation attempted. The status will be "OK" unless any
185 - * of the operations failed and the 'force' parameter was not set.
 184+ * will reflect each operation attempted. The status will be "OK" unless:
 185+ * a) unexpected operation errors occurred (network partitions, disk full...)
 186+ * b) significant operation errors occured and 'force' was not set
186187 *
187188 * @param $ops Array List of operations to execute in order
188189 * @param $opts Array Batch operation options
Property changes on: branches/wmf/1.19wmf1/includes
___________________________________________________________________
Modified: svn:mergeinfo
189190 Merged /trunk/phase3/includes:r113412
Property changes on: branches/wmf/1.19wmf1
___________________________________________________________________
Modified: svn:mergeinfo
190191 Merged /trunk/phase3:r113412

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r113412[FileBackend] Made doOperations() Status handling align with documentation as...aaron22:31, 8 March 2012

Status & tagging log