Index: trunk/phase3/includes/Cdb_PHP.php |
— | — | @@ -82,6 +82,9 @@ |
83 | 83 | * CDB reader class |
84 | 84 | */ |
85 | 85 | class CdbReader_PHP extends CdbReader { |
| 86 | + /** The filename */ |
| 87 | + var $fileName; |
| 88 | + |
86 | 89 | /** The file handle */ |
87 | 90 | var $handle; |
88 | 91 | |
— | — | @@ -110,9 +113,10 @@ |
111 | 114 | * @param $fileName string |
112 | 115 | */ |
113 | 116 | function __construct( $fileName ) { |
| 117 | + $this->fileName = $fileName; |
114 | 118 | $this->handle = fopen( $fileName, 'rb' ); |
115 | 119 | if ( !$this->handle ) { |
116 | | - throw new MWException( 'Unable to open CDB file "' . $fileName . '"' ); |
| 120 | + throw new MWException( 'Unable to open CDB file "' . $this->fileName . '".' ); |
117 | 121 | } |
118 | 122 | $this->findStart(); |
119 | 123 | } |
— | — | @@ -160,7 +164,8 @@ |
161 | 165 | protected function read( $length, $pos ) { |
162 | 166 | if ( fseek( $this->handle, $pos ) == -1 ) { |
163 | 167 | // This can easily happen if the internal pointers are incorrect |
164 | | - throw new MWException( __METHOD__.': seek failed, file may be corrupted.' ); |
| 168 | + throw new MWException( |
| 169 | + 'Seek failed, file "' . $this->fileName . '" may be corrupted.' ); |
165 | 170 | } |
166 | 171 | |
167 | 172 | if ( $length == 0 ) { |
— | — | @@ -169,7 +174,8 @@ |
170 | 175 | |
171 | 176 | $buf = fread( $this->handle, $length ); |
172 | 177 | if ( $buf === false || strlen( $buf ) !== $length ) { |
173 | | - throw new MWException( __METHOD__.': read from CDB file failed, file may be corrupted' ); |
| 178 | + throw new MWException( |
| 179 | + 'Read from CDB file failed, file "' . $this->fileName . '" may be corrupted.' ); |
174 | 180 | } |
175 | 181 | return $buf; |
176 | 182 | } |
— | — | @@ -182,7 +188,8 @@ |
183 | 189 | protected function unpack31( $s ) { |
184 | 190 | $data = unpack( 'V', $s ); |
185 | 191 | if ( $data[1] > 0x7fffffff ) { |
186 | | - throw new MWException( __METHOD__.': error in CDB file, integer too big' ); |
| 192 | + throw new MWException( |
| 193 | + 'Error in CDB file "' . $this->fileName . '", integer too big.' ); |
187 | 194 | } |
188 | 195 | return $data[1]; |
189 | 196 | } |
— | — | @@ -270,13 +277,15 @@ |
271 | 278 | $this->tmpFileName = $fileName . '.tmp.' . mt_rand( 0, 0x7fffffff ); |
272 | 279 | $this->handle = fopen( $this->tmpFileName, 'wb' ); |
273 | 280 | if ( !$this->handle ) { |
274 | | - throw new MWException( 'Unable to open CDB file for write "' . $fileName . '"' ); |
| 281 | + throw new MWException( |
| 282 | + 'Unable to open CDB file "' . $this->tmpFileName . '" for write.' ); |
275 | 283 | } |
276 | 284 | $this->hplist = array(); |
277 | 285 | $this->numentries = 0; |
278 | 286 | $this->pos = 2048; // leaving space for the pointer array, 256 * 8 |
279 | 287 | if ( fseek( $this->handle, $this->pos ) == -1 ) { |
280 | | - throw new MWException( __METHOD__.': fseek failed' ); |
| 288 | + throw new MWException( |
| 289 | + 'fseek failed in file "' . $this->tmpFileName . '".' ); |
281 | 290 | } |
282 | 291 | } |
283 | 292 | |
— | — | @@ -326,7 +335,7 @@ |
327 | 336 | protected function write( $buf ) { |
328 | 337 | $len = fwrite( $this->handle, $buf ); |
329 | 338 | if ( $len !== strlen( $buf ) ) { |
330 | | - throw new MWException( 'Error writing to CDB file.' ); |
| 339 | + throw new MWException( 'Error writing to CDB file "'.$this->tmpFileName.'".' ); |
331 | 340 | } |
332 | 341 | } |
333 | 342 | |
— | — | @@ -337,7 +346,8 @@ |
338 | 347 | protected function posplus( $len ) { |
339 | 348 | $newpos = $this->pos + $len; |
340 | 349 | if ( $newpos > 0x7fffffff ) { |
341 | | - throw new MWException( 'A value in the CDB file is too large' ); |
| 350 | + throw new MWException( |
| 351 | + 'A value in the CDB file "'.$this->tmpFileName.'" is too large.' ); |
342 | 352 | } |
343 | 353 | $this->pos = $newpos; |
344 | 354 | } |
— | — | @@ -366,10 +376,10 @@ |
367 | 377 | */ |
368 | 378 | protected function addbegin( $keylen, $datalen ) { |
369 | 379 | if ( $keylen > 0x7fffffff ) { |
370 | | - throw new MWException( __METHOD__.': key length too long' ); |
| 380 | + throw new MWException( 'Key length too long in file "'.$this->tmpFileName.'".' ); |
371 | 381 | } |
372 | 382 | if ( $datalen > 0x7fffffff ) { |
373 | | - throw new MWException( __METHOD__.': data length too long' ); |
| 383 | + throw new MWException( 'Data length too long in file "'.$this->tmpFileName.'".' ); |
374 | 384 | } |
375 | 385 | $buf = pack( 'VV', $keylen, $datalen ); |
376 | 386 | $this->write( $buf ); |
— | — | @@ -444,7 +454,7 @@ |
445 | 455 | // Write the pointer array at the start of the file |
446 | 456 | rewind( $this->handle ); |
447 | 457 | if ( ftell( $this->handle ) != 0 ) { |
448 | | - throw new MWException( __METHOD__.': Error rewinding to start of file' ); |
| 458 | + throw new MWException( 'Error rewinding to start of file "'.$this->tmpFileName.'".' ); |
449 | 459 | } |
450 | 460 | $this->write( $final ); |
451 | 461 | } |