X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FCdb_PHP.php;h=1485cc6698b3ccd0bcc3272acc364c52b1128c0f;hb=f96c0ddd63759054b4b91d08496c7a7910275363;hp=f2a044c55bd1a235b05f3f2a3c4faa7c6dc2196e;hpb=0cbc00e3ef25723382049f6235977b26c54265c9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Cdb_PHP.php b/includes/Cdb_PHP.php index f2a044c55b..1485cc6698 100644 --- a/includes/Cdb_PHP.php +++ b/includes/Cdb_PHP.php @@ -1,11 +1,12 @@ > $b ) | ( 0x40000000 >> ( $b - 1 ) ); } else { return $a >> $b; @@ -45,20 +46,21 @@ class CdbFunctions { public static function hash( $s ) { $h = 5381; for ( $i = 0; $i < strlen( $s ); $i++ ) { - $h5 = $h << 5; + $h5 = ($h << 5) & 0xffffffff; // Do a 32-bit sum // Inlined here for speed $sum = ($h & 0x3fffffff) + ($h5 & 0x3fffffff); $h = ( ( $sum & 0x40000000 ? 1 : 0 ) - + ( $h < 0 ? 2 : 0 ) + + ( $h & 0x80000000 ? 2 : 0 ) + ( $h & 0x40000000 ? 1 : 0 ) - + ( $h5 < 0 ? 2 : 0 ) + + ( $h5 & 0x80000000 ? 2 : 0 ) + ( $h5 & 0x40000000 ? 1 : 0 ) ) << 30 | ( $sum & 0x3fffffff ); $h ^= ord( $s[$i] ); + $h &= 0xffffffff; } return $h; } @@ -95,13 +97,14 @@ class CdbReader_PHP extends CdbReader { function __construct( $fileName ) { $this->handle = fopen( $fileName, 'rb' ); if ( !$this->handle ) { - throw new MWException( 'Unable to open DB file "' . $fileName . '"' ); + throw new MWException( 'Unable to open CDB file "' . $fileName . '"' ); } $this->findStart(); } function close() { - fclose( $this->handle ); + if( isset($this->handle) ) + fclose( $this->handle ); unset( $this->handle ); } @@ -135,7 +138,7 @@ class CdbReader_PHP extends CdbReader { $buf = fread( $this->handle, $length ); if ( $buf === false || strlen( $buf ) !== $length ) { - throw new MWException( __METHOD__.': read from cdb file failed, file may be corrupted' ); + throw new MWException( __METHOD__.': read from CDB file failed, file may be corrupted' ); } return $buf; } @@ -221,7 +224,7 @@ class CdbWriter_PHP extends CdbWriter { $this->tmpFileName = $fileName . '.tmp.' . mt_rand( 0, 0x7fffffff ); $this->handle = fopen( $this->tmpFileName, 'wb' ); if ( !$this->handle ) { - throw new MWException( 'Unable to open DB file for write "' . $fileName . '"' ); + throw new MWException( 'Unable to open CDB file for write "' . $fileName . '"' ); } $this->hplist = array(); $this->numentries = 0; @@ -250,8 +253,9 @@ class CdbWriter_PHP extends CdbWriter { public function close() { $this->finish(); - fclose( $this->handle ); - if ( wfIsWindows() ) { + if( isset($this->handle) ) + fclose( $this->handle ); + if ( wfIsWindows() && file_exists($this->realFileName) ) { unlink( $this->realFileName ); } if ( !rename( $this->tmpFileName, $this->realFileName ) ) {