Reduced max TempFSFile::factory() attempts since it uses 12 hex chars.
[lhc/web/wiklou.git] / includes / filebackend / TempFSFile.php
index 00f1080..5032bf6 100644 (file)
@@ -43,7 +43,7 @@ class TempFSFile extends FSFile {
         */
        public static function factory( $prefix, $extension = '' ) {
                wfProfileIn( __METHOD__ );
-               $base = wfTempDir() . '/' . $prefix . dechex( mt_rand( 0, 99999999 ) );
+               $base = wfTempDir() . '/' . $prefix . wfRandomString( 12 );
                $ext = ( $extension != '' ) ? ".{$extension}" : "";
                for ( $attempt = 1; true; $attempt++ ) {
                        $path = "{$base}-{$attempt}{$ext}";
@@ -54,7 +54,7 @@ class TempFSFile extends FSFile {
                                fclose( $newFileHandle );
                                break; // got it
                        }
-                       if ( $attempt >= 15 ) {
+                       if ( $attempt >= 5 ) {
                                wfProfileOut( __METHOD__ );
                                return null; // give up
                        }
@@ -99,6 +99,15 @@ class TempFSFile extends FSFile {
                $this->canDelete = false;
        }
 
+       /**
+        * Set flag clean up after the temporary file
+        *
+        * @return void
+        */
+       public function autocollect() {
+               $this->canDelete = true;
+       }
+
        /**
         * Cleans up after the temporary file by deleting it
         */