Index: bin/php/clusterize.php
===================================================================
--- bin/php/clusterize.php	(revision 21470)
+++ bin/php/clusterize.php	(working copy)
@@ -92,6 +92,35 @@
     $cli->output();
 }
 
+function copyPackageFilesToDB( $remove )
+{
+    global $cli, $dbFileHandler;
+
+    $repositoryPath = eZPackage::repositoryPath();
+    $includeHidden = true;
+    $items = eZDir::findSubitems( $repositoryPath, 'd', false, $includeHidden );
+    while ( count( $items ) > 0 )
+    {
+        $currentItems = $items;
+        $items = array();
+        foreach ( $currentItems as $item )
+        {
+            $fullPath = $sourceDir . '/' . $item;
+            if ( is_file( $fullPath ) )
+            {
+                $cli->output( "- " . $fullPath );
+                $dbFileHandler->fileStore( $fullPath, 'package', $remove );
+            }
+            else if ( is_dir( $fullPath ) )
+            {
+                $newItems = eZDir::findSubitems( $fullPath, 'df', $item, $includeHidden );
+                $items = array_merge( $items, $newItems );
+                unset( $newItems );
+            }
+        }
+    }
+}
+
 function copyImagesToDB( $remove )
 {
     global $cli, $dbFileHandler;
@@ -150,17 +179,19 @@
                                        'skip-binary-files' => 'Skip copying binary files',
                                        'skip-media-files'  => 'Skip copying media files',
                                        'skip-images'       => 'Skip copying images',
+                                       'skip-packages'     => 'Skip copying packages',
                                        'r'                 => 'Remove files after copying',
                                        'n'                 => 'Do not wait' ) );
 
 $script->initialize();
 
-$clusterize = !isset( $options['u'] );
-$remove     =  isset( $options['r'] );
-$copyFiles  = !isset( $options['skip-binary-files'] );
-$copyMedia  = !isset( $options['skip-media-files'] );
-$copyImages = !isset( $options['skip-images'] );
-$wait       = !isset( $options['n'] );
+$clusterize   = !isset( $options['u'] );
+$remove       =  isset( $options['r'] );
+$copyFiles    = !isset( $options['skip-binary-files'] );
+$copyMedia    = !isset( $options['skip-media-files'] );
+$copyImages   = !isset( $options['skip-images'] );
+$copyPackages = !isset( $options['skip-packages'] );
+$wait         = !isset( $options['n'] );
 
 if ( $wait )
 {
@@ -188,6 +219,8 @@
         copyImagesToDB( $remove );
     if ( $copyMedia )
         copyMediafilesToDB( $remove );
+    if ( $copyPackages )
+        copyPackageFilesToDB( $remove );
 }
 else
 {
Index: kernel/classes/clusterfilehandlers/dbbackends/mysql.php
===================================================================
--- kernel/classes/clusterfilehandlers/dbbackends/mysql.php	(revision 21470)
+++ kernel/classes/clusterfilehandlers/dbbackends/mysql.php	(working copy)
@@ -111,7 +111,7 @@
             return $this->_die( "Unable to select database {$params['dbname']}" );
     }
 
-    function _copy( $srcFilePath, $dstFilePath, $fname = false )
+    function _copy( $srcFilePath, $dstFilePath, $fname = false, $scope = false )
     {
         if ( $fname )
             $fname .= "::_copy($srcFilePath, $dstFilePath)";
@@ -122,6 +122,10 @@
         $metaData = $this->_fetchMetadata( $srcFilePath, $fname );
         if ( !$metaData ) // if source file does not exist then do nothing.
             return false;
+        if ( $scope )
+        {
+            $metaData['scope'] = $scope;
+        }
         return $this->_protect( array( $this, "_copyInner" ), $fname,
                                 $srcFilePath, $dstFilePath, $fname, $metaData );
     }
@@ -776,6 +780,47 @@
         return true;
     }
 
+    function _getFileListByPath( $path )
+    {
+        $quotedPath = $this->_quote( $path . '/%' );
+        $query = "SELECT name FROM " . TABLE_METADATA . " WHERE name LIKE $quotedPath";
+
+        $rslt = $this->_query( $query, "_getFileListByPath($path)" );
+        if ( !$rslt )
+        {
+            $this->_error( $query, "_getFileListByPath($path)", mysql_error( $this->db ) );
+            return false;
+        }
+
+        $filePathList = array();
+        while ( $row = mysql_fetch_row( $rslt ) )
+            $filePathList[] = $row[0];
+
+        return $filePathList;
+    }
+
+    function _getSubDirectoryList( $path )
+    {
+        $elementCount = count( explode( '/', $path ) ) + 1;
+        $quotedPath = $this->_quote( $path . '/%/%' );
+        $query = "SELECT DISTINCT( SUBSTRING_INDEX( name, '/', $elementCount ) ) FROM " . TABLE_METADATA . " WHERE name LIKE $quotedPath";
+
+        $rslt = $this->_query( $query, "_getSubDirectoryList($path)" );
+        if ( !$rslt )
+        {
+            $this->_error( $query, "_getSubDirectoryList($path)", mysql_error( $this->db ) );
+            return false;
+        }
+
+        $pathList = array();
+        while ( $row = mysql_fetch_row( $rslt ) )
+        {
+            $pathList[] = substr( $row[0], strlen( $path . '/' ) );
+        }
+
+        return $pathList;
+    }
+
     function _getFileList( $skipBinaryFiles, $skipImages )
     {
         $query = 'SELECT name FROM ' . TABLE_METADATA;
@@ -792,6 +837,33 @@
         $rslt = $this->_query( $query, "_getFileList($skipBinaryFiles, $skipImages)" );
         if ( !$rslt )
         {
+            $this->_error( $query, "_getFileList($path)", mysql_error( $this->db ) );
+            return false;
+        }
+
+        $filePathList = array();
+        while ( $row = mysql_fetch_row( $rslt ) )
+            $filePathList[] = $row[0];
+
+        return $filePathList;
+    }
+
+    function _getDirContents( $skipBinaryFiles, $skipImages )
+    {
+        $query = 'SELECT name FROM ' . TABLE_METADATA;
+
+        // omit some file types if needed
+        $filters = array();
+        if ( $skipBinaryFiles )
+            $filters[] = "'binaryfile'";
+        if ( $skipImages )
+            $filters[] = "'image'";
+        if ( $filters )
+            $query .= ' WHERE scope NOT IN (' . join( ', ', $filters ) . ')';
+
+        $rslt = $this->_query( $query, "_getFileList($skipBinaryFiles, $skipImages)" );
+        if ( !$rslt )
+        {
             $this->_error( mysql_error( $this->db ) );
             return false;
         }
Index: kernel/classes/clusterfilehandlers/ezdbfilehandler.php
===================================================================
--- kernel/classes/clusterfilehandlers/ezdbfilehandler.php	(revision 21470)
+++ kernel/classes/clusterfilehandlers/ezdbfilehandler.php	(working copy)
@@ -833,7 +833,14 @@
         $path = eZDBFileHandler::cleanPath( $path );
         eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileDeleteLocal( '$path' )" );
 
-        @unlink( $path );
+        if ( is_file( $path ) )
+        {
+            @unlink( $path );
+        }
+        else if ( is_dir( $path ) )
+        {
+            eZDir::recursiveDelete( $path );
+        }
     }
 
     /**
@@ -945,13 +952,13 @@
      * \public
      * \static
      */
