From 8a423dc44e779ad0c47a5ef72af6184f40a6ee97 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 17 Oct 2012 13:15:36 -0700 Subject: [PATCH] [FileBackend] Added more tests and fixed some local copy/reference bugs. Change-Id: I21f635174310a1ce406483b546ae98dec218e5ba --- includes/filebackend/FSFileBackend.php | 6 +++-- .../includes/filerepo/FileBackendTest.php | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/includes/filebackend/FSFileBackend.php b/includes/filebackend/FSFileBackend.php index 092291921f..dd43f82921 100644 --- a/includes/filebackend/FSFileBackend.php +++ b/includes/filebackend/FSFileBackend.php @@ -670,8 +670,8 @@ class FSFileBackend extends FileBackendStore { foreach ( $params['srcs'] as $src ) { $source = $this->resolveToFSPath( $src ); - if ( $source === null ) { - $fsFiles[$src] = null; // invalid path + if ( $source === null || !is_file( $source ) ) { + $fsFiles[$src] = null; // invalid path or file does not exist } else { $fsFiles[$src] = new FSFile( $source ); } @@ -700,7 +700,9 @@ class FSFileBackend extends FileBackendStore { } else { $tmpPath = $tmpFile->getPath(); // Copy the source file over the temp file + wfSuppressWarnings(); $ok = copy( $source, $tmpPath ); + wfRestoreWarnings(); if ( !$ok ) { $tmpFiles[$src] = null; } else { diff --git a/tests/phpunit/includes/filerepo/FileBackendTest.php b/tests/phpunit/includes/filerepo/FileBackendTest.php index f159d5d8f2..7201eec3f1 100644 --- a/tests/phpunit/includes/filerepo/FileBackendTest.php +++ b/tests/phpunit/includes/filerepo/FileBackendTest.php @@ -1113,6 +1113,32 @@ class FileBackendTest extends MediaWikiTestCase { return $cases; } + public function testGetLocalCopyAndReference404() { + $this->backend = $this->singleBackend; + $this->tearDownFiles(); + $this->doTestGetLocalCopyAndReference404(); + $this->tearDownFiles(); + + $this->backend = $this->multiBackend; + $this->tearDownFiles(); + $this->doTestGetLocalCopyAndReference404(); + $this->tearDownFiles(); + } + + public function doTestGetLocalCopyAndReference404() { + $backendName = $this->backendClass(); + + $base = self::baseStorePath(); + + $tmpFile = $this->backend->getLocalCopy( array( + 'src' => "$base/unittest-cont1/not-there" ) ); + $this->assertEquals( null, $tmpFile, "Local copy of not existing file is null ($backendName)." ); + + $tmpFile = $this->backend->getLocalReference( array( + 'src' => "$base/unittest-cont1/not-there" ) ); + $this->assertEquals( null, $tmpFile, "Local ref of not existing file is null ($backendName)." ); + } + /** * @dataProvider provider_testPrepareAndClean */ -- 2.20.1