From b9766fe1e398979e71ce7b45dbcb338c6e504833 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Thu, 2 Feb 2006 07:07:39 +0000 Subject: [PATCH] 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. --- includes/Image.php | 34 +++++++++++++++++++++++++++++++++- thumb.php | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/includes/Image.php b/includes/Image.php index 89cf299b18..479fdcc6ec 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -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 ); diff --git a/thumb.php b/thumb.php index 07a6abc21a..32dec6df05 100644 --- 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; } -- 2.20.1