function purge($printCallback = false, $microsleep = false, $max = false, $expiry = false)
 {
     $file = $this->filePath;
     if ($max === false) {
         $max = 100;
     }
     $count = 0;
     $list = array();
     if (is_file($file)) {
         $list = array($file);
     } else {
         $globResult = glob($file . "/*");
         if (is_array($globResult)) {
             $list = $globResult;
         }
     }
     do {
         if ($count % $max == 0 && $microsleep) {
             usleep($microsleep);
         }
         // Sleep a bit to make the filesystem happier
         $count = 0;
         $file = array_shift($list);
         if (is_file($file)) {
             $mtime = @filemtime($file);
             if ($expiry === false || $mtime < $expiry) {
                 @unlink($file);
                 eZClusterFileHandler::cleanupEmptyDirectories($file);
             }
             ++$count;
         } else {
             if (is_dir($file)) {
                 $globResult = glob($file . "/*");
                 if (is_array($globResult)) {
                     $list = array_merge($globResult, $list);
                 }
             }
         }
         if ($printCallback) {
             call_user_func_array($printCallback, array($file, 1));
         }
     } while (count($list) > 0);
 }
 /**
  * Renamed DFS file $oldPath to DFS file $newPath
  *
  * @param string $oldPath
  * @param string $newPath
  * @return bool
  */
 public function renameOnDFS($oldPath, $newPath)
 {
     $this->accumulatorStart();
     $oldPath = $this->makeDFSPath($oldPath);
     $newPath = $this->makeDFSPath($newPath);
     $ret = eZFile::rename($oldPath, $newPath, true);
     if ($ret) {
         eZClusterFileHandler::cleanupEmptyDirectories($oldPath);
     }
     $this->accumulatorStop();
     return $ret;
 }
    /**
     * Purge local and remote file data for current file.
     */
    function purge( $printCallback = false, $microsleep = false, $max = false, $expiry = false )
    {
        $file = $this->filePath;
        if ( $max === false )
            $max = 100;
        $count = 0;
        if ( is_file( $file ) )
            $list = array( $file );
        else
            $list = glob( $file . "/*" );
        do
        {
            if ( ( $count % $max ) == 0 && $microsleep )
                usleep( $microsleep ); // Sleep a bit to make the filesystem happier

            $count = 0;
            $file = array_shift( $list );

            if ( is_file( $file ) )
            {
                $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 ) )
            {
                $list = array_merge( $list, glob( $file . "/*" ) );
            }

            if ( $printCallback )
                call_user_func_array( $printCallback,
                                      array( $file, 1 ) );
        } while ( count( $list ) > 0 );
    }
 /**
  * Purges local and remote file data for current file path.
  *
  * Can be given a file or a folder. In order to clear a folder, do NOT add
  * a trailing / at the end of the file's path: path/to/file instead of
  * path/to/file/.
  *
  * By default, only expired files will be removed (ezdfsfile.expired = 1).
  * If you specify an $expiry time, it will replace the expired test and
  * only purge files older than the given expiry timestamp.
  *
  * @param callback $printCallback
  *        Callback called after each delete iteration (@see $max) to print
  *        out a report of the deleted files. This callback expects two
  *        parameters, $file (delete pattern used to perform deletion) and
  *        $count (number of deleted items)
  * @param int $microsleep
  *        Wait interval before each purge batch of $max items
  * @param int $max
  *        Maximum number of items to delete in one batch (default: 100)
  * @param int $expiry
  *        If specificed, only files older than this date will be purged
  * @return void
  */
 function purge($printCallback = false, $microsleep = false, $max = false, $expiry = false)
 {
     eZDebugSetting::writeDebug('kernel-clustering', "dfs::purge( '{$this->filePath}' )");
     $file = $this->filePath;
     if ($max === false) {
         $max = 100;
     }
     $count = 0;
     /**
      * The loop starts without knowing how many files are to be deleted.
      * When _purgeByLike is called, it returns the number of affected rows.
      * If rows were affected, _purgeByLike will be called again
      */
     do {
         // @todo this won't work on windows, make a wrapper that uses
         //       either usleep or sleep depending on the OS
         if ($count > 0 && $microsleep) {
             usleep($microsleep);
             // Sleep a bit to make the database happier
         }
         $count = self::$dbbackend->_purgeByLike($file . "/%", true, $max, $expiry, 'purge');
         self::$dbbackend->_purge($file, true, $expiry, 'purge');
         if ($printCallback) {
             call_user_func_array($printCallback, array($file, $count));
         }
         // @todo Compare $count to $max. If $count < $max, no more files are to
         // be purged, and we can exit the loop
     } while ($count > 0);
     // Remove local copies
     if (is_file($file)) {
         @unlink($file);
     } elseif (is_dir($file)) {
         eZDir::recursiveDelete($file);
     }
     eZClusterFileHandler::cleanupEmptyDirectories($file);
 }
    function purge( $printCallback = false, $microsleep = false, $max = false, $expiry = false )
    {
        $file = $this->filePath;
        if ( $max === false )
            $max = 100;
        $count = 0;
        do
        {
            if ( $count > 0 && $microsleep )
                usleep( $microsleep ); // Sleep a bit to make the database happier
            $count = self::$dbbackend->_purgeByLike( $file . "/%", true, $max, $expiry, 'purge' );
            self::$dbbackend->_purge( $file, true, $expiry, 'purge' );
            if ( $printCallback )
                call_user_func_array( $printCallback,
                                      array( $file, $count ) );
        } while ( $count > 0 );
        // Remove local copy
        if ( is_file( $file ) )
        {
            @unlink( $file );
        }
        else if ( is_dir( $file ) )
        {
            eZDir::recursiveDelete( $file );
        }

        eZClusterFileHandler::cleanupEmptyDirectories( $file );
    }