From 1045622590d9702dd2f0c0e97c38220a392d20c1 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 12 Mar 2013 13:39:40 -0700 Subject: [PATCH] [FileBackend] Fixed "ignoreMissingSource" bug in multiwrite backend. * Beefed up unit tests for this case and other "ignoreMissingSource" cases such as when the source container or parent directory do not exist. Change-Id: Iea6dae2424edfd0c4367e5cff606c09a4e8a865b --- .../filebackend/FileBackendMultiWrite.php | 8 ++++++- .../includes/filebackend/FileBackendTest.php | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/includes/filebackend/FileBackendMultiWrite.php b/includes/filebackend/FileBackendMultiWrite.php index 1e98adc999..939315d178 100644 --- a/includes/filebackend/FileBackendMultiWrite.php +++ b/includes/filebackend/FileBackendMultiWrite.php @@ -343,7 +343,13 @@ class FileBackendMultiWrite extends FileBackend { $paths = array(); foreach ( $ops as $op ) { if ( isset( $op['src'] ) ) { - $paths[] = $op['src']; + // For things like copy/move/delete with "ignoreMissingSource" and there + // is no source file, nothing should happen and there should be no errors. + if ( empty( $op['ignoreMissingSource'] ) + || $this->fileExists( array( 'src' => $op['src'] ) ) ) + { + $paths[] = $op['src']; + } } if ( isset( $op['srcs'] ) ) { $paths = array_merge( $paths, $op['srcs'] ); diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index b7cf446111..9fbf7bb0a4 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -387,6 +387,14 @@ class FileBackendTest extends MediaWikiTestCase { $dest, // dest ); + $op2 = $op; + $op2['ignoreMissingSource'] = true; + $cases[] = array( + $op2, // operation + self::baseStorePath() . '/unittest-cont-bad/e/file.txt', // source + $dest, // dest + ); + return $cases; } @@ -499,6 +507,14 @@ class FileBackendTest extends MediaWikiTestCase { $dest, // dest ); + $op2 = $op; + $op2['ignoreMissingSource'] = true; + $cases[] = array( + $op2, // operation + self::baseStorePath() . '/unittest-cont-bad/e/file.txt', // source + $dest, // dest + ); + return $cases; } @@ -582,6 +598,14 @@ class FileBackendTest extends MediaWikiTestCase { true // succeeds ); + $op['ignoreMissingSource'] = true; + $op['src'] = self::baseStorePath() . '/unittest-cont-bad/e/file.txt'; + $cases[] = array( + $op, // operation + false, // without source + true // succeeds + ); + return $cases; } -- 2.20.1