X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ffilebackend%2FFSFile.php;h=7d0dbd522833ddce8754525422f37fe874a31ff9;hb=44291b29fece62799bea799deecf1ea6fffa80b4;hp=acbc4a996d888b70a51402170e7d426c2dbab0cd;hpb=e8c5b7f35722bb52dbe0e6c7853d3e73df27819e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filebackend/FSFile.php b/includes/filebackend/FSFile.php index acbc4a996d..7d0dbd5228 100644 --- a/includes/filebackend/FSFile.php +++ b/includes/filebackend/FSFile.php @@ -28,11 +28,12 @@ */ class FSFile { protected $path; // path to file + private $sha1Base36 = null; // File Sha1Base36 /** * Sets up the file object * - * @param $path string Path to temporary file on local disk + * @param string $path Path to temporary file on local disk * @throws MWException */ public function __construct( $path ) { @@ -193,20 +194,27 @@ class FSFile { * 160 log 2 / log 36 = 30.95, so the 160-bit hash fills 31 digits in base 36 * fairly neatly. * + * @param $recache bool * @return bool|string False on failure */ - public function getSha1Base36() { + public function getSha1Base36( $recache = false ) { wfProfileIn( __METHOD__ ); + if ( $this->sha1Base36 !== null && !$recache ) { + wfProfileOut( __METHOD__ ); + return $this->sha1Base36; + } + wfSuppressWarnings(); - $hash = sha1_file( $this->path ); + $this->sha1Base36 = sha1_file( $this->path ); wfRestoreWarnings(); - if ( $hash !== false ) { - $hash = wfBaseConvert( $hash, 16, 36, 31 ); + + if ( $this->sha1Base36 !== false ) { + $this->sha1Base36 = wfBaseConvert( $this->sha1Base36, 16, 36, 31 ); } wfProfileOut( __METHOD__ ); - return $hash; + return $this->sha1Base36; } /** @@ -223,7 +231,7 @@ class FSFile { /** * Get an associative array containing information about a file in the local filesystem. * - * @param $path String: absolute local filesystem path + * @param string $path absolute local filesystem path * @param $ext Mixed: the file extension, or true to extract it from the filename. * Set it to false to ignore the extension. * @@ -242,11 +250,18 @@ class FSFile { * fairly neatly. * * @param $path string + * @param $recache bool * * @return bool|string False on failure */ - public static function getSha1Base36FromPath( $path ) { - $fsFile = new self( $path ); - return $fsFile->getSha1Base36(); + public static function getSha1Base36FromPath( $path, $recache = false ) { + static $sha1Base36 = array(); + + if ( !isset( $sha1Base36[$path] ) || $recache ) { + $fsFile = new self( $path ); + $sha1Base36[$path] = $fsFile->getSha1Base36(); + } + + return $sha1Base36[$path]; } }