Index: trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php |
— | — | @@ -1034,6 +1034,16 @@ |
1035 | 1035 | $this->doTestDoOperations(); |
1036 | 1036 | $this->tearDownFiles(); |
1037 | 1037 | |
| 1038 | + $this->backend = $this->singleBackend; |
| 1039 | + $this->tearDownFiles(); |
| 1040 | + $this->doTestDoOperationsFailing(); |
| 1041 | + $this->tearDownFiles(); |
| 1042 | + |
| 1043 | + $this->backend = $this->multiBackend; |
| 1044 | + $this->tearDownFiles(); |
| 1045 | + $this->doTestDoOperationsFailing(); |
| 1046 | + $this->tearDownFiles(); |
| 1047 | + |
1038 | 1048 | // @TODO: test some cases where the ops should fail |
1039 | 1049 | } |
1040 | 1050 | |
— | — | @@ -1057,9 +1067,9 @@ |
1058 | 1068 | |
1059 | 1069 | $status = $this->backend->doOperations( array( |
1060 | 1070 | array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ), |
1061 | | - // Now: A:<A>, B:<B>, C:<A>, D:<D> (file:<orginal contents>) |
| 1071 | + // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>) |
1062 | 1072 | array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ), |
1063 | | - // Now: A:<A>, B:<B>, C:<A>, D:<D> |
| 1073 | + // Now: A:<A>, B:<B>, C:<A>, D:<empty> |
1064 | 1074 | array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ), |
1065 | 1075 | // Now: A:<A>, B:<B>, C:<empty>, D:<A> |
1066 | 1076 | array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ), |
— | — | @@ -1109,6 +1119,68 @@ |
1110 | 1120 | "Correct file SHA-1 of $fileC" ); |
1111 | 1121 | } |
1112 | 1122 | |
| 1123 | + function doTestDoOperationsFailing() { |
| 1124 | + $base = $this->baseStorePath(); |
| 1125 | + |
| 1126 | + $fileA = "$base/unittest-cont2/a/b/fileA.txt"; |
| 1127 | + $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq'; |
| 1128 | + $fileB = "$base/unittest-cont2/a/b/fileB.txt"; |
| 1129 | + $fileBContents = 'g-jmq3gpqgt3qtg q3GT '; |
| 1130 | + $fileC = "$base/unittest-cont2/a/b/fileC.txt"; |
| 1131 | + $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag'; |
| 1132 | + $fileD = "$base/unittest-cont2/a/b/fileD.txt"; |
| 1133 | + |
| 1134 | + $this->prepare( array( 'dir' => dirname( $fileA ) ) ); |
| 1135 | + $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) ); |
| 1136 | + $this->prepare( array( 'dir' => dirname( $fileB ) ) ); |
| 1137 | + $this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) ); |
| 1138 | + $this->prepare( array( 'dir' => dirname( $fileC ) ) ); |
| 1139 | + $this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) ); |
| 1140 | + |
| 1141 | + $status = $this->backend->doOperations( array( |
| 1142 | + array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ), |
| 1143 | + // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>) |
| 1144 | + array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ), |
| 1145 | + // Now: A:<A>, B:<B>, C:<A>, D:<empty> |
| 1146 | + array( 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ), |
| 1147 | + // Now: A:<A>, B:<B>, C:<A>, D:<B> |
| 1148 | + array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ), |
| 1149 | + // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed) |
| 1150 | + array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ), |
| 1151 | + // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed) |
| 1152 | + array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ), |
| 1153 | + // Now: A:<B>, B:<empty>, C:<A>, D:<empty> |
| 1154 | + array( 'op' => 'delete', 'src' => $fileD ), |
| 1155 | + // Now: A:<B>, B:<empty>, C:<A>, D:<empty> |
| 1156 | + array( 'op' => 'null' ), |
| 1157 | + // Does nothing |
| 1158 | + ), array( 'force' => 1 ) ); |
| 1159 | + |
| 1160 | + $this->assertNotEquals( array(), $status->errors, "Operation had warnings" ); |
| 1161 | + $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" ); |
| 1162 | + $this->assertEquals( 8, count( $status->success ), |
| 1163 | + "Operation batch has correct success array" ); |
| 1164 | + |
| 1165 | + $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ), |
| 1166 | + "File does not exist at $fileB" ); |
| 1167 | + $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ), |
| 1168 | + "File does not exist at $fileD" ); |
| 1169 | + |
| 1170 | + $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileA ) ), |
| 1171 | + "File does not exist at $fileA" ); |
| 1172 | + $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ), |
| 1173 | + "File exists at $fileC" ); |
| 1174 | + $this->assertEquals( $fileBContents, |
| 1175 | + $this->backend->getFileContents( array( 'src' => $fileA ) ), |
| 1176 | + "Correct file contents of $fileA" ); |
| 1177 | + $this->assertEquals( strlen( $fileBContents ), |
| 1178 | + $this->backend->getFileSize( array( 'src' => $fileA ) ), |
| 1179 | + "Correct file size of $fileA" ); |
| 1180 | + $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ), |
| 1181 | + $this->backend->getFileSha1Base36( array( 'src' => $fileA ) ), |
| 1182 | + "Correct file SHA-1 of $fileA" ); |
| 1183 | + } |
| 1184 | + |
1113 | 1185 | public function testGetFileList() { |
1114 | 1186 | $this->backend = $this->singleBackend; |
1115 | 1187 | $this->tearDownFiles(); |
Index: trunk/phase3/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: trunk/phase3/includes/filerepo/backend/FileBackend.php |
— | — | @@ -186,8 +186,9 @@ |
187 | 187 | * Return value: |
188 | 188 | * This returns a Status, which contains all warnings and fatals that occured |
189 | 189 | * during the operation. The 'failCount', 'successCount', and 'success' members |
190 | | - * will reflect each operation attempted. The status will be "OK" unless any |
191 | | - * of the operations failed and the 'force' parameter was not set. |
| 190 | + * will reflect each operation attempted. The status will be "OK" unless: |
| 191 | + * a) unexpected operation errors occurred (network partitions, disk full...) |
| 192 | + * b) significant operation errors occured and 'force' was not set |
192 | 193 | * |
193 | 194 | * @param $ops Array List of operations to execute in order |
194 | 195 | * @param $opts Array Batch operation options |