Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackendMultiWrite.php |
— | — | @@ -197,16 +197,17 @@ |
198 | 198 | return $this->backends[$this->masterIndex]->getFileTimestamp( $params ); |
199 | 199 | } |
200 | 200 | |
201 | | - function getFileHash( array $params ) { |
202 | | - // Skip non-master for consistent hash formats |
203 | | - return $this->backends[$this->masterIndex]->getFileHash( $params ); |
| 201 | + function getSha1Base36(array $params) { |
| 202 | + # Hit all backends in case of failed operations (out of sync) |
| 203 | + foreach ( $this->backends as $backend ) { |
| 204 | + $hash = $backend->getSha1Base36( $params ); |
| 205 | + if ( $hash !== false ) { |
| 206 | + return $hash; |
| 207 | + } |
| 208 | + } |
| 209 | + return false; |
204 | 210 | } |
205 | 211 | |
206 | | - function getHashType() { |
207 | | - // Skip non-master for consistent hash formats |
208 | | - return $this->backends[$this->masterIndex]->getHashType(); |
209 | | - } |
210 | | - |
211 | 212 | function getFileProps( array $params ) { |
212 | 213 | # Hit all backends in case of failed operations (out of sync) |
213 | 214 | foreach ( $this->backends as $backend ) { |
Index: branches/FileBackend/phase3/includes/filerepo/backend/FileOp.php |
— | — | @@ -136,13 +136,6 @@ |
137 | 137 | if ( $this->state !== self::STATE_ATTEMPTED ) { |
138 | 138 | return Status::newFatal( 'fileop-fail-state', self::STATE_ATTEMPTED, $this->state ); |
139 | 139 | } |
140 | | - // Kill any backup files (useful for background scripts) |
141 | | - if ( isset( $this->tmpDestFile ) ) { |
142 | | - $this->tmpDestFile->purge(); |
143 | | - } |
144 | | - if ( isset( $this->tmpSourceFile ) ) { |
145 | | - $this->tmpSourceFile->purge(); |
146 | | - } |
147 | 140 | $this->state = self::STATE_DONE; |
148 | 141 | if ( $this->failed ) { |
149 | 142 | $status = Status::newGood(); // nothing to finish |
— | — | @@ -280,12 +273,12 @@ |
281 | 274 | return $status; |
282 | 275 | } |
283 | 276 | } elseif ( $this->getParam( 'overwriteSame' ) ) { |
284 | | - $shash = $this->getSourceMD5(); |
| 277 | + $shash = $this->getSourceSha1Base36(); |
285 | 278 | // If there is a single source, then we can do some checks already. |
286 | 279 | // For things like concatenate(), we would need to build a temp file |
287 | 280 | // first and thus don't support 'overwriteSame' ($shash is null). |
288 | 281 | if ( $shash !== null ) { |
289 | | - $dhash = $this->getFileMD5( $this->params['dst'] ); |
| 282 | + $dhash = $this->getFileSha1Base36( $this->params['dst'] ); |
290 | 283 | if ( !strlen( $shash ) || !strlen( $dhash ) ) { |
291 | 284 | $status->fatal( 'backend-fail-hashes' ); |
292 | 285 | } elseif ( $shash !== $dhash ) { |
— | — | @@ -305,37 +298,34 @@ |
306 | 299 | } |
307 | 300 | |
308 | 301 | /** |
309 | | - * checkAndBackupDest() helper function to get the source file MD5. |
| 302 | + * checkAndBackupDest() helper function to get the source file Sha1. |
310 | 303 | * Returns false on failure and null if there is no single source. |
311 | 304 | * |
312 | 305 | * @return string|false|null |
313 | 306 | */ |
314 | | - protected function getSourceMD5() { |
| 307 | + protected function getSourceSha1Base36() { |
315 | 308 | return null; // N/A |
316 | 309 | } |
317 | 310 | |
318 | 311 | /** |
319 | | - * checkAndBackupDest() helper function to get the MD5 of a file. |
| 312 | + * checkAndBackupDest() helper function to get the Sha1 of a file. |
320 | 313 | * |
321 | 314 | * @return string|false False on failure |
322 | 315 | */ |
323 | | - protected function getFileMD5( $path ) { |
| 316 | + protected function getFileSha1Base36( $path ) { |
324 | 317 | // Source file is in backend |
325 | 318 | if ( FileBackend::isStoragePath( $path ) ) { |
326 | 319 | // For some backends (e.g. Swift, Azure) we can get |
327 | 320 | // standard hashes to use for this types of comparisons. |
328 | | - if ( $this->backend->getHashType() === 'md5' ) { |
329 | | - $hash = $this->backend->getFileHash( array( 'src' => $path ) ); |
330 | | - } else { |
331 | | - $tmp = $this->backend->getLocalCopy( array( 'src' => $path ) ); |
332 | | - if ( !$tmp ) { |
333 | | - return false; // error |
334 | | - } |
335 | | - $hash = md5_file( $tmp->getPath() ); |
336 | | - } |
| 321 | + $hash = $this->backend->getSha1Base36( array( 'src' => $path ) ); |
337 | 322 | // Source file is on file system |
338 | 323 | } else { |
339 | | - $hash = md5_file( $path ); |
| 324 | + wfSuppressWarnings(); |
| 325 | + $hash = sha1_file( $path ); |
| 326 | + wfRestoreWarnings(); |
| 327 | + if ( $hash !== false ) { |
| 328 | + $hash = wfBaseConvert( $hash, 16, 36, 31 ); |
| 329 | + } |
340 | 330 | } |
341 | 331 | return $hash; |
342 | 332 | } |
— | — | @@ -459,8 +449,8 @@ |
460 | 450 | return $status; |
461 | 451 | } |
462 | 452 | |
463 | | - protected function getSourceMD5() { |
464 | | - return md5_file( $this->params['src'] ); |
| 453 | + protected function getSourceSha1Base36() { |
| 454 | + return $this->getFileSha1Base36( $this->params['src'] ); |
465 | 455 | } |
466 | 456 | |
467 | 457 | public function storagePathsChanged() { |
— | — | @@ -524,8 +514,8 @@ |
525 | 515 | return $status; |
526 | 516 | } |
527 | 517 | |
528 | | - protected function getSourceMD5() { |
529 | | - return md5( $this->params['content'] ); |
| 518 | + protected function getSourceSha1Base36() { |
| 519 | + return wfBaseConvert( sha1( $this->params['content'] ), 16, 36, 31 ); |
530 | 520 | } |
531 | 521 | |
532 | 522 | public function storagePathsChanged() { |
— | — | @@ -594,8 +584,8 @@ |
595 | 585 | return $status; |
596 | 586 | } |
597 | 587 | |
598 | | - protected function getSourceMD5() { |
599 | | - return $this->getFileMD5( $this->params['src'] ); |
| 588 | + protected function getSourceSha1Base36() { |
| 589 | + return $this->getFileSha1Base36( $this->params['src'] ); |
600 | 590 | } |
601 | 591 | |
602 | 592 | public function storagePathsRead() { |
— | — | @@ -726,8 +716,8 @@ |
727 | 717 | return $status; |
728 | 718 | } |
729 | 719 | |
730 | | - protected function getSourceMD5() { |
731 | | - return $this->getFileMD5( $this->params['src'] ); |
| 720 | + protected function getSourceSha1Base36() { |
| 721 | + return $this->getFileSha1Base36( $this->params['src'] ); |
732 | 722 | } |
733 | 723 | |
734 | 724 | public function storagePathsRead() { |
— | — | @@ -796,7 +786,7 @@ |
797 | 787 | return $status; |
798 | 788 | } |
799 | 789 | |
800 | | - protected function getSourceMD5() { |
| 790 | + protected function getSourceSha1Base36() { |
801 | 791 | return null; // defer this until we finish building the new file |
802 | 792 | } |
803 | 793 | |
Index: branches/FileBackend/phase3/includes/filerepo/backend/FSFileBackend.php |
— | — | @@ -420,21 +420,12 @@ |
421 | 421 | if ( $source === null ) { |
422 | 422 | return false; // invalid storage path |
423 | 423 | } |
424 | | - return is_file( $source ); |
| 424 | + wfSuppressWarnings(); |
| 425 | + $exists = is_file( $source ); |
| 426 | + wfRestoreWarnings(); |
| 427 | + return $exists; |
425 | 428 | } |
426 | 429 | |
427 | | - function getHashType() { |
428 | | - return 'md5'; |
429 | | - } |
430 | | - |
431 | | - function getFileHash( array $params ) { |
432 | | - list( $c, $source ) = $this->resolveStoragePath( $params['src'] ); |
433 | | - if ( $source === null ) { |
434 | | - return false; // invalid storage path |
435 | | - } |
436 | | - return md5_file( $source ); |
437 | | - } |
438 | | - |
439 | 430 | function getFileTimestamp( array $params ) { |
440 | 431 | list( $c, $source ) = $this->resolveStoragePath( $params['src'] ); |
441 | 432 | if ( $source === null ) { |
— | — | @@ -444,15 +435,6 @@ |
445 | 436 | return $fsFile->getTimestamp(); |
446 | 437 | } |
447 | 438 | |
448 | | - function getFileProps( array $params ) { |
449 | | - list( $c, $source ) = $this->resolveStoragePath( $params['src'] ); |
450 | | - if ( $source === null ) { |
451 | | - return FSFile::placeholderProps(); // invalid storage path |
452 | | - } |
453 | | - $fsFile = new FSFile( $source ); |
454 | | - return $fsFile->getProps(); |
455 | | - } |
456 | | - |
457 | 439 | function getFileList( array $params ) { |
458 | 440 | list( $c, $dir ) = $this->resolveStoragePath( $params['dir'] ); |
459 | 441 | if ( $dir === null ) { // invalid storage path |
Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php |
— | — | @@ -202,8 +202,7 @@ |
203 | 203 | abstract public function fileExists( array $params ); |
204 | 204 | |
205 | 205 | /** |
206 | | - * Get a hash of the file at a storage path in the backend. |
207 | | - * Typically this will be a SHA-1 hash, MD5 hash, or something similar. |
| 206 | + * Get a SHA-1 hash of the file at a storage path in the backend. |
208 | 207 | * |
209 | 208 | * $params include: |
210 | 209 | * src : source storage path |
— | — | @@ -211,16 +210,9 @@ |
212 | 211 | * @param $params Array |
213 | 212 | * @return string|false Hash string or false on failure |
214 | 213 | */ |
215 | | - abstract public function getFileHash( array $params ); |
| 214 | + abstract public function getSha1Base36( array $params ); |
216 | 215 | |
217 | 216 | /** |
218 | | - * Get the format of the hash that getFileHash() uses |
219 | | - * |
220 | | - * @return string (md5, sha1, internal, ...) |
221 | | - */ |
222 | | - abstract public function getHashType(); |
223 | | - |
224 | | - /** |
225 | 217 | * Get the last-modified timestamp of the file at a storage path. |
226 | 218 | * |
227 | 219 | * $params include: |
— | — | @@ -464,6 +456,15 @@ |
465 | 457 | return false; // not implemented |
466 | 458 | } |
467 | 459 | |
| 460 | + public function getSha1Base36( array $params ) { |
| 461 | + $fsFile = $this->getLocalReference( array( 'src' => $params['src'] ) ); |
| 462 | + if ( !$fsFile ) { |
| 463 | + return false; |
| 464 | + } else { |
| 465 | + return $fsFile->sha1Base36(); |
| 466 | + } |
| 467 | + } |
| 468 | + |
468 | 469 | public function getFileProps( array $params ) { |
469 | 470 | $fsFile = $this->getLocalReference( array( 'src' => $params['src'] ) ); |
470 | 471 | if ( !$fsFile ) { |
— | — | @@ -473,10 +474,6 @@ |
474 | 475 | } |
475 | 476 | } |
476 | 477 | |
477 | | - public function getHashType() { |
478 | | - return 'internal'; |
479 | | - } |
480 | | - |
481 | 478 | public function getLocalReference( array $params ) { |
482 | 479 | return $this->getLocalCopy( $params ); |
483 | 480 | } |