filebackend: use AtEase in FileBackend related classes
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 20 Aug 2019 14:09:16 +0000 (10:09 -0400)
committerKrinkle <krinklemail@gmail.com>
Fri, 23 Aug 2019 13:46:30 +0000 (13:46 +0000)
Change-Id: I819e0e923dfd3ffa7299acd1d6103e3cdf2baa93

includes/libs/filebackend/FileBackendStore.php
includes/libs/filebackend/HTTPFileStreamer.php
includes/libs/filebackend/MemoryFileBackend.php
includes/libs/filebackend/SwiftFileBackend.php
includes/libs/filebackend/fileop/FileOp.php
includes/libs/filebackend/fileop/StoreFileOp.php
includes/libs/filebackend/fsfile/FSFile.php
includes/libs/filebackend/fsfile/TempFSFile.php

index e2a25fc..aa95ee4 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup FileBackend
  */
+use Wikimedia\AtEase\AtEase;
 use Wikimedia\Timestamp\ConvertibleTimestamp;
 
 /**
@@ -376,9 +377,9 @@ abstract class FileBackendStore extends FileBackend {
                unset( $params['latest'] ); // sanity
 
                // Check that the specified temp file is valid...
-               Wikimedia\suppressWarnings();
+               AtEase::suppressWarnings();
                $ok = ( is_file( $tmpPath ) && filesize( $tmpPath ) == 0 );
-               Wikimedia\restoreWarnings();
+               AtEase::restoreWarnings();
                if ( !$ok ) { // not present or not empty
                        $status->fatal( 'backend-fail-opentemp', $tmpPath );
 
@@ -714,9 +715,9 @@ abstract class FileBackendStore extends FileBackend {
        protected function doGetFileContentsMulti( array $params ) {
                $contents = [];
                foreach ( $this->doGetLocalReferenceMulti( $params ) as $path => $fsFile ) {
-                       Wikimedia\suppressWarnings();
+                       AtEase::suppressWarnings();
                        $contents[$path] = $fsFile ? file_get_contents( $fsFile->getPath() ) : false;
-                       Wikimedia\restoreWarnings();
+                       AtEase::restoreWarnings();
                }
 
                return $contents;
index 7a11aeb..653a102 100644 (file)
@@ -19,6 +19,8 @@
  *
  * @file
  */
+
+use Wikimedia\AtEase\AtEase;
 use Wikimedia\Timestamp\ConvertibleTimestamp;
 
 /**
@@ -100,9 +102,9 @@ class HTTPFileStreamer {
                                is_int( $header ) ? HttpStatus::header( $header ) : header( $header );
                        };
 
-               Wikimedia\suppressWarnings();
+               AtEase::suppressWarnings();
                $info = stat( $this->path );
-               Wikimedia\restoreWarnings();
+               AtEase::restoreWarnings();
 
                if ( !is_array( $info ) ) {
                        if ( $sendErrors ) {
index 3932f34..f0cbf3b 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup FileBackend
  */
 
+use Wikimedia\AtEase\AtEase;
+
 /**
  * Simulation of a backend storage in memory.
  *
@@ -70,9 +72,9 @@ class MemoryFileBackend extends FileBackendStore {
                        return $status;
                }
 
-               Wikimedia\suppressWarnings();
+               AtEase::suppressWarnings();
                $data = file_get_contents( $params['src'] );
-               Wikimedia\restoreWarnings();
+               AtEase::restoreWarnings();
                if ( $data === false ) { // source doesn't exist?
                        $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
 
index d6a0c6c..afd1688 100644 (file)
@@ -22,6 +22,8 @@
  * @author Russ Nelson
  */
 
