X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilebackend%2FSwiftFileBackend.php;h=c3d2de8bd183c120fd48d483ceecb67d8b5bc5c4;hb=cc281862b272e845453611ba2245c34604815f0e;hp=d9f4fc8987f14834140bebfbc285cbe65adbc4a0;hpb=9a3b6e5639d0fae23c721ed803a3feb0a0462c14;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filebackend/SwiftFileBackend.php b/includes/filebackend/SwiftFileBackend.php index d9f4fc8987..c3d2de8bd1 100644 --- a/includes/filebackend/SwiftFileBackend.php +++ b/includes/filebackend/SwiftFileBackend.php @@ -89,12 +89,12 @@ class SwiftFileBackend extends FileBackendStore { * - cacheAuthInfo : Whether to cache authentication tokens in APC, XCache, ect. * If those are not available, then the main cache will be used. * This is probably insecure in shared hosting environments. - * - rgwS3AccessKey : Ragos Gateway S3 "access key" value on the account. + * - rgwS3AccessKey : Rados Gateway S3 "access key" value on the account. * Do not set this until it has been set in the backend. * This is used for generating expiring pre-authenticated URLs. * Only use this when using rgw and to work around * http://tracker.newdream.net/issues/3454. - * - rgwS3SecretKey : Ragos Gateway S3 "secret key" value on the account. + * - rgwS3SecretKey : Rados Gateway S3 "secret key" value on the account. * Do not set this until it has been set in the backend. * This is used for generating expiring pre-authenticated URLs. * Only use this when using rgw and to work around @@ -275,7 +275,7 @@ class SwiftFileBackend extends FileBackendStore { $sha1Hash = wfBaseConvert( $sha1Hash, 16, 36, 31 ); $contentType = $this->getContentType( $params['dst'], null, $params['src'] ); - $handle = fopen( $params['src'], 'rb+' ); + $handle = fopen( $params['src'], 'rb' ); if ( $handle === false ) { // source doesn't exist? $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] ); @@ -638,7 +638,7 @@ class SwiftFileBackend extends FileBackendStore { list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $this->http->run( array( 'method' => 'HEAD', 'url' => $this->storageUrl( $auth, $srcCont, $srcRel ), - 'headers' => $this->authTokenHeaders( $auth ) + 'headers' => $this->authTokenHeaders( $auth ) + $this->headersFromParams( $params ) ) ); if ( $rcode === 200 || $rcode === 204 ) { // Update the object if it is missing some headers @@ -708,7 +708,7 @@ class SwiftFileBackend extends FileBackendStore { $auth = $this->getAuthentication(); if ( !$auth ) { $objHdrs['x-object-meta-sha1base36'] = false; - return false; // failed + return $objHdrs; // failed } $status = Status::newGood(); @@ -726,7 +726,7 @@ class SwiftFileBackend extends FileBackendStore { 'headers' => $this->authTokenHeaders( $auth ) + $objHdrs ) ); if ( $rcode >= 200 && $rcode <= 299 ) { - return true; // success + return $objHdrs; // success } } } @@ -734,7 +734,7 @@ class SwiftFileBackend extends FileBackendStore { trigger_error( "Unable to set SHA-1 metadata for $path", E_USER_WARNING ); $objHdrs['x-object-meta-sha1base36'] = false; - return false; // failed + return $objHdrs; // failed } protected function doGetFileContentsMulti( array $params ) { @@ -1101,7 +1101,7 @@ class SwiftFileBackend extends FileBackendStore { fclose( $op['stream'] ); // close open handle if ( $rcode >= 200 && $rcode <= 299 // double check that the disk is not full/broken - && $tmpFile->getSize() == $rhdrs['content-length'] + && $tmpFiles[$path]->getSize() == $rhdrs['content-length'] ) { // good } elseif ( $rcode === 404 ) { @@ -1136,8 +1136,10 @@ class SwiftFileBackend extends FileBackendStore { if ( $this->swiftTempUrlKey != '' ) { $url = $this->storageUrl( $auth, $srcCont, $srcRel ); + // Swift wants the signature based on the unencoded object name + $contPath = parse_url( $this->storageUrl( $auth, $srcCont ), PHP_URL_PATH ); $signature = hash_hmac( 'sha1', - "GET\n{$expires}\n" . parse_url( $url, PHP_URL_PATH ), + "GET\n{$expires}\n{$contPath}/{$srcRel}", $this->swiftTempUrlKey ); return "{$url}?temp_url_sig={$signature}&temp_url_expires={$expires}"; @@ -1183,7 +1185,7 @@ class SwiftFileBackend extends FileBackendStore { protected function headersFromParams( array $params ) { $hdrs = array(); if ( !empty( $params['latest'] ) ) { - $hdrs[] = 'X-Newest: true'; + $hdrs['x-newest'] = 'true'; } return $hdrs; @@ -1216,7 +1218,8 @@ class SwiftFileBackend extends FileBackendStore { } // Run all requests for the first stage, then the next, and so on - for ( $stage = 0; $stage < count( $httpReqsByStage ); ++$stage ) { + $reqCount = count( $httpReqsByStage ); + for ( $stage = 0; $stage < $reqCount; ++$stage ) { $httpReqs = $this->http->runMulti( $httpReqsByStage[$stage] ); foreach ( $httpReqs as $index => $httpReq ) { // Run the callback for each request of this operation @@ -1568,11 +1571,11 @@ class SwiftFileBackend extends FileBackendStore { * Log an unexpected exception for this backend. * This also sets the Status object to have a fatal error. * - * @param Status $code null + * @param Status|null $status * @param string $func * @param array $params * @param string $err Error string - * @param integer $status HTTP status + * @param integer $code HTTP status * @param string $desc HTTP status description */ public function onError( $status, $func, array $params, $err = '', $code = 0, $desc = '' ) {