diff options
Diffstat (limited to 'includes/filebackend/FileBackendStore.php')
-rw-r--r-- | includes/filebackend/FileBackendStore.php | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/includes/filebackend/FileBackendStore.php b/includes/filebackend/FileBackendStore.php index fe3a068456b1..7980d100675e 100644 --- a/includes/filebackend/FileBackendStore.php +++ b/includes/filebackend/FileBackendStore.php @@ -655,10 +655,15 @@ abstract class FileBackendStore extends FileBackend { $this->cheapCache->set( $path, 'sha1', array( 'hash' => $stat['sha1'], 'latest' => $latest ) ); } + if ( isset( $stat['xattr'] ) ) { // some backends store headers/metadata + $stat['xattr'] = self::normalizeXAttributes( $stat['xattr'] ); + $this->cheapCache->set( $path, 'xattr', + array( 'map' => $stat['xattr'], 'latest' => $latest ) ); + } } elseif ( $stat === false ) { // file does not exist $this->cheapCache->set( $path, 'stat', $latest ? 'NOT_EXIST_LATEST' : 'NOT_EXIST' ); - $this->cheapCache->set( $path, 'sha1', // the SHA-1 must be false too - array( 'hash' => false, 'latest' => $latest ) ); + $this->cheapCache->set( $path, 'xattr', array( 'map' => false, 'latest' => $latest ) ); + $this->cheapCache->set( $path, 'sha1', array( 'hash' => false, 'latest' => $latest ) ); wfDebug( __METHOD__ . ": File $path does not exist.\n" ); } else { // an error occurred wfDebug( __METHOD__ . ": Could not stat file $path.\n" ); @@ -697,6 +702,39 @@ abstract class FileBackendStore extends FileBackend { return $contents; } + final public function getFileXAttributes( array $params ) { + $path = self::normalizeStoragePath( $params['src'] ); + if ( $path === null ) { + return false; // invalid storage path + } + $section = new ProfileSection( __METHOD__ . "-{$this->name}" ); + $latest = !empty( $params['latest'] ); // use latest data? + if ( $this->cheapCache->has( $path, 'xattr', self::CACHE_TTL ) ) { + $stat = $this->cheapCache->get( $path, 'xattr' ); + // If we want the latest data, check that this cached + // value was in fact fetched with the latest available data. + if ( !$latest || $stat['latest'] ) { + return $stat['map']; + } + } + wfProfileIn( __METHOD__ . '-miss' ); + wfProfileIn( __METHOD__ . '-miss-' . $this->name ); + $fields = $this->doGetFileXAttributes( $params ); + $fields = is_array( $fields ) ? self::normalizeXAttributes( $fields ) : false; + wfProfileOut( __METHOD__ . '-miss-' . $this->name ); + wfProfileOut( __METHOD__ . '-miss' ); + $this->cheapCache->set( $path, 'xattr', array( 'map' => $fields, 'latest' => $latest ) ); + return $fields; + } + + /** + * @see FileBackendStore::getFileXAttributes() + * @return bool|string + */ + protected function doGetFileXAttributes( array $params ) { + return array( 'headers' => array(), 'metadata' => array() ); // not supported + } + final public function getFileSha1Base36( array $params ) { $path = self::normalizeStoragePath( $params['src'] ); if ( $path === null ) { @@ -1625,11 +1663,34 @@ abstract class FileBackendStore extends FileBackend { $this->cheapCache->set( $path, 'sha1', array( 'hash' => $val['sha1'], 'latest' => $val['latest'] ) ); } + if ( isset( $val['xattr'] ) ) { // some backends store headers/metadata + $stat['xattr'] = self::normalizeXAttributes( $stat['xattr'] ); + $this->cheapCache->set( $path, 'xattr', + array( 'map' => $val['xattr'], 'latest' => $val['latest'] ) ); + } } } } /** + * Normalize file headers/metadata to the FileBackend::getFileXAttributes() format + * + * @param array $xattr + * @return array + * @since 1.22 + */ + final protected static function normalizeXAttributes( array $xattr ) { + $newXAttr = array( 'headers' => array(), 'metadata' => array() ); + foreach ( $xattr['headers'] as $name => $value ) { + $newXAttr['headers'][strtolower( $name )] = $value; + } + foreach ( $xattr['metadata'] as $name => $value ) { + $newXAttr['metadata'][strtolower( $name )] = $value; + } + return $newXAttr; + } + + /** * Set the 'concurrency' option from a list of operation options * * @param array $opts Map of operation options |