Author: kn
Date: Thu Oct  4 10:56:19 2007
New Revision: 6354

Log:
- Catch delete errors in file backend

Modified:
    trunk/Webdav/src/backends/file.php
    trunk/Webdav/src/backends/simple.php
    trunk/Webdav/tests/backend_file_test.php

Modified: trunk/Webdav/src/backends/file.php
==============================================================================
--- trunk/Webdav/src/backends/file.php [iso-8859-1] (original)
+++ trunk/Webdav/src/backends/file.php [iso-8859-1] Thu Oct  4 10:56:19 2007
@@ -583,16 +583,13 @@
      * of 0 means, that only the current file or directory will be copied,
      * without any recursion.
      *
-     * @throws ezcBaseFileNotFoundException
-     *      If the $sourceDir directory is not a directory or does not exist.
-     * @throws ezcBaseFilePermissionException 
-     *      If the $sourceDir directory could not be opened for reading, or the
-     *      destination is not writeable.
+     * Returns an empty array if no errors occured, and an array with the files
+     * which caused errors otherwise.
      * 
      * @param string $source 
      * @param string $destination 
      * @param int $depth 
-     * @return void
+     * @return array
      */
     public function copyRecursive( $source, $destination, $depth = 
ezcWebdavRequest::DEPTH_INFINITY )
     {
@@ -689,17 +686,75 @@
     }
 
     /**
+     * Check recusively if everything can be deleted.
+     *
+     * Check files and directories recursively, if everything can be deleted.
+     *
+     * Returns an empty array if no errors occured, and an array with the files
+     * which caused errors otherwise.
+     *
+     * @param string $source 
+     * @return array
+     */
+    public function checkDeleteRecursive( $source )
+    {
+        // Skip non readable files in source directory, or non writeable
+        // destination directories.
+        if ( !is_writeable( dirname( $source ) ) )
+        {
+            return array( $source );
+        }
+
+        if ( is_file( $source ) )
+        {
+            // For plain files the above checks should be sufficant
+            return array();
+        }
+
+        // Recurse
+        $dh = opendir( $source );
+        $errors = array();
+        while( $file = readdir( $dh ) )
+        {
+            if ( ( $file === '.' ) ||
+                 ( $file === '..' ) )
+            {
+                continue;
+            }
+
+            $errors = array_merge(
+                $errors,
+                $this->checkDeleteRecursive( $source . '/' . $file )
+            );
+        }
+        closedir( $dh );
+
+        // Return errors
+        return $errors;
+    }
+
+    /**
      * Delete everything below this path.
      *
-     * Returns false if the delete process failed.
+     * Returns an error response if the deletion failed, and null on success.
      * 
      * @param string $path 
-     * @return array(ezcWebdavErrorResponse)
+     * @return ezcWebdavErrorResponse
      */
     protected function performDelete( $path )
     {
-        // @TODO: Handle errors
-        //
+        $errors = $this->checkDeleteRecursive( $this->root . $path );
+
+        // If an error will occur return the proper status
+        if ( count( $errors ) )
+        {
+            return new ezcWebdavErrorResponse(
+                ezcWebdavResponse::STATUS_403,
+                $path
+            );
+        }
+
+        // Just delete otherwise
         if ( is_file( $this->root . $path ) )
         {
             unlink( $this->root . $path );
@@ -709,7 +764,14 @@
             ezcBaseFile::removeRecursive( $this->root . $path );
         }
 
-        return array();
+        // Finally empty property storage for removed node
+        $storagePath = $this->getPropertyStoragePath( $path );
+        if ( is_file( $storagePath ) )
+        {
+            unlink( $storagePath );
+        }
+
+        return null;
     }
 
     /**

Modified: trunk/Webdav/src/backends/simple.php
==============================================================================
--- trunk/Webdav/src/backends/simple.php [iso-8859-1] (original)
+++ trunk/Webdav/src/backends/simple.php [iso-8859-1] Thu Oct  4 10:56:19 2007
@@ -140,10 +140,10 @@
     /**
      * Delete everything below this path.
      *
-     * Returns false if the delete process failed.
+     * Returns an error response if the deletion failed, and null on success.
      * 
      * @param string $path 
-     * @return array(ezcWebdavErrorResponse)
+     * @return ezcWebdavErrorResponse
      */
     abstract protected function performDelete( $path );
 
@@ -736,11 +736,9 @@
 
         // Delete
         $deletion = $this->performDelete( $source );
-        if ( count( $deletion ) > 0 )
-        {
-            return new ezcWebdavMultistatusResponse(
-                $deletion
-            );
+        if ( $deletion !== null )
+        {
+            return $deletion;
         }
 
         // Send proper response on success

Modified: trunk/Webdav/tests/backend_file_test.php
==============================================================================
--- trunk/Webdav/tests/backend_file_test.php [iso-8859-1] (original)
+++ trunk/Webdav/tests/backend_file_test.php [iso-8859-1] Thu Oct  4 10:56:19 
2007
@@ -963,7 +963,7 @@
             'Expected existing file.'
         );
 
-        chmod ( $this->tempDir . 'backend/collection/test.txt', 0 );
+        chmod ( $this->tempDir . 'backend/collection', 0 );
 
         $request = new ezcWebdavDeleteRequest( '/collection/test.txt' );
         $request->validateHeaders();
@@ -972,7 +972,7 @@
         $this->assertEquals(
             $response,
             new ezcWebdavErrorResponse(
-                ezcWebdavResponse::STATUS_423,
+                ezcWebdavResponse::STATUS_403,
                 '/collection/test.txt'
             ),
             'Expected response does not match real response.',
@@ -985,7 +985,7 @@
             'Expected still existing file.'
         );
 
-        chmod ( $this->tempDir . 'backend/collection/test.txt', 0777 );
+        chmod ( $this->tempDir . 'backend/collection', 0777 );
     }
 
     public function testMakeCollectionOnExistingCollection()


-- 
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to