r12936 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r12935‎ | r12936 | r12937 >
Date:07:26, 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. (backport from HEAD)
Modified paths:
  • /branches/REL1_5/phase3/includes/Image.php (modified) (history)
  • /branches/REL1_5/phase3/thumb.php (modified) (history)

Diff [purge]

Index: branches/REL1_5/phase3/thumb.php
@@ -44,7 +44,7 @@
4545 }
4646 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
4747
48 -if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
 48+if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
4949 wfStreamFile( $thumbPath );
5050 exit;
5151 }
Index: branches/REL1_5/phase3/includes/Image.php
@@ -960,12 +960,40 @@
961961 $thumbName = $this->thumbName( $width, $this->fromSharedDirectory );
962962 $thumbPath = wfImageThumbDir( $this->name, $this->fromSharedDirectory ).'/'.$thumbName;
963963
 964+ if ( is_dir( $thumbPath ) ) {
 965+ // Directory where file should be
 966+ // This happened occasionally due to broken migration code in 1.5
 967+ // Rename to broken-*
 968+ global $wgUploadDirectory;
 969+ for ( $i = 0; $i < 100 ; $i++ ) {
 970+ $broken = "$wgUploadDirectory/broken-$i-$thumbName";
 971+ if ( !file_exists( $broken ) ) {
 972+ rename( $thumbPath, $broken );
 973+ break;
 974+ }
 975+ }
 976+ // Code below will ask if it exists, and the answer is now no
 977+ clearstatcache();
 978+ }
 979+
964980 if ( !file_exists( $thumbPath ) ) {
965981 $oldThumbPath = wfDeprecatedThumbDir( $thumbName, 'thumb', $this->fromSharedDirectory ).
966982 '/'.$thumbName;
967983 $done = false;
968 - if ( file_exists( $oldThumbPath ) ) {
 984+
 985+ // Migration from old directory structure
 986+ if ( is_file( $oldThumbPath ) ) {
969987 if ( filemtime($oldThumbPath) >= filemtime($this->imagePath) ) {
 988+ if ( file_exists( $thumbPath ) ) {
 989+ if ( !is_dir( $thumbPath ) ) {
 990+ // Old image in the way of rename
 991+ unlink( $thumbPath );
 992+ } else {
 993+ // This should have been dealt with already
 994+ wfDebugDieBacktrace( "Directory where image should be: $thumbPath" );
 995+ }
 996+ }
 997+ // Rename the old image into the new location
970998 rename( $oldThumbPath, $thumbPath );
971999 $done = true;
9721000 } else {
@@ -1542,7 +1570,11 @@
15431571 umask( $oldumask );
15441572 }
15451573
1546 - if ( ! is_dir( $dir ) ) {
 1574+ if ( ! is_dir( $dir ) ) {
 1575+ if ( is_file( $dir ) ) {
 1576+ // Old thumbnail in the way of directory creation, kill it
 1577+ unlink( $dir );
 1578+ }
15471579 $oldumask = umask(0);
15481580 @mkdir( $dir, 0777 );
15491581 umask( $oldumask );

Past revisions this follows-up on

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

Status & tagging log