protected static function _addPackageToArchive(Engine_Package_Manifest $package, Archive_Tar $archive, $basePath)
 {
     $rval = null;
     foreach ($package->getStructure() as $name => $contents) {
         if (!$contents instanceof Engine_Package_Manifest_Entity_Abstract) {
             continue;
         }
         switch ($contents->getType()) {
             case 'package':
                 $subPackageObject = new Engine_Package_Manifest($basePath . DIRECTORY_SEPARATOR . $contents['path'] . DIRECTORY_SEPARATOR . $contents['packageFile']);
                 $subPackageObject->setBasePath($basePath);
                 self::_addPackageToArchive($subPackageObject, $archive, $basePath);
                 break;
             case 'directory':
                 // Add directory
                 $rval = $archive->addModify($basePath . DIRECTORY_SEPARATOR . $contents['path'], null, $basePath);
                 if ($archive->isError($rval)) {
                     throw new Engine_Package_Exception(sprintf('Unable to add path "%s" to archive', $contents['path']));
                 }
                 break;
             case 'file':
                 // Add file
                 $rval = $archive->addModify($basePath . DIRECTORY_SEPARATOR . $contents['path'], null, $basePath);
                 if ($archive->isError($rval)) {
                     throw new Engine_Package_Exception(sprintf('Unable to add path "%s" to archive', $contents['path']));
                 }
                 break;
             default:
                 throw new Engine_Package_Exception('unknown contents type');
                 break;
         }
     }
     // Throw error if failed
     if ($archive->isError($rval)) {
         throw new Engine_Package_Exception('Error in archive: ' . $rval->getMessage());
     }
 }