[FileBackend] Check if paths are writable for delete ops too.
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 1 Nov 2012 06:36:49 +0000 (23:36 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 1 Nov 2012 06:36:49 +0000 (23:36 -0700)
* Also clarified the docs around isPathUsableInternal().

Change-Id: I3fc10fce43e040f45045d6da69f0211e9ab4155d

includes/filebackend/FileBackendStore.php
includes/filebackend/FileOp.php

index cb8be0b..7e91949 100644 (file)
@@ -72,8 +72,9 @@ abstract class FileBackendStore extends FileBackend {
        }
 
        /**
-        * Check if a file can be created at a given storage path.
-        * FS backends should check if the parent directory exists and the file is writable.
+        * Check if a file can be created or changed at a given storage path.
+        * FS backends should check if the parent directory exists, files can be
+        * written under it, and that any file already there is writable.
         * Backends using key/value stores should check if the container exists.
         *
         * @param $storagePath string
index 20dfda2..ff1b604 100644 (file)
@@ -488,7 +488,7 @@ class StoreFileOp extends FileOp {
                                $this->params['dst'], $this->backend->maxFileSizeInternal() );
                        $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
                        return $status;
-               // Check if a file can be placed at the destination
+               // Check if a file can be placed/changed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
                        $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-store', $this->params['src'], $this->params['dst'] );
@@ -551,7 +551,7 @@ class CreateFileOp extends FileOp {
                                $this->params['dst'], $this->backend->maxFileSizeInternal() );
                        $status->fatal( 'backend-fail-create', $this->params['dst'] );
                        return $status;
-               // Check if a file can be placed at the destination
+               // Check if a file can be placed/changed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
                        $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-create', $this->params['dst'] );
@@ -624,7 +624,7 @@ class CopyFileOp extends FileOp {
                                $status->fatal( 'backend-fail-notexists', $this->params['src'] );
                                return $status;
                        }
-               // Check if a file can be placed at the destination
+               // Check if a file can be placed/changed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
                        $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-copy', $this->params['src'], $this->params['dst'] );
@@ -700,7 +700,7 @@ class MoveFileOp extends FileOp {
                                $status->fatal( 'backend-fail-notexists', $this->params['src'] );
                                return $status;
                        }
-               // Check if a file can be placed at the destination
+               // Check if a file can be placed/changed at the destination
                } elseif ( !$this->backend->isPathUsableInternal( $this->params['dst'] ) ) {
                        $status->fatal( 'backend-fail-usable', $this->params['dst'] );
                        $status->fatal( 'backend-fail-move', $this->params['src'], $this->params['dst'] );
@@ -781,6 +781,11 @@ class DeleteFileOp extends FileOp {
                                $status->fatal( 'backend-fail-notexists', $this->params['src'] );
                                return $status;
                        }
+               // Check if a file can be placed/changed at the source
+               } elseif ( !$this->backend->isPathUsableInternal( $this->params['src'] ) ) {
+                       $status->fatal( 'backend-fail-usable', $this->params['src'] );
+                       $status->fatal( 'backend-fail-delete', $this->params['src'] );
+                       return $status;
                }
                // Update file existence predicates
                $predicates['exists'][$this->params['src']] = false;