From: Aaron Schulz Date: Fri, 26 Feb 2016 03:17:46 +0000 (-0800) Subject: filebackend: Clean up TempFSFile and fix IDEA errors X-Git-Tag: 1.31.0-rc.0~7751^2 X-Git-Url: http://git.cyclocoop.org/%22%20%20.%20generer_url_ecrire%28%22mots_tous%22%29%20.%20%22?a=commitdiff_plain;h=b3c80a0ff5bfb51e8406c2dda43c53a9a7421a38;p=lhc%2Fweb%2Fwiklou.git filebackend: Clean up TempFSFile and fix IDEA errors Change-Id: I4e25e3bf906fa3a918f4462fac1a6be5e85696aa --- diff --git a/includes/filebackend/TempFSFile.php b/includes/filebackend/TempFSFile.php index 3ec34f18a1..f57284080d 100644 --- a/includes/filebackend/TempFSFile.php +++ b/includes/filebackend/TempFSFile.php @@ -31,9 +31,6 @@ class TempFSFile extends FSFile { /** @var bool Garbage collect the temp file */ protected $canDelete = false; - /** @var array Active temp files to purge on shutdown */ - protected static $instances = []; - /** @var array Map of (path => 1) for paths to delete on shutdown */ protected static $pathsCollect = null; @@ -55,25 +52,25 @@ class TempFSFile extends FSFile { * @return TempFSFile|null */ public static function factory( $prefix, $extension = '' ) { - $base = wfTempDir() . '/' . $prefix . wfRandomString( 12 ); - $ext = ( $extension != '' ) ? ".{$extension}" : ""; - for ( $attempt = 1; true; $attempt++ ) { - $path = "{$base}-{$attempt}{$ext}"; + $ext = ( $extension != '' ) ? ".{$extension}" : ''; + + $attempts = 5; + while ( $attempts-- ) { + $path = wfTempDir() . '/' . $prefix . wfRandomString( 12 ) . $ext; MediaWiki\suppressWarnings(); $newFileHandle = fopen( $path, 'x' ); MediaWiki\restoreWarnings(); if ( $newFileHandle ) { fclose( $newFileHandle ); - break; // got it - } - if ( $attempt >= 5 ) { - return null; // give up + $tmpFile = new self( $path ); + $tmpFile->autocollect(); + // Safely instantiated, end loop. + return $tmpFile; } } - $tmpFile = new self( $path ); - $tmpFile->autocollect(); // safely instantiated - return $tmpFile; + // Give up + return null; } /**