jenkins-bot has submitted this change and it was merged.

Change subject: Dependency inject $wgTmpDirectory into FileBackend classes
......................................................................


Dependency inject $wgTmpDirectory into FileBackend classes

Change-Id: I219daffa67ff672bf5bd38921f4b1ca058d96b0f
---
M includes/filebackend/FSFileBackend.php
M includes/filebackend/FileBackendGroup.php
M includes/filebackend/MemoryFileBackend.php
M includes/filebackend/SwiftFileBackend.php
M includes/filerepo/FSRepo.php
M includes/libs/filebackend/FileBackend.php
6 files changed, 13 insertions(+), 5 deletions(-)

Approvals:
  BryanDavis: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/filebackend/FSFileBackend.php 
b/includes/filebackend/FSFileBackend.php
index b0e3eee..45951ec 100644
--- a/includes/filebackend/FSFileBackend.php
+++ b/includes/filebackend/FSFileBackend.php
@@ -195,7 +195,7 @@
                }
 
                if ( !empty( $params['async'] ) ) { // deferred
-                       $tempFile = TempFSFile::factory( 'create_', 'tmp' );
+                       $tempFile = TempFSFile::factory( 'create_', 'tmp', 
$this->tmpDirectory );
                        if ( !$tempFile ) {
                                $status->fatal( 'backend-fail-create', 
$params['dst'] );
 
@@ -653,7 +653,7 @@
                        } else {
                                // Create a new temporary file with the same 
extension...
                                $ext = FileBackend::extensionFromPath( $src );
-                               $tmpFile = TempFSFile::factory( 'localcopy_', 
$ext );
+                               $tmpFile = TempFSFile::factory( 'localcopy_', 
$ext, $this->tmpDirectory );
                                if ( !$tmpFile ) {
                                        $tmpFiles[$src] = null;
                                } else {
diff --git a/includes/filebackend/FileBackendGroup.php 
b/includes/filebackend/FileBackendGroup.php
index 0bae5ff..b560e94 100644
--- a/includes/filebackend/FileBackendGroup.php
+++ b/includes/filebackend/FileBackendGroup.php
@@ -168,6 +168,7 @@
                        $config['wanCache'] = ObjectCache::getMainWANInstance();
                        $config['mimeCallback'] = [ $this, 'guessMimeInternal' 
];
                        $config['statusWrapper'] = [ 'Status', 'wrap' ];
+                       $config['tmpDirectory'] = wfTempDir();
 
                        $this->backends[$name]['instance'] = new $class( 
$config );
                }
@@ -222,7 +223,7 @@
                if ( !$type && $fsPath ) {
                        $type = $magic->guessMimeType( $fsPath, false );
                } elseif ( !$type && strlen( $content ) ) {
-                       $tmpFile = TempFSFile::factory( 'mime_' );
+                       $tmpFile = TempFSFile::factory( 'mime_', '', 
wfTempDir() );
                        file_put_contents( $tmpFile->getPath(), $content );
                        $type = $magic->guessMimeType( $tmpFile->getPath(), 
false );
                }
diff --git a/includes/filebackend/MemoryFileBackend.php 
b/includes/filebackend/MemoryFileBackend.php
index 74a0068..44fe2cb 100644
--- a/includes/filebackend/MemoryFileBackend.php
+++ b/includes/filebackend/MemoryFileBackend.php
@@ -169,7 +169,7 @@
                        } else {
                                // Create a new temporary file with the same 
extension...
                                $ext = FileBackend::extensionFromPath( $src );
-                               $fsFile = TempFSFile::factory( 'localcopy_', 
$ext );
+                               $fsFile = TempFSFile::factory( 'localcopy_', 
$ext, $this->tmpDirectory );
                                if ( $fsFile ) {
                                        $bytes = file_put_contents( 
$fsFile->getPath(), $this->files[$src]['data'] );
                                        if ( $bytes !== strlen( 
$this->files[$src]['data'] ) ) {
diff --git a/includes/filebackend/SwiftFileBackend.php 
b/includes/filebackend/SwiftFileBackend.php
index a0027e4..0a0e9f5 100644
--- a/includes/filebackend/SwiftFileBackend.php
+++ b/includes/filebackend/SwiftFileBackend.php
@@ -1127,7 +1127,7 @@
                        // Get source file extension
                        $ext = FileBackend::extensionFromPath( $path );
                        // Create a new temporary file...
-                       $tmpFile = TempFSFile::factory( 'localcopy_', $ext );
+                       $tmpFile = TempFSFile::factory( 'localcopy_', $ext, 
$this->tmpDirectory );
                        if ( $tmpFile ) {
                                $handle = fopen( $tmpFile->getPath(), 'wb' );
                                if ( $handle ) {
diff --git a/includes/filerepo/FSRepo.php b/includes/filerepo/FSRepo.php
index b24354d..d06acf2 100644
--- a/includes/filerepo/FSRepo.php
+++ b/includes/filerepo/FSRepo.php
@@ -66,6 +66,7 @@
                                        "{$repoName}-deleted" => $deletedDir
                                ],
                                'fileMode' => $fileMode,
+                               'tmpDirectory' => wfTempDir()
                        ] );
                        // Update repo config to use this backend
                        $info['backend'] = $backend;
diff --git a/includes/libs/filebackend/FileBackend.php 
b/includes/libs/filebackend/FileBackend.php
index 4ff342f..1317b65 100644
--- a/includes/libs/filebackend/FileBackend.php
+++ b/includes/libs/filebackend/FileBackend.php
@@ -98,6 +98,9 @@
        /** @var int How many operations can be done in parallel */
        protected $concurrency;
 
+       /** @var string Temporary file directory */
+       protected $tmpDirectory;
+
        /** @var LockManager */
        protected $lockManager;
 
@@ -134,6 +137,8 @@
         *   - parallelize : When to do file operations in parallel (when 
possible).
         *                   Allowed values are "implicit", "explicit" and 
"off".
         *   - concurrency : How many file operations can be done in parallel.
+        *   - tmpDirectory : Directory to use for temporary files. If this is 
not set or null,
+        *                    then the backend will try to discover a usable 
temporary directory.
         * @throws FileBackendException
         */
        public function __construct( array $config ) {
@@ -160,6 +165,7 @@
                        ? (int)$config['concurrency']
                        : 50;
                $this->statusWrapper = isset( $config['statusWrapper'] ) ? 
$config['statusWrapper'] : null;
+               $this->tmpDirectory = isset( $config['tmpDirectory'] ) ? 
$config['tmpDirectory'] : null;
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/311905
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I219daffa67ff672bf5bd38921f4b1ca058d96b0f
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: BryanDavis <bda...@wikimedia.org>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to