-    function fileCopy( $srcPath, $dstPath )
+    function fileCopy( $srcPath, $dstPath, $scope = false )
     {
         $srcPath = eZDBFileHandler::cleanPath( $srcPath );
         $dstPath = eZDBFileHandler::cleanPath( $dstPath );
         eZDebugSetting::writeDebug( 'kernel-clustering', "db::fileCopy( '$srcPath', '$dstPath' )" );
 
-        $this->backend->_copy( $srcPath, $dstPath );
+        $this->backend->_copy( $srcPath, $dstPath, false, $scope );
     }
 
     /**
@@ -1004,6 +1011,33 @@
     }
 
     /**
+     * Get a list of files under a specific path
+     *
+     * \public
+     */
+    function getFileListByPath( $path )
+    {
+         $path = eZDBFileHandler::cleanPath( $path );
+         eZDebugSetting::writeDebug( 'kernel-clustering', "db::getFileListByPath( '$path' )" );
+        return $this->backend->_getFileListByPath( $path );
+    }
+
+    /**
+     * Get a list of directories directly under a specific path
+     *
+     * Because the database cluster implementation only stores files and no directory information,
+     * we need to rely on the files to reverse engineer the directories
+     *
+     * \public
+     */
+    function getSubDirectoryList( $path )
+    {
+        $path = eZDBFileHandler::cleanPath( $path );
+        eZDebugSetting::writeDebug( 'kernel-clustering', "db::getSubDirectoryList( '$path' )" );
+        return $this->backend->_getSubDirectoryList( $path );
+    }
+
+    /**
      * Get list of files stored in database.
      *
      * Used in bin/php/clusterize.php.
Index: kernel/classes/clusterfilehandlers/ezfsfilehandler.php
===================================================================
--- kernel/classes/clusterfilehandlers/ezfsfilehandler.php	(revision 21470)
+++ kernel/classes/clusterfilehandlers/ezfsfilehandler.php	(working copy)
@@ -895,12 +895,16 @@
      * \public
      * \static
      */
-    function fileCopy( $srcPath, $dstPath )
+    function fileCopy( $srcPath, $dstPath, $scope = false )
     {
         eZDebugSetting::writeDebug( 'kernel-clustering', "fs::fileCopy( '$srcPath', '$dstPath' )" );
 
         eZDebug::accumulatorStart( 'dbfile', false, 'dbfile' );
         require_once( 'lib/ezfile/classes/ezfilehandler.php' );
+        if ( !file_exists( dirname( $dstPath ) ) )
+        {
+            eZDir::mkdir( $dstPath, false, true );
+        }
         eZFileHandler::copy( $srcPath, $dstPath );
         eZDebug::accumulatorStop( 'dbfile', false, 'dbfile' );
     }
@@ -954,6 +958,26 @@
         eZDebug::accumulatorStop( 'dbfile' );
     }
 
+    /**
+     * Get a list of files under a specific path
+     *
+     * \public
+     */
+    function getFileListByPath( $path )
+    {
+        return eZDir::recursiveFind( $path, '.*' );
+    }
+
+    /**
+     * Get a list of directories directly under a specific path
+     *
+     * \public
+     */
+    function getSubDirectoryList( $path )
+    {
+        return eZDir::findSubdirs( $path );
+    }
+
     public $metaData = null;
 }
 
Index: kernel/classes/datatypes/ezbinaryfile/ezbinaryfiletype.php
===================================================================
--- kernel/classes/datatypes/ezbinaryfile/ezbinaryfiletype.php	(revision 21470)
+++ kernel/classes/datatypes/ezbinaryfile/ezbinaryfiletype.php	(working copy)
@@ -692,7 +692,9 @@
 
         $sourcePath = $package->simpleFilePath( $fileNode->getAttribute( 'filekey' ) );
 
