[FileBackend] Fixed "ignoreMissingSource" bug in multiwrite backend.
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 12 Mar 2013 20:39:40 +0000 (13:39 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 12 Mar 2013 20:39:40 +0000 (13:39 -0700)
* 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

includes/filebackend/FileBackendMultiWrite.php
tests/phpunit/includes/filebackend/FileBackendTest.php

index 1e98adc..939315d 100644 (file)
@@ -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'] );
index b7cf446..9fbf7bb 100644 (file)
@@ -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;
        }