r12933 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12932‎ | r12933 | r12934 >
Date:07:07, 2 February 2006
Author:timstarling
Status:old
Tags:
Comment:
More robust directory structure migration, should fix bug #2532, except for Brion's complaint that the directory structure should be completely different, which he is free to fix in his own time.
Modified paths:
  • /trunk/phase3/includes/Image.php (modified) (history)
  • /trunk/phase3/thumb.php (modified) (history)

Diff [purge]

Index: trunk/phase3/thumb.php
@@ -49,7 +49,7 @@
5050 }
5151 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
5252
53 -if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
 53+if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
5454 wfStreamFile( $thumbPath );
5555 exit;
5656 }
Index: trunk/phase3/includes/Image.php
@@ -967,13 +967,41 @@
968968 $thumbName = $this->thumbName( $width, $this->fromSharedDirectory );
969969 $thumbPath = wfImageThumbDir( $this->name, $this->fromSharedDirectory ).'/'.$thumbName;
970970
 971+ if ( is_dir( $thumbPath ) ) {
 972+ // Directory where file should be
 973+ // This happened occasionally due to broken migration code in 1.5
 974+ // Rename to broken-*
 975+ global $wgUploadDirectory;
 976+ for ( $i = 0; $i < 100 ; $i++ ) {
 977+ $broken = "$wgUploadDirectory/broken-$i-$thumbName";
 978+ if ( !file_exists( $broken ) ) {
 979+ rename( $thumbPath, $broken );
 980+ break;
 981+ }
 982+ }
 983+ // Code below will ask if it exists, and the answer is now no
 984+ clearstatcache();
 985+ }
 986+
971987 if ( !file_exists( $thumbPath ) ||
972988 filemtime( $thumbPath ) < wfTimestamp( TS_UNIX, $wgThumbnailEpoch ) ) {
973989 $oldThumbPath = wfDeprecatedThumbDir( $thumbName, 'thumb', $this->fromSharedDirectory ).
974990 '/'.$thumbName;
975991 $done = false;
976 - if ( file_exists( $oldThumbPath ) ) {
 992+
 993+ // Migration from old directory structure
 994+ if ( is_file( $oldThumbPath ) ) {
977995 if ( filemtime($oldThumbPath) >= filemtime($this->imagePath) ) {
 996+ if ( file_exists( $thumbPath ) ) {
 997+ if ( !is_dir( $thumbPath ) ) {
 998+ // Old image in the way of rename
 999+ unlink( $thumbPath );
 1000+ } else {
 1001+ // This should have been dealt with already
 1002+ wfDebugDieBacktrace( "Directory where image should be: $thumbPath" );
 1003+ }
 1004+ }
 1005+ // Rename the old image into the new location
9781006 rename( $oldThumbPath, $thumbPath );
9791007 $done = true;
9801008 } else {
@@ -1608,6 +1636,10 @@
16091637 }
16101638
16111639 if ( ! is_dir( $dir ) ) {
 1640+ if ( is_file( $dir ) ) {
 1641+ // Old thumbnail in the way of directory creation, kill it
 1642+ unlink( $dir );
 1643+ }
16121644 $oldumask = umask(0);
16131645 @mkdir( $dir, 0777 );
16141646 umask( $oldumask );

Follow-up revisions

RevisionCommit summaryAuthorDate
r12936More robust directory structure migration, should fix bug #2532, except for B...timstarling07:26, 2 February 2006

Status & tagging log