-        if ( !file_exists( $sourcePath ) )
+       $fileHandler = eZClusterFileHandler::instance();
+
+        if ( !$fileHandler->fileExists( $sourcePath ) )
         {
             eZDebug::writeError( "The file '$sourcePath' does not exist, cannot initialize file attribute with it",
                                  'eZBinaryFileType::unserializeContentObjectAttribute' );
@@ -704,25 +706,15 @@
         $mimeType = $fileNode->getAttribute( 'mime-type' );
         list( $mimeTypeCategory, $mimeTypeName ) = explode( '/', $mimeType );
         $destinationPath = eZSys::storageDirectory() . '/original/' . $mimeTypeCategory . '/';
-        if ( !file_exists( $destinationPath ) )
-        {
-            $oldumask = umask( 0 );
-            if ( !eZDir::mkdir( $destinationPath, eZDir::directoryPermission(), true ) )
-            {
-                umask( $oldumask );
-                return false;
-            }
-            umask( $oldumask );
-        }
 
         $basename = basename( $fileNode->getAttribute( 'filename' ) );
-        while ( file_exists( $destinationPath . $basename ) )
+        while ( $fileHandler->fileExists( $destinationPath . $basename ) )
         {
             $basename = substr( md5( mt_rand() ), 0, 8 ) . '.' . eZFile::suffix( $fileNode->getAttribute( 'filename' ) );
         }
 
-        //include_once( 'lib/ezfile/classes/ezfilehandler.php' );
-        eZFileHandler::copy( $sourcePath, $destinationPath . $basename );
+        $fileHandler->fileCopy( $sourcePath, $destinationPath . $basename, 'binaryfile' );
+
         eZDebug::writeNotice( 'Copied: ' . $sourcePath . ' to: ' . $destinationPath . $basename,
                               'eZBinaryFileType::unserializeContentObjectAttribute()' );
 
@@ -732,12 +724,6 @@
         $binaryFile->setAttribute( 'mime_type', $fileNode->getAttribute( 'mime-type' ) );
 
         $binaryFile->store();
-
-        // VS-DBFILE + SP DBFile fix
-
-        require_once( 'kernel/classes/ezclusterfilehandler.php' );
-        $fileHandler = eZClusterFileHandler::instance();
-        $fileHandler->fileStore( $destinationPath . $basename, 'binaryfile', true );
     }
 
 }
Index: kernel/classes/datatypes/ezimage/ezimagetype.php
===================================================================
--- kernel/classes/datatypes/ezimage/ezimagetype.php	(revision 21470)
+++ kernel/classes/datatypes/ezimage/ezimagetype.php	(working copy)
@@ -546,7 +546,9 @@
         $imageFileKey = $attributeNode->getAttribute( 'image-file-key' );
         if ( $imageFileKey )
         {
-            $content->initializeFromFile( $package->simpleFilePath( $imageFileKey ), $alternativeText );
+            $fileHandler = eZClusterFileHandler::instance( $package->simpleFilePath( $imageFileKey ) );
+            $tempPath = $fileHandler->fetchUnique();
+            $content->initializeFromFile( $tempPath, $alternativeText );
         }
         else
         {
Index: kernel/classes/datatypes/ezmedia/ezmediatype.php
===================================================================
--- kernel/classes/datatypes/ezmedia/ezmediatype.php	(revision 21470)
+++ kernel/classes/datatypes/ezmedia/ezmediatype.php	(working copy)
@@ -766,27 +766,21 @@
 
         $sourcePath = $package->simpleFilePath( $mediaNode->getAttribute( 'filekey' ) );
 
+        $fileHandler = eZClusterFileHandler::instance();
+
         //include_once( 'lib/ezfile/classes/ezdir.php' );
         $ini = eZINI::instance();
         $mimeType = $mediaNode->getAttribute( 'mime-type' );
         list( $mimeTypeCategory, $mimeTypeName ) = explode( '/', $mimeType );
         $destinationPath = eZSys::storageDirectory() . '/original/' . $mimeTypeCategory . '/';
-        if ( !file_exists( $destinationPath ) )
-        {
-            if ( !eZDir::mkdir( $destinationPath, eZDir::directoryPermission(), true ) )
-            {
-                return false;
-            }
-        }
 
         $basename = basename( $mediaNode->getAttribute( 'filename' ) );
-        while ( file_exists( $destinationPath . $basename ) )
+        while ( $fileHandler->fileExists( $destinationPath . $basename ) )
         {
             $basename = substr( md5( mt_rand() ), 0, 8 ) . '.' . eZFile::suffix( $mediaNode->getAttribute( 'filename' ) );
         }
 
-        //include_once( 'lib/ezfile/classes/ezfilehandler.php' );
-        eZFileHandler::copy( $sourcePath, $destinationPath . $basename );
+        $fileHandler->fileCopy( $sourcePath, $destinationPath . $basename, 'mediafile' );
         eZDebug::writeNotice( 'Copied: ' . $sourcePath . ' to: ' . $destinationPath . $basename,
                               'eZMediaType::unserializeContentObjectAttribute()' );
 
@@ -804,12 +798,6 @@
         $mediaFile->setAttribute( 'quality', $mediaNode->getAttribute( 'quality' ) );
         $mediaFile->setAttribute( 'is_loop', $mediaNode->getAttribute( 'is-loop' ) );
 
-        // VS-DBFILE
-
-        require_once( 'kernel/classes/ezclusterfilehandler.php' );
-        $fileHandler = eZClusterFileHandler::instance();
-        $fileHandler->fileStore( $destinationPath . $basename, 'mediafile', true );
-
         $mediaFile->store();
     }
 }
Index: kernel/classes/ezpackage.php
===================================================================
--- kernel/classes/ezpackage.php	(revision 21470)
+++ kernel/classes/ezpackage.php	(working copy)
@@ -72,10 +72,11 @@
     function remove()
     {
         $path = $this->path();
-        if ( file_exists( $path ) )
-        {
-            eZDir::recursiveDelete( $path );
-        }
+        eZDebug::writeDebug( $path, 'path ro remove' );
+
+        $fileHandler = eZClusterFileHandler::instance( $path );
+        $fileHandler->delete();
+        $fileHandler->purge();
         $this->setInstalled( false );
     }
 
