filebackend: Clean up TempFSFile and fix IDEA errors
Change-Id: I4e25e3bf906fa3a918f4462fac1a6be5e85696aa
This commit is contained in:
parent
5353260265
commit
b3c80a0ff5
1 changed files with 11 additions and 14 deletions
|
|
@ -31,9 +31,6 @@ class TempFSFile extends FSFile {
|
||||||
/** @var bool Garbage collect the temp file */
|
/** @var bool Garbage collect the temp file */
|
||||||
protected $canDelete = false;
|
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 */
|
/** @var array Map of (path => 1) for paths to delete on shutdown */
|
||||||
protected static $pathsCollect = null;
|
protected static $pathsCollect = null;
|
||||||
|
|
||||||
|
|
@ -55,26 +52,26 @@ class TempFSFile extends FSFile {
|
||||||
* @return TempFSFile|null
|
* @return TempFSFile|null
|
||||||
*/
|
*/
|
||||||
public static function factory( $prefix, $extension = '' ) {
|
public static function factory( $prefix, $extension = '' ) {
|
||||||
$base = wfTempDir() . '/' . $prefix . wfRandomString( 12 );
|
$ext = ( $extension != '' ) ? ".{$extension}" : '';
|
||||||
$ext = ( $extension != '' ) ? ".{$extension}" : "";
|
|
||||||
for ( $attempt = 1; true; $attempt++ ) {
|
$attempts = 5;
|
||||||
$path = "{$base}-{$attempt}{$ext}";
|
while ( $attempts-- ) {
|
||||||
|
$path = wfTempDir() . '/' . $prefix . wfRandomString( 12 ) . $ext;
|
||||||
MediaWiki\suppressWarnings();
|
MediaWiki\suppressWarnings();
|
||||||
$newFileHandle = fopen( $path, 'x' );
|
$newFileHandle = fopen( $path, 'x' );
|
||||||
MediaWiki\restoreWarnings();
|
MediaWiki\restoreWarnings();
|
||||||
if ( $newFileHandle ) {
|
if ( $newFileHandle ) {
|
||||||
fclose( $newFileHandle );
|
fclose( $newFileHandle );
|
||||||
break; // got it
|
|
||||||
}
|
|
||||||
if ( $attempt >= 5 ) {
|
|
||||||
return null; // give up
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$tmpFile = new self( $path );
|
$tmpFile = new self( $path );
|
||||||
$tmpFile->autocollect(); // safely instantiated
|
$tmpFile->autocollect();
|
||||||
|
// Safely instantiated, end loop.
|
||||||
return $tmpFile;
|
return $tmpFile;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Give up
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purge this file off the file system
|
* Purge this file off the file system
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue