Index: kernel/classes/clusterfilehandlers/ezdbfilehandler.php
===================================================================
--- kernel/classes/clusterfilehandlers/ezdbfilehandler.php	(revision 25366)
+++ kernel/classes/clusterfilehandlers/ezdbfilehandler.php	(working copy)
@@ -985,6 +985,8 @@
         eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileDeleteLocal( '$path' )" );
 
         @unlink( $path );
+
+        eZClusterFileHandler::cleanupEmptyDirectories( $path );
     }
 
     /**
@@ -997,6 +999,8 @@
         $path = $this->filePath;
         eZDebugSetting::writeDebug( 'kernel-clustering', "db::deleteLocal( '$path' )" );
         @unlink( $path );
+
+        eZClusterFileHandler::cleanupEmptyDirectories( $path );
     }
 
     /*!
@@ -1027,6 +1031,8 @@
         {
             eZDir::recursiveDelete( $file );
         }
+
+        eZClusterFileHandler::cleanupEmptyDirectories( $file );
     }
 
     /**
Index: kernel/classes/clusterfilehandlers/ezfsfilehandler.php
===================================================================
--- kernel/classes/clusterfilehandlers/ezfsfilehandler.php	(revision 25366)
+++ kernel/classes/clusterfilehandlers/ezfsfilehandler.php	(working copy)
@@ -789,6 +789,8 @@
             eZDir::recursiveDelete( $path );
         }
 
+        eZClusterFileHandler::cleanupEmptyDirectories( $path );
+
         eZDebug::accumulatorStop( 'dbfile' );
     }
 
@@ -853,7 +855,11 @@
                 $mtime = @filemtime( $file );
                 if ( $expiry === false ||
                      $mtime < $expiry ) // remove it if it is too old
+                {
                     @unlink( $file );
+
+                    eZClusterFileHandler::cleanupEmptyDirectories( $file );
+                }
                 ++$count;
             }
             else if ( is_dir( $file ) )
Index: kernel/classes/ezclusterfilehandler.php
===================================================================
--- kernel/classes/ezclusterfilehandler.php	(revision 25366)
+++ kernel/classes/ezclusterfilehandler.php	(working copy)
@@ -108,6 +108,26 @@
 
         return $GLOBALS['eZClusterFileHandler_search_path_array'];
     }
+
+    /**
+     * Goes trough the directory path and removes empty directories, starting at
+     * the leaf and deleting down until a non empty directory is reached.
+     * If the path is not a directory, nothing will happen.
+     *
+     * @param string $path
+     */
+    public static function cleanupEmptyDirectories( $path )
+    {
+        $dirpath = eZDir::dirpath( $path );
+
+        eZDebugSetting::writeDebug( 'kernel-clustering', "eZClusterFileHandler::cleanupEmptyDirectories( '{$dirpath}' )" );
+
+        if ( is_dir( $dirpath ) )
+        {
+            eZDir::cleanupEmptyDirectories( $dirpath );
+        }
+    }
+
 }
 
-?>
\ No newline at end of file
+?>
Index: kernel/private/classes/clusterfilehandlers/ezdfsfilehandler.php
===================================================================
--- kernel/private/classes/clusterfilehandlers/ezdfsfilehandler.php	(revision 25366)
+++ kernel/private/classes/clusterfilehandlers/ezdfsfilehandler.php	(working copy)
@@ -1039,6 +1039,8 @@
     {
         eZDebugSetting::writeDebug( 'kernel-clustering', "dfs::fileDeleteLocal( '$path' )" );
         @unlink( eZDBFileHandler::cleanPath( $path ) );
+
+        eZClusterFileHandler::cleanupEmptyDirectories( $path );
     }
 
     /**
@@ -1049,6 +1051,8 @@
         $path = $this->filePath;
         eZDebugSetting::writeDebug( 'kernel-clustering', "dfs::deleteLocal( '$path' )" );
         @unlink( $path );
+
+        eZClusterFileHandler::cleanupEmptyDirectories( $path );
     }
 
     /**
@@ -1118,6 +1122,8 @@
         {
             eZDir::recursiveDelete( $file );
         }
+
+        eZClusterFileHandler::cleanupEmptyDirectories( $file );
     }
 
     /**
Index: kernel/private/classes/clusterfilehandlers/dfsbackends/dfs.php
===================================================================
--- kernel/private/classes/clusterfilehandlers/dfsbackends/dfs.php	(revision 25366)
+++ kernel/private/classes/clusterfilehandlers/dfsbackends/dfs.php	(working copy)
@@ -141,13 +141,21 @@
             $ret = true;
             foreach( $filePath as $file )
             {
-                $locRet = @unlink( $this->makeDFSPath( $file ) );
+                $dfsPath = $this->makeDFSPath( $file );
+                $locRet = @unlink( $dfsPath );
                 $ret = $ret and $locRet;
+
+                if ( $locRet )
+                    eZClusterFileHandler::cleanupEmptyDirectories( $dfsPath );
             }
         }
         else
         {
-            $ret = @unlink( $this->makeDFSPath( $filePath ) );
+            $dfsPath = $this->makeDFSPath( $filePath );
+            $ret = @unlink( $dfsPath );
+
+            if ( $ret )
+                eZClusterFileHandler::cleanupEmptyDirectories( $dfsPath );
         }
 
         $this->accumulatorStop();
@@ -241,6 +249,9 @@
 
         $ret = rename( $oldPath, $newPath );
 
+        if ( $ret )
+            eZClusterFileHandler::cleanupEmptyDirectories( $oldPath );
+
         $this->accumulatorStop();
 
         return $ret;
Index: kernel/private/classes/clusterfilehandlers/dfsbackends/mysql.php
===================================================================
--- kernel/private/classes/clusterfilehandlers/dfsbackends/mysql.php	(revision 25366)
+++ kernel/private/classes/clusterfilehandlers/dfsbackends/mysql.php	(working copy)
@@ -220,7 +220,7 @@
         {
             return $this->_fail( "Purging file metadata for $filePath failed" );
         }
-        if ( mysql_affected_rows() == 1 )
+        if ( mysql_affected_rows( $this->db ) == 1 )
         {
             $this->dfsbackend->delete( $filePath );
         }
Index: kernel/private/classes/clusterfilehandlers/ezfs2filehandler.php
===================================================================
--- kernel/private/classes/clusterfilehandlers/ezfs2filehandler.php	(revision 25366)
+++ kernel/private/classes/clusterfilehandlers/ezfs2filehandler.php	(working copy)
@@ -647,6 +647,8 @@
     {
         $path = $this->filePath;
         eZDebugSetting::writeDebug( 'kernel-clustering', "fs::deleteLocal( '$path' )", __METHOD__ );
+
+        eZClusterFileHandler::cleanupEmptyDirectories( $path );
     }
 
     /**
@@ -675,7 +677,11 @@
                 $mtime = @filemtime( $file );
                 if ( $expiry === false ||
                     $mtime < $expiry ) // remove it if it is too old
+                {
                     @unlink( $file );
+
+                    eZClusterFileHandler::cleanupEmptyDirectories( $file );
+                }
                 ++$count;
             }
             else if ( is_dir( $file ) )
Index: lib/ezfile/classes/ezdir.php
===================================================================
--- lib/ezfile/classes/ezdir.php	(revision 25366)
+++ lib/ezfile/classes/ezdir.php	(working copy)
@@ -117,14 +117,14 @@
     */
     static function cleanupEmptyDirectories( $dir )
     {
-        $dir = eZDir::cleanPath( $dir, self::SEPARATOR_UNIX );
+        $dir = self::cleanPath( $dir, self::SEPARATOR_UNIX );
         $dirElements = explode( '/', $dir );
         if ( count( $dirElements ) == 0 )
             return true;
         $currentDir = $dirElements[0];
         $result = true;
         if ( !file_exists( $currentDir ) and $currentDir != "" )
-            $result = eZDir::doMkdir( $currentDir, $perm );
+            $result = self::doMkdir( $currentDir, self::directoryPermission() );
         if ( !$result )
             return false;
 