@@ -501,8 +502,8 @@
                                                   'audience' => $audience );
         if ( $create )
         {
-            eZFile::create( $name, $this->path() . '/' . eZPackage::documentDirectory(),
-                            $data );
+            $fileHandler = eZClusterFileHandler::instance();
+            $fileHandler->fileStoreContents( $this->path() . '/' . eZPackage::documentDirectory() . '/' . $name, $data, 'package' );
         }
     }
 
@@ -532,6 +533,9 @@
 
     static function md5sum( $file )
     {
+        $fileHandler = eZClusterFileHandler::instance();
+        $fileHandler->fileFetch( $file );
+
         if ( function_exists( 'md5_file' ) )
         {
             if ( file_exists( $file ) )
@@ -743,17 +747,47 @@
             $path = $this->path() . '/' . eZPackage::filesDirectory() . '/' . $collection . '/' . $typeDir;
             if ( $subDirectory )
                 $path .= '/' . $subDirectory;
-            if ( !file_exists( $path ) )
-                eZDir::mkdir( $path, eZDir::directoryPermission(), true );
 
+            $fileHandler = eZClusterFileHandler::instance();
+
             if ( is_dir( $fileItem['path'] ) )
             {
-                eZDir::copy( $fileItem['path'], $path,
-                             $fileItem['name'] != false, true, false, eZDir::temporaryFileRegexp() );
+                // code borrowed from eZDir::copy
+                $excludeItems = eZDir::temporaryFileRegexp();
+                $includeHidden = false;
+
+                if ( $fileItem['name'] )
+                {
+                    if ( preg_match( "#^.+/([^/]+)$#", $fileItem['path'], $matches ) )
+                    {
+                        $path .= '/' . $matches[1];
+                    }
+                }
+
+                $items = eZDir::findSubitems( $fileItem['path'], 'df', false, $includeHidden, $excludeItems );
+                while ( count( $items ) > 0 )
+                {
+                    $currentItems = $items;
+                    $items = array();
+                    foreach ( $currentItems as $item )
+                    {
+                        $fullPath = $fileItem['path'] . '/' . $item;
+                        if ( is_file( $fullPath ) )
+                        {
+                            $fileHandler->fileStoreContents( $path . '/' . $item, file_get_contents( $fullPath ), 'package' );
+                        }
+                        else if ( is_dir( $fullPath ) )
+                        {
+                            $newItems = eZDir::findSubitems( $fullPath, 'df', $item, $includeHidden, $excludeItems );
+                            $items = array_merge( $items, $newItems );
+                            unset( $newItems );
+                        }
+                    }
+                }
             }
             else
             {
-                eZFileHandler::copy( $fileItem['path'], $path . '/' . $fileItem['name'] );
+                $fileHandler->fileStoreContents( $path, file_get_contents( $fileItem['path'] ), 'package' );
             }
         }
     }
@@ -927,10 +961,7 @@
                     $path .= '/' . $installEntry['sub-directory'];
                 }
                 $filePath = $path . '/' . $installEntry['filename'] . '.xml';
-                if ( !file_exists( $path ) )
-                {
-                    eZDir::mkdir( $path, eZDir::directoryPermission(), true );
-                }
+
                 $partDOM = new DOMDocument( '1.0', 'utf-8' );
                 $partDOM->formatOutput = true;
                 $contentImport = $partDOM->importNode( $content, true );
@@ -1038,19 +1069,32 @@
     /*!
      Stores the current package definition file to the directory \a $path.
     */
-    function storePackageFile( $path, $storeCache = true )
+    function storePackageFile( $path, $storeCache = true, $useCluster = true )
     {
-        if ( !file_exists( $path ) )
+        $filePath = $path . '/' . eZPackage::definitionFilename();
+        $packageFileString = $this->toString();
+
+        if ( $useCluster )
         {
-            eZDir::mkdir( $path, eZDir::directoryPermission(), true );
+            $fileHandler = eZClusterFileHandler::instance();
+            $result = $fileHandler->fileStoreContents( $filePath, $packageFileString );
         }
-        $filePath = $path . '/' . eZPackage::definitionFilename();
+        else
+        {
+            if ( !file_exists( $path ) )
+            {
+                eZDir::mkdir( $path, eZDir::directoryPermission(), true );
+            }
 
-        $packageFileString = $this->toString();
-        $result = $this->storeString( $filePath, $packageFileString );
+            $packageFileString = $this->toString();
+            $result = $this->storeString( $filePath, $packageFileString );
+        }
 
         if ( $storeCache )
+        {
             $this->storeCache( $path . '/' . $this->cacheDirectory() );
+        }
+
         return $result;
     }
 
@@ -1071,10 +1115,12 @@
     function exportToArchive( $archivePath )
     {
         $tempPath = eZPackage::temporaryExportPath() . '/' . $this->attribute( 'name' );
+        eZDebug::writeDebug( $tempPath, 'temp path' );
         $this->removeFiles( $tempPath );
 
         // Create package temp dir and copy package's XML file there
-        $this->storePackageFile( $tempPath, false );
+        $useCluster = false;
+        $this->storePackageFile( $tempPath, false, $useCluster );
 
         // Copy package's directories
         $directoryList = array( $this->documentDirectory(),
@@ -1089,12 +1135,30 @@
         }
 
         $path = $this->path();
-        foreach( $directoryList as $dirName )
+
+        $fileHandler = eZClusterFileHandler::instance();
+
+        // need to recursively copy directories here from cluster to temporary location on the file system
+        foreach ( $directoryList as $dirName )
         {
-            $destDir = $tempPath;
             $dir = $path . '/' . $dirName;
-            if ( file_exists( $dir ) )
-                eZDir::copy( $dir, $destDir );
+            $dirFileList = $fileHandler->getFileListByPath( $dir );
+            eZDebug::writeDebug( $dirFileList, "file list for path $dir" );
+            foreach ( $dirFileList as $file )
+            {
+                $specificFileHandler = eZClusterFileHandler::instance( $file );
+                $tempFilePath = $specificFileHandler->fetchUnique();
+
+                $newFilePath = $tempPath . '/' . $dirName . substr( $file, strlen( $dir ) );
+                $newFileDir = dirname( $newFilePath );
+
+                if ( !is_dir( $newFileDir ) )
+                {
+                    eZDir::mkdir( $newFileDir, false, true );
+                }
+
+                eZFileHandler::copy( $tempFilePath, $newFilePath );
+            }
         }
 
         //include_once( 'lib/ezfile/classes/ezarchivehandler.php' );
@@ -1103,10 +1167,11 @@
 
         $packageBaseDirectory = $tempPath;
         $fileList = array();
-        $fileList[] = $packageBaseDirectory;
+        $fileList[] = $tempPath;
 
-        $archive->createModify( $fileList, '', $packageBaseDirectory );
+        $archive->createModify( $fileList, '', $tempPath );
 
+        // put next line into comments for easier debugging
         $this->removeFiles( $tempPath );
         return $archivePath;
     }
@@ -1142,8 +1207,11 @@
                 $retValue = false;
                 return $retValue;
             }
+            eZDebug::writeDebug( $tempDirPath, 'temp dir path' );
 
-            $package = eZPackage::fetch( $packageName, $tempDirPath, false, $dbAvailable );
+            // the package is still at a temporary location, we should not use the cluster yet to load it
+            $useCluster = false;
+            $package = eZPackage::fetch( $packageName, $tempDirPath, false, $dbAvailable, $useCluster );
             eZPackage::removeFiles( $archivePath );
 
             if ( $package )
@@ -1164,13 +1232,41 @@
 
                 $fullRepositoryPath = eZPackage::repositoryPath() . '/' . $repositoryID;
                 $packagePath = $fullRepositoryPath . '/' . $packageName;
-                if ( !file_exists( $packagePath ) )
-                {
-                    eZDir::mkdir( $packagePath, eZDir::directoryPermission(), true );
-                }
+
                 $archive = eZArchiveHandler::instance( 'tar', 'gzip', $archiveName );
                 $archive->extractModify( $packagePath, '' );
 
+                // store package files from $packagePath into the cluster
+                $fileHandler = eZClusterFileHandler::instance();
+
+                // we will delete files locally after we stored them into the cluster
+                $delete = true;
+
+                // code borrowed from eZDir::copy
+                $items = eZDir::findSubitems( $packagePath, 'df' );
+                while ( count( $items ) > 0 )
+                {
+                    $currentItems = $items;
+                    $items = array();
+                    foreach ( $currentItems as $item )
+                    {
+                        $fullPath = $packagePath . '/' . $item;
+                        if ( is_file( $fullPath ) )
+                        {
+                            $fileHandler->fileStore( $fullPath, 'package', $delete );
+                        }
+                        else if ( is_dir( $fullPath ) )
+                        {
+                            $newItems = eZDir::findSubitems( $fullPath, 'df', $item );
+
+                            $items = array_merge( $items, $newItems );
+                            unset( $newItems );
+                        }
+                    }
+                }
+                eZDebug::writeDebug( 'deleting locally: ' . $packagePath );
+                $fileHandler->fileDeleteLocal( $packagePath );
+
                 $package = eZPackage::fetch( $packageName, $fullRepositoryPath, false, $dbAvailable );
                 if ( !$package )
                 {
@@ -1227,23 +1323,11 @@
     */
     static function storeDOM( $filename, $dom )
     {
-        $bytes = $dom->save( $filename );
+        $contents = $dom->saveXML();
+        $fileHandler = eZClusterFileHandler::instance();
+        $fileHandler->fileStoreContents( $filename, $contents, 'package' );
 
-        if ( $bytes !== false )
-        {
-            eZPackage::applyStorageFilePermissions( $filename );
-
-            eZDebugSetting::writeNotice( 'kernel-ezpackage-store',
-                                         "Stored file $filename",
-                                         'eZPackage::storeDOM' );
-            return true;
-        }
-        else
-        {
-            eZDebug::writeError( "Saving DOM tree to $filename failed", 'eZPackage::storeDOM' );
-        }
-
-        return false;
+        return true;
     }
 
     /*!
@@ -1280,8 +1364,14 @@
      Loads the contents of the file \a $filename and parses it into a DOM tree.
      The DOM tree is returned.
     */
-    static function fetchDOMFromFile( $filename )
+    static function fetchDOMFromFile( $filename, $useCluster = true )
     {
+        if ( $useCluster )
+        {
+            $fileHandler = eZClusterFileHandler::instance( $filename );
+            $fileHandler->fetch( true );
+        }
+
         if ( file_exists( $filename ) )
         {
             $dom = new DOMDocument( '1.0', 'utf-8' );
@@ -1297,9 +1387,9 @@
      and create a package object from it.
      \return \c false if it could be fetched.
     */
-    static function fetchFromFile( $filename )
+    static function fetchFromFile( $filename, $useCluster = true )
     {
-        $dom = eZPackage::fetchDOMFromFile( $filename );
+        $dom = eZPackage::fetchDOMFromFile( $filename, $useCluster );
 
         if ( $dom === false )
         {
@@ -1327,7 +1417,7 @@
                           (false in setup wizard)
      \return \c false if no package could be found.
     */
-    static function fetch( $packageName, $packagePath = false, $repositoryID = false, $dbAvailable = true )
+    static function fetch( $packageName, $packagePath = false, $repositoryID = false, $dbAvailable = true, $useCluster = true )
     {
         $packageRepositories = eZPackage::packageRepositories( array( 'path' => $packagePath ) );
 
@@ -1344,9 +1434,11 @@
             $path .= '/' . $packageName;
             $filePath = $path . '/' . eZPackage::definitionFilename();
 
-            if ( file_exists( $filePath ) )
+            $fileHandler = eZClusterFileHandler::instance( $filePath );
+
+            if ( ( !$useCluster && file_exists( $filePath ) ) || $fileHandler->exists() )
             {
-                $fileModification = filemtime( $filePath );
+                $fileModification = $useCluster ? $fileHandler->mtime() : filemtime( $filePath );
                 $package = false;
                 $cacheExpired = false;
 
@@ -1361,7 +1453,7 @@
                 }
                 else
                 {
-                    $package = eZPackage::fetchFromFile( $filePath );
+                    $package = eZPackage::fetchFromFile( $filePath, $useCluster );
 
                     if ( $package )
                     {
@@ -1593,7 +1685,9 @@
                                                  'name' => ezi18n( 'kernel/package', 'Local' ),
                                                  'type' => 'local' ) );
 
-            $subdirs = eZDir::findSubitems( $repositoryPath, 'd' );
+            $fileHandler = eZClusterFileHandler::instance();
+            $subdirs = $fileHandler->getSubDirectoryList( $repositoryPath );
+
             foreach( $subdirs as $dir )
             {
                 if ( $dir == 'local' )
@@ -1674,91 +1768,84 @@
         if ( isset( $parameters['db_available'] ) )
             $dbAvailable = $parameters['db_available'];
 
+        $fileHandler = eZClusterFileHandler::instance();
+
         foreach ( $packageRepositories as $packageRepository )
         {
             if ( strlen( $repositoryID ) == 0 or
                  $repositoryID == $packageRepository['id'] )
             {
                 $path = $packageRepository['path'];
-                if ( file_exists( $path ) )
+
+                $fileList = $fileHandler->getSubDirectoryList( $path );
+
+                sort( $fileList );
+                foreach ( $fileList as $file )
                 {
-                    $fileList = array();
-                    $dir = opendir( $path );
-                    while( ( $file = readdir( $dir ) ) !== false )
+                    $dirPath = $path . '/' . $file;
+
+                    $filePath = $dirPath . '/' . eZPackage::definitionFilename();
+
+                    $specificFileHandler = eZClusterFileHandler::instance( $filePath );
+                    if ( $specificFileHandler->exists() )
                     {
-                        if ( $file == '.' or
-                             $file == '..' )
-                            continue;
-                        $fileList[] = $file;
-                    }
-                    closedir( $dir );
-                    sort( $fileList );
-                    foreach ( $fileList as $file )
-                    {
-                        $dirPath = $path . '/' . $file;
-                        if ( !is_dir( $dirPath ) )
-                            continue;
-                        $filePath = $dirPath . '/' . eZPackage::definitionFilename();
-                        if ( file_exists( $filePath ) )
+                        $fileModification = $specificFileHandler->mtime();
+                        $name = $file;
+                        $packageCachePath = $dirPath . '/' . eZPackage::cacheDirectory() . '/package.php';
+                        unset( $package );
+                        $package = false;
+                        $cacheExpired = false;
+                        if ( eZPackage::useCache() )
                         {
-                            $fileModification = filemtime( $filePath );
-                            $name = $file;
-                            $packageCachePath = $dirPath . '/' . eZPackage::cacheDirectory() . '/package.php';
-                            unset( $package );
-                            $package = false;
-                            $cacheExpired = false;
-                            if ( eZPackage::useCache() )
+                            $package = eZPackage::fetchFromCache( $dirPath, $fileModification, $cacheExpired );
+                        }
+                        if ( !$package )
+                        {
+                            $package = eZPackage::fetchFromFile( $filePath );
+                            if ( $package and
+                                 $cacheExpired and
+                                 eZPackage::useCache() )
                             {
-                                $package = eZPackage::fetchFromCache( $dirPath, $fileModification, $cacheExpired );
+                                $package->storeCache( $dirPath . '/' . eZPackage::cacheDirectory() );
                             }
-                            if ( !$package )
-                            {
-                                $package = eZPackage::fetchFromFile( $filePath );
-                                if ( $package and
-                                     $cacheExpired and
-                                     eZPackage::useCache() )
-                                {
-                                    $package->storeCache( $dirPath . '/' . eZPackage::cacheDirectory() );
-                                }
-                            }
-                            if ( !$package )
-                                continue;
+                        }
+                        if ( !$package )
+                            continue;
 
-                            if ( $dbAvailable )
-                                $package->getInstallState();
+                        if ( $dbAvailable )
+                            $package->getInstallState();
 
-                            if ( $requiredType !== null )
-                            {
-                                $type = $package->attribute( 'type' );
-                                if ( $type != $requiredType )
-                                    continue;
-                            }
+                        if ( $requiredType !== null )
+                        {
+                            $type = $package->attribute( 'type' );
+                            if ( $type != $requiredType )
+                                continue;
+                        }
 
-                            if ( $requiredPriority !== null )
-                            {
-                                $type = $package->attribute( 'priority' );
-                                if ( $priority != $requiredPriority )
-                                    continue;
-                            }
+                        if ( $requiredPriority !== null )
+                        {
+                            $type = $package->attribute( 'priority' );
+                            if ( $priority != $requiredPriority )
+                                continue;
+                        }
 
-                            if ( $requiredExtension !== null )
-                            {
-                                $type = $package->attribute( 'extension' );
-                                if ( $extension != $requiredExtension )
-                                    continue;
-                            }
+                        if ( $requiredExtension !== null )
+                        {
+                            $type = $package->attribute( 'extension' );
+                            if ( $extension != $requiredExtension )
+                                continue;
+                        }
 
-                            if ( $requiredVendor !== null )
-                            {
-                                $type = $package->attribute( 'vendor' );
-                                if ( $vendor != $requiredVendor )
-                                    continue;
-                            }
+                        if ( $requiredVendor !== null )
+                        {
+                            $type = $package->attribute( 'vendor' );
+                            if ( $vendor != $requiredVendor )
+                                continue;
+                        }
 
-                            $package->setCurrentRepositoryInformation( $packageRepository );
+                        $package->setCurrentRepositoryInformation( $packageRepository );
 
-                            $packages[] =& $package;
-                        }
+                        $packages[] =& $package;
                     }
                 }
             }
@@ -2795,17 +2882,26 @@
 
         $suffix = eZFile::suffix( $filepath );
         //$sourcePath = $fileInfo['original-path'];
-        $packagePath = eZPackage::simpleFilesDirectory() . '/' . substr( md5( mt_rand() ), 0, 8 ) . '.' . $suffix;
+        $fileName = substr( md5( mt_rand() ), 0, 8 ) . '.' . $suffix;
+        $simpleFilesPath = $this->path() . '/' . eZPackage::simpleFilesDirectory();
+        $packagePath = eZPackage::simpleFilesDirectory() . '/' . $fileName;
         $destinationPath = $this->path() . '/' . $packagePath;
-        eZDir::mkdir( eZDir::dirpath( $destinationPath ), false, true );
 
-       //SP DBfile
+        //SP DBfile
         require_once( 'kernel/classes/ezclusterfilehandler.php' );
         $fileHandler = eZClusterFileHandler::instance();
         $fileHandler->fileFetch( $filepath );
 
+        if ( !is_dir( $simpleFilesPath ) )
+        {
+            eZDir::mkdir( $simpleFilesPath, false, true );
+        }
+
         eZFileHandler::copy( $filepath, $destinationPath );
 
+        $delete = true;
+        $fileHandler->fileStore( $destinationPath, 'package', $delete );
+
         $this->Parameters['simple-file-list'][$key] = array( 'original-path' => $filepath,
                                                              'package-path' => $packagePath );
     }
Index: kernel/classes/packagehandlers/ezcontentobject/ezcontentobjectpackagehandler.php
===================================================================
--- kernel/classes/packagehandlers/ezcontentobject/ezcontentobjectpackagehandler.php	(revision 21470)
+++ kernel/classes/packagehandlers/ezcontentobject/ezcontentobjectpackagehandler.php	(working copy)
@@ -357,8 +357,6 @@
         }
 
         $path = $this->Package->path() . '/' . $this->contentObjectDirectory();
-        if ( !file_exists( $path ) )
-                eZDir::mkdir( $path, eZDir::directoryPermission(), true );
 
         $dom = new DOMDocument( '1.0', 'utf-8' );
 
Index: kernel/classes/packagehandlers/ezdb/ezdbpackagehandler.php
===================================================================
--- kernel/classes/packagehandlers/ezdb/ezdbpackagehandler.php	(revision 21470)
+++ kernel/classes/packagehandlers/ezdb/ezdbpackagehandler.php	(working copy)
@@ -69,30 +69,29 @@
             $path .= '/' . $databaseType;
         }
 
-        if ( file_exists( $path ) )
+        $fullPath = "$path/$filename";
+
+        $fileHandler = eZClusterFileHandler::instance( $fullPath );
+        if ( $fileHandler->exists() )
         {
             $db = eZDB::instance();
-            $canInsert = true;
+
             if ( $databaseType and
                  $databaseType != $db->databaseName() )
             {
-                $canInsert = false;
+                eZDebug::writeDebug( "Skipping SQL file " );
             }
-
-            if ( $canInsert )
+            else
             {
-                eZDebug::writeDebug( "Installing SQL file $path/$filename" );
-                $db->insertFile( $path, $filename, false );
+                eZDebug::writeDebug( "Installing SQL file $fullPath" );
+                $fileHandler->fetch( true );
+                $db->insertFile( dirname( $tempPath ), basename( $tempPath ), false );
                 return true;
             }
-            else
-            {
-                eZDebug::writeDebug( "Skipping SQL file $path/$filename" );
-            }
         }
         else
         {
-            eZDebug::writeError( "Could not find SQL file $path/$filename" );
+            eZDebug::writeError( "Could not find SQL file $fullPath" );
         }
         return false;
     }
@@ -232,9 +231,14 @@
         $installDirectory = $package->path() . '/' . eZDBPackageHandler::sqlDirectory();
         if ( $installItem['database-type'] )
             $installDirectory .= '/' . $installItem['database-type'];
+
+        $fileHandler = eZClusterFileHandler::instance();
         if ( !file_exists(  $installDirectory ) )
             eZDir::mkdir( $installDirectory, eZDir::directoryPermission(), true );
-        eZFileHandler::copy( $originalPath, $installDirectory . '/' . $installItem['filename'] );
+        $newPath = $installDirectory . '/' . $installItem['filename'];
+        eZFileHandler::copy( $originalPath, $newPath );
+        $delete = true;
+        $fileHandler->fileStore( $newPath, 'package', $delete );
     }
 
     /*!
Index: kernel/classes/packagehandlers/ezextension/ezextensionpackagehandler.php
===================================================================
--- kernel/classes/packagehandlers/ezextension/ezextensionpackagehandler.php	(revision 21470)
+++ kernel/classes/packagehandlers/ezextension/ezextensionpackagehandler.php	(working copy)
@@ -182,6 +182,8 @@
             else
             {
                 $sourcePath = $packageExtensionDir . $path . '/' . $file->getAttribute( 'name' );
+                $fileHandler = eZClusterFileHandler::instance( $sourcePath );
+                $fileHandler->fetch( true );
                 eZFileHandler::copy( $sourcePath, $destPath );
             }
         }
@@ -231,13 +233,34 @@
         $sourceDir = $extensionDir . '/' . $extensionName;
         $targetDir = $package->path() . '/ezextension';
 
-        eZDir::mkdir( $targetDir, false, true );
-        eZDir::copy( $sourceDir, $targetDir );
+        $fileHandler = eZClusterFileHandler::instance();
 
-        eZDir::recursiveList( $targetDir, '', $fileList );
+        $includeHidden = true;
+        $items = eZDir::findSubitems( $sourceDir, 'df', false, $includeHidden );
+        while ( count( $items ) > 0 )
+        {
+            $currentItems = $items;
+            $items = array();
+            foreach ( $currentItems as $item )
+            {
+                $fullPath = $sourceDir . '/' . $item;
+                if ( is_file( $fullPath ) )
+                {
+                    $fileHandler->fileStoreContents( $targetDir . '/' . $item, file_get_contents( $fullPath ), 'package' );
+                }
+                else if ( is_dir( $fullPath ) )
+                {
+                    $newItems = eZDir::findSubitems( $fullPath, 'df', $item, $includeHidden );
+                    $items = array_merge( $items, $newItems );
+                    unset( $newItems );
+                }
+            }
+        }
 
-        $doc = new DOMDocument;
+        eZDir::recursiveList( $sourceDir, '', $fileList );
 
+        $doc = new DOMDocument( '1.0', 'utf-8' );
+
         $packageRoot = $doc->createElement( 'extension' );
         $packageRoot->setAttribute( 'name', $extensionName );
 
@@ -250,10 +273,14 @@
                 $fileNode->setAttribute( 'path', $file['path'] );
 
             $fullPath = $targetDir . $file['path'] . '/' . $file['name'];
-            $fileNode->setAttribute( 'md5sum', $package->md5sum( $fullPath ) );
-
-            if ( $file['type'] == 'dir' )
+            if ( $file['type'] != 'dir' )
+            {
+                $fileNode->setAttribute( 'md5sum', $package->md5sum( $fullPath ) );
+            }
+            else
+            {
                  $fileNode->setAttribute( 'type', 'dir' );
+             }
 
             $packageRoot->appendChild( $fileNode );
             unset( $fileNode );
Index: kernel/classes/packagehandlers/ezinstallscript/ezinstallscriptpackagehandler.php
===================================================================
--- kernel/classes/packagehandlers/ezinstallscript/ezinstallscriptpackagehandler.php	(revision 21470)
+++ kernel/classes/packagehandlers/ezinstallscript/ezinstallscriptpackagehandler.php	(working copy)
@@ -109,6 +109,8 @@
         $siteINI = eZINI::instance();
         $extensionDir = $siteINI->variable( 'ExtensionSettings', 'ExtensionDirectory' );
 
+        $fileHandler = eZClusterFileHandler::instance();
+
         //$cli->output( var_export( $parameters, true ) );
         foreach ( $parameters as $scriptItem )
         {
@@ -117,8 +119,27 @@
             $sourceDir = $scriptItem['source-directory'];
             $targetDir = $package->path() . '/' . $scriptItem['sub-directory'];
 
-            eZDir::mkdir( $targetDir, false, true );
-            eZDir::copy( $sourceDir, $targetDir, false );
+            $includeHidden = true;
+            $items = eZDir::findSubitems( $sourceDir, 'df', false, $includeHidden );
+            while ( count( $items ) > 0 )
+            {
+                $currentItems = $items;
+                $items = array();
+                foreach ( $currentItems as $item )
+                {
+                    $fullPath = $sourceDir . '/' . $item;
+                    if ( is_file( $fullPath ) )
+                    {
+                        $fileHandler->fileStoreContents( $targetDir . '/' . $item, file_get_contents( $fullPath ), 'package' );
+                    }
+                    else if ( is_dir( $fullPath ) )
+                    {
+                        $newItems = eZDir::findSubitems( $fullPath, 'df', $item, $includeHidden );
+                        $items = array_merge( $items, $newItems );
+                        unset( $newItems );
+                    }
+                }
+            }
 
             $package->appendInstall( 'ezinstallscript', false, false, true,
                                      $scriptItem['filename'], $scriptItem['sub-directory'],
Index: kernel/classes/packageinstallers/ezinstallscript/ezinstallscriptpackageinstaller.php
===================================================================
--- kernel/classes/packageinstallers/ezinstallscript/ezinstallscriptpackageinstaller.php	(revision 21470)
+++ kernel/classes/packageinstallers/ezinstallscript/ezinstallscriptpackageinstaller.php	(working copy)
@@ -67,7 +67,12 @@
         if ( $dom )
             $mainNode =& $dom->root();
 
-        $return['file-path'] = $itemPath . '/' . $mainNode->getAttribute( 'filename' );
+        $filePath = $itemPath . '/' . $mainNode->getAttribute( 'filename' );
+
+        $fileHandler = eZClusterFileHandler::instance();
+        $fileHandler->fileFetch( $filePath );
+
+        $return['file-path'] = $filePath;
         $return['classname'] = $mainNode->getAttribute( 'classname' );
 
         return $return;
@@ -78,8 +83,11 @@
         $itemPath = $package->path() . '/' . $installItem['sub-directory'];
         $stepTemplatePath = $itemPath . '/templates';
 
+        $fileHandler = eZClusterFileHandler::instance();
+        $fileHandler->fileFetch( $stepTemplatePath . '/' . $step['template'] );
+
         return array( 'name' => $step['template'],
-                      'path' => $stepTemplatePath );
+                      'path' =>  $stepTemplatePath );
     }
 }
 ?>
