Index: trunk/phase3/includes/filerepo/file/File.php |
— | — | @@ -799,12 +799,11 @@ |
800 | 800 | $thumb = $this->handler->getTransform( $this, $tmpThumbPath, $thumbUrl, $params ); |
801 | 801 | } |
802 | 802 | } elseif ( $thumb->hasFile() && !$thumb->fileIsSource() ) { |
803 | | - // @TODO: use a FileRepo store function |
804 | | - $op = array( 'op' => 'store', |
805 | | - 'src' => $tmpThumbPath, 'dst' => $thumbPath, 'overwriteDest' => true ); |
806 | 803 | // Copy any thumbnail from the FS into storage at $dstpath |
807 | | - $opts = array( 'ignoreErrors' => true, 'nonLocking' => true ); // performance |
808 | | - if ( !$this->getRepo()->getBackend()->doOperation( $op, $opts )->isOK() ) { |
| 804 | + $status = $this->repo->store( |
| 805 | + $tmpThumbPath, 'thumb', $this->getThumbRel( $thumbName ), |
| 806 | + FileRepo::OVERWRITE | FileRepo::SKIP_LOCKING ); |
| 807 | + if ( !$status->isOK() ) { |
809 | 808 | return new MediaTransformError( 'thumbnail_error', |
810 | 809 | $params['width'], 0, wfMsg( 'thumbnail-dest-create' ) ); |
811 | 810 | } |
— | — | @@ -1013,7 +1012,8 @@ |
1014 | 1013 | } |
1015 | 1014 | |
1016 | 1015 | /** |
1017 | | - * Get the path of the file relative to the public zone root |
| 1016 | + * Get the path of the file relative to the public zone root. |
| 1017 | + * This function is overriden in OldLocalFile to be like getArchiveRel(). |
1018 | 1018 | * |
1019 | 1019 | * @return string |
1020 | 1020 | */ |
— | — | @@ -1022,17 +1022,8 @@ |
1023 | 1023 | } |
1024 | 1024 | |
1025 | 1025 | /** |
1026 | | - * Get urlencoded relative path of the file |
| 1026 | + * Get the path of an archived file relative to the public zone root |
1027 | 1027 | * |
1028 | | - * @return string |
1029 | | - */ |
1030 | | - function getUrlRel() { |
1031 | | - return $this->getHashPath() . rawurlencode( $this->getName() ); |
1032 | | - } |
1033 | | - |
1034 | | - /** |
1035 | | - * Get the relative path for an archived file |
1036 | | - * |
1037 | 1028 | * @param $suffix bool|string if not false, the name of an archived thumbnail file |
1038 | 1029 | * |
1039 | 1030 | * @return string |
— | — | @@ -1048,7 +1039,33 @@ |
1049 | 1040 | } |
1050 | 1041 | |
1051 | 1042 | /** |
1052 | | - * Get the relative path for an archived file's thumbs directory |
| 1043 | + * Get the path, relative to the thumbnail zone root, of the |
| 1044 | + * thumbnail directory or a particular file if $suffix is specified |
| 1045 | + * |
| 1046 | + * @param $suffix bool|string if not false, the name of a thumbnail file |
| 1047 | + * |
| 1048 | + * @return string |
| 1049 | + */ |
| 1050 | + function getThumbRel( $suffix = false ) { |
| 1051 | + $path = $this->getRel(); |
| 1052 | + if ( $suffix !== false ) { |
| 1053 | + $path .= '/' . $suffix; |
| 1054 | + } |
| 1055 | + return $path; |
| 1056 | + } |
| 1057 | + |
| 1058 | + /** |
| 1059 | + * Get urlencoded path of the file relative to the public zone root. |
| 1060 | + * This function is overriden in OldLocalFile to be like getArchiveUrl(). |
| 1061 | + * |
| 1062 | + * @return string |
| 1063 | + */ |
| 1064 | + function getUrlRel() { |
| 1065 | + return $this->getHashPath() . rawurlencode( $this->getName() ); |
| 1066 | + } |
| 1067 | + |
| 1068 | + /** |
| 1069 | + * Get the path, relative to the thumbnail zone root, for an archived file's thumbs directory |
1053 | 1070 | * or a specific thumb if the $suffix is given. |
1054 | 1071 | * |
1055 | 1072 | * @param $archiveName string the timestamped name of an archived image |
— | — | @@ -1079,7 +1096,7 @@ |
1080 | 1097 | } |
1081 | 1098 | |
1082 | 1099 | /** |
1083 | | - * Get the path of the archived file's thumbs, or a particular thumb if $suffix is specified |
| 1100 | + * Get the path of an archived file's thumbs, or a particular thumb if $suffix is specified |
1084 | 1101 | * |
1085 | 1102 | * @param $archiveName string the timestamped name of an archived image |
1086 | 1103 | * @param $suffix bool|string if not false, the name of a thumbnail file |
— | — | @@ -1101,11 +1118,7 @@ |
1102 | 1119 | */ |
1103 | 1120 | function getThumbPath( $suffix = false ) { |
1104 | 1121 | $this->assertRepoDefined(); |
1105 | | - $path = $this->repo->getZonePath( 'thumb' ) . '/' . $this->getRel(); |
1106 | | - if ( $suffix !== false ) { |
1107 | | - $path .= '/' . $suffix; |
1108 | | - } |
1109 | | - return $path; |
| 1122 | + return $this->repo->getZonePath( 'thumb' ) . '/' . $this->getThumbRel( $suffix ); |
1110 | 1123 | } |
1111 | 1124 | |
1112 | 1125 | /** |
Index: trunk/phase3/includes/filerepo/FileRepo.php |
— | — | @@ -13,10 +13,11 @@ |
14 | 14 | */ |
15 | 15 | class FileRepo { |
16 | 16 | const FILES_ONLY = 1; |
| 17 | + |
17 | 18 | const DELETE_SOURCE = 1; |
18 | 19 | const OVERWRITE = 2; |
19 | 20 | const OVERWRITE_SAME = 4; |
20 | | - const SKIP_VALIDATION = 8; |
| 21 | + const SKIP_LOCKING = 8; |
21 | 22 | |
22 | 23 | /** @var FileBackendBase */ |
23 | 24 | protected $backend; |
— | — | @@ -622,6 +623,7 @@ |
623 | 624 | * self::OVERWRITE Overwrite an existing destination file instead of failing |
624 | 625 | * self::OVERWRITE_SAME Overwrite the file if the destination exists and has the |
625 | 626 | * same contents as the source |
| 627 | + * self::SKIP_LOCKING Skip any file locking when doing the store |
626 | 628 | * @return FileRepoStatus |
627 | 629 | */ |
628 | 630 | public function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) { |
— | — | @@ -641,17 +643,12 @@ |
642 | 644 | * self::OVERWRITE Overwrite an existing destination file instead of failing |
643 | 645 | * self::OVERWRITE_SAME Overwrite the file if the destination exists and has the |
644 | 646 | * same contents as the source |
| 647 | + * self::SKIP_LOCKING Skip any file locking when doing the store |
645 | 648 | * @return FileRepoStatus |
646 | 649 | */ |
647 | 650 | public function storeBatch( $triplets, $flags = 0 ) { |
648 | 651 | $backend = $this->backend; // convenience |
649 | 652 | |
650 | | - // Try creating directories |
651 | | - $status = $this->initZones(); |
652 | | - if ( !$status->isOK() ) { |
653 | | - return $status; |
654 | | - } |
655 | | - |
656 | 653 | $status = $this->newGood(); |
657 | 654 | |
658 | 655 | $operations = array(); |
— | — | @@ -705,6 +702,9 @@ |
706 | 703 | |
707 | 704 | // Execute the store operation for each triplet |
708 | 705 | $opts = array( 'ignoreErrors' => true ); |
| 706 | + if ( $flags & self::SKIP_LOCKING ) { |
| 707 | + $opts['nonLocking'] = true; |
| 708 | + } |
709 | 709 | $status->merge( $backend->doOperations( $operations, $opts ) ); |
710 | 710 | // Cleanup for disk source files... |
711 | 711 | foreach ( $sourceFSFilesToDelete as $file ) { |
— | — | @@ -778,7 +778,7 @@ |
779 | 779 | $dstRel = "{$hashPath}{$date}!{$originalName}"; |
780 | 780 | $dstUrlRel = $hashPath . $date . '!' . rawurlencode( $originalName ); |
781 | 781 | |
782 | | - $result = $this->store( $srcPath, 'temp', $dstRel ); |
| 782 | + $result = $this->store( $srcPath, 'temp', $dstRel, self::SKIP_LOCKING ); |
783 | 783 | $result->value = $this->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel; |
784 | 784 | return $result; |
785 | 785 | } |
— | — | @@ -1005,9 +1005,6 @@ |
1006 | 1006 | * @return Either array of files and existence flags, or false |
1007 | 1007 | */ |
1008 | 1008 | public function fileExistsBatch( $files, $flags = 0 ) { |
1009 | | - if ( !$this->initZones() ) { |
1010 | | - return false; |
1011 | | - } |
1012 | 1009 | $result = array(); |
1013 | 1010 | foreach ( $files as $key => $file ) { |
1014 | 1011 | if ( self::isVirtualUrl( $file ) ) { |