More robust directory structure migration, should fix bug #2532, except for Brion...
authorTim Starling <tstarling@users.mediawiki.org>
Thu, 2 Feb 2006 07:07:39 +0000 (07:07 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Thu, 2 Feb 2006 07:07:39 +0000 (07:07 +0000)
includes/Image.php
thumb.php

index 89cf299..479fdcc 100644 (file)
@@ -967,13 +967,41 @@ class Image
                $thumbName = $this->thumbName( $width, $this->fromSharedDirectory );
                $thumbPath = wfImageThumbDir( $this->name, $this->fromSharedDirectory ).'/'.$thumbName;
 
+               if ( is_dir( $thumbPath ) ) {
+                       // Directory where file should be
+                       // This happened occasionally due to broken migration code in 1.5
+                       // Rename to broken-*
+                       global $wgUploadDirectory;
+                       for ( $i = 0; $i < 100 ; $i++ ) {
+                               $broken = "$wgUploadDirectory/broken-$i-$thumbName";
+                               if ( !file_exists( $broken ) ) {
+                                       rename( $thumbPath, $broken );
+                                       break;
+                               }
+                       }
+                       // Code below will ask if it exists, and the answer is now no
+                       clearstatcache();
+               }
+
                if ( !file_exists( $thumbPath ) ||
                        filemtime( $thumbPath ) < wfTimestamp( TS_UNIX, $wgThumbnailEpoch ) ) {
                        $oldThumbPath = wfDeprecatedThumbDir( $thumbName, 'thumb', $this->fromSharedDirectory ).
                                '/'.$thumbName;
                        $done = false;
-                       if ( file_exists( $oldThumbPath ) ) {
+
+                       // Migration from old directory structure
+                       if ( is_file( $oldThumbPath ) ) {
                                if ( filemtime($oldThumbPath) >= filemtime($this->imagePath) ) {
+                                       if ( file_exists( $thumbPath ) ) {
+                                               if ( !is_dir( $thumbPath ) ) {
+                                                       // Old image in the way of rename
+                                                       unlink( $thumbPath );
+                                               } else {
+                                                       // This should have been dealt with already
+                                                       wfDebugDieBacktrace( "Directory where image should be: $thumbPath" );
+                                               }
+                                       }
+                                       // Rename the old image into the new location
                                        rename( $oldThumbPath, $thumbPath );
                                        $done = true;
                                } else {
@@ -1608,6 +1636,10 @@ function wfImageThumbDir( $fname, $shared = false ) {
                }
 
                if ( ! is_dir( $dir ) ) {
+                       if ( is_file( $dir ) ) {
+                               // Old thumbnail in the way of directory creation, kill it
+                               unlink( $dir );
+                       }
                        $oldumask = umask(0);
                        @mkdir( $dir, 0777 );
                        umask( $oldumask );
index 07a6abc..32dec6d 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -49,7 +49,7 @@ if ( $pre_render ) {
 }
 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
 
-if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
+if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
        wfStreamFile( $thumbPath );
        exit;
 }