Index: branches/wmf/1.19wmf1/tests/phpunit/includes/filerepo/FileBackendTest.php |
— | — | @@ -1032,6 +1032,16 @@ |
1033 | 1033 | $this->doTestDoOperations(); |
1034 | 1034 | $this->tearDownFiles(); |
1035 | 1035 | |
| 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 | + |
1036 | 1046 | // @TODO: test some cases where the ops should fail |
1037 | 1047 | } |
1038 | 1048 | |
— | — | @@ -1055,9 +1065,9 @@ |
1056 | 1066 | |
1057 | 1067 | $status = $this->backend->doOperations( array( |
1058 | 1068 | 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>) |
1060 | 1070 | 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> |
1062 | 1072 | array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ), |
1063 | 1073 | // Now: A:<A>, B:<B>, C:<empty>, D:<A> |
1064 | 1074 | array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ), |
— | — | @@ -1107,6 +1117,68 @@ |
1108 | 1118 | "Correct file SHA-1 of $fileC" ); |
1109 | 1119 | } |
1110 | 1120 | |
| 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 | + |
1111 | 1183 | public function testGetFileList() { |
1112 | 1184 | $this->backend = $this->singleBackend; |
1113 | 1185 | $this->tearDownFiles(); |
Index: branches/wmf/1.19wmf1/includes/filerepo/backend/FileOp.php |
— | — | @@ -81,6 +81,10 @@ |
82 | 82 | * 'allowStale' : Don't require the latest available data. |
83 | 83 | * This can increase performance for non-critical writes. |
84 | 84 | * 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 |
85 | 89 | * |
86 | 90 | * @param $performOps Array List of FileOp operations |
87 | 91 | * @param $opts Array Batch operation options |
— | — | @@ -115,6 +119,11 @@ |
116 | 120 | } |
117 | 121 | } |
118 | 122 | |
| 123 | + if ( $ignoreErrors ) { |
| 124 | + # Treat all precheck() fatals as merely warnings |
| 125 | + $status->setResult( true, $status->value ); |
| 126 | + } |
| 127 | + |
119 | 128 | // Restart PHP's execution timer and set the timeout to safe amount. |
120 | 129 | // This handles cases where the operations take a long time or where we are |
121 | 130 | // 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 @@ |
181 | 181 | * Return value: |
182 | 182 | * This returns a Status, which contains all warnings and fatals that occured |
183 | 183 | * 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 |
186 | 187 | * |
187 | 188 | * @param $ops Array List of operations to execute in order |
188 | 189 | * @param $opts Array Batch operation options |
Property changes on: branches/wmf/1.19wmf1/includes |
___________________________________________________________________ |
Modified: svn:mergeinfo |
189 | 190 | Merged /trunk/phase3/includes:r113412 |
Property changes on: branches/wmf/1.19wmf1 |
___________________________________________________________________ |
Modified: svn:mergeinfo |
190 | 191 | Merged /trunk/phase3:r113412 |