+use Wikimedia\AtEase\AtEase;
+
 /**
  * @brief Class for an OpenStack Swift (or Ceph RGW) based file backend.
  *
@@ -326,9 +328,9 @@ class SwiftFileBackend extends FileBackendStore {
                        return $status;
                }
 
-               Wikimedia\suppressWarnings();
+               AtEase::suppressWarnings();
                $sha1Hash = sha1_file( $params['src'] );
-               Wikimedia\restoreWarnings();
+               AtEase::restoreWarnings();
                if ( $sha1Hash === false ) { // source doesn't exist?
                        $status->fatal( 'backend-fail-store', $params['src'], $params['dst'] );
 
index 206048b..961fdb9 100644 (file)
@@ -77,7 +77,7 @@ abstract class FileOp {
         * @param FileBackendStore $backend
         * @param array $params
         * @param LoggerInterface $logger PSR logger instance
-        * @throws FileBackendError
+        * @throws InvalidArgumentException
         */
        final public function __construct(
                FileBackendStore $backend, array $params, LoggerInterface $logger
index 69ae47f..5783a82 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup FileBackend
  */
 
+use Wikimedia\AtEase\AtEase;
+
 /**
  * Store a file into the backend from a file on the file system.
  * Parameters for this operation are outlined in FileBackend::doOperations().
@@ -77,9 +79,9 @@ class StoreFileOp extends FileOp {
        }
 
        protected function getSourceSha1Base36() {
-               Wikimedia\suppressWarnings();
+               AtEase::suppressWarnings();
                $hash = sha1_file( $this->params['src'] );
-               Wikimedia\restoreWarnings();
+               AtEase::restoreWarnings();
                if ( $hash !== false ) {
                        $hash = Wikimedia\base_convert( $hash, 16, 36, 31 );
                }
index 553c9aa..1937e37 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup FileBackend
  */
 
+use Wikimedia\AtEase\AtEase;
+
 /**
  * Class representing a non-directory file on the file system
  *
@@ -75,9 +77,9 @@ class FSFile {
         * @return string|bool TS_MW timestamp or false on failure
         */
        public function getTimestamp() {
-               Wikimedia\suppressWarnings();
+               AtEase::suppressWarnings();
                $timestamp = filemtime( $this->path );
-               Wikimedia\restoreWarnings();
+               AtEase::restoreWarnings();
                if ( $timestamp !== false ) {
                        $timestamp = wfTimestamp( TS_MW, $timestamp );
                }
@@ -168,9 +170,9 @@ class FSFile {
                        return $this->sha1Base36;
                }
 
-               Wikimedia\suppressWarnings();
+               AtEase::suppressWarnings();
                $this->sha1Base36 = sha1_file( $this->path );
-               Wikimedia\restoreWarnings();
+               AtEase::restoreWarnings();
 
                if ( $this->sha1Base36 !== false ) {
                        $this->sha1Base36 = Wikimedia\base_convert( $this->sha1Base36, 16, 36, 31 );
index 378dbe7..46fa5e1 100644 (file)
@@ -24,6 +24,8 @@ use MediaWiki\FileBackend\FSFile\TempFSFileFactory;
  * @ingroup FileBackend
  */
 
+use Wikimedia\AtEase\AtEase;
+
 /**
  * This class is used to hold the location and do limited manipulation
  * of files stored temporarily (this will be whatever wfTempDir() returns)
@@ -38,7 +40,9 @@ class TempFSFile extends FSFile {
        protected static $pathsCollect = null;
 
        /**
-        * Do not call directly. Use TempFSFileFactory.
+        * Do not call directly. Use TempFSFileFactory
+        *
+        * @param string $path
         */
        public function __construct( $path ) {
                parent::__construct( $path );
@@ -110,9 +114,9 @@ class TempFSFile extends FSFile {
         */
        public function purge() {
                $this->canDelete = false; // done
-               Wikimedia\suppressWarnings();
+               AtEase::suppressWarnings();
                $ok = unlink( $this->path );
-               Wikimedia\restoreWarnings();
+               AtEase::restoreWarnings();
 
                unset( self::$pathsCollect[$this->path] );
 
@@ -172,9 +176,9 @@ class TempFSFile extends FSFile {
         */
        public static function purgeAllOnShutdown() {
                foreach ( self::$pathsCollect as $path => $unused ) {
-                       Wikimedia\suppressWarnings();
+                       AtEase::suppressWarnings();
                        unlink( $path );
-                       Wikimedia\restoreWarnings();
+                       AtEase::restoreWarnings();
                }
        }