add support for installing apps from tgz

This commit is contained in:
Robin Appelman 2012-03-29 00:07:28 +02:00
parent 72882beb0d
commit d6a9af3138
1 changed files with 17 additions and 7 deletions

View File

@ -62,7 +62,7 @@ class OC_Installer{
//download the file if necesary
if($data['source']=='http'){
$path=OC_Helper::tmpFile('.zip');
$path=OC_Helper::tmpFile();
if(!isset($data['href'])){
OC_Log::write('core','No href specified when installing app from http',OC_Log::ERROR);
return false;
@ -76,14 +76,24 @@ class OC_Installer{
$path=$data['path'];
}
//detect the archive type
$mime=OC_Helper::getMimeType($path);
if($mime=='application/zip'){
rename($path,$path.'.zip');
$path.='.zip';
}elseif($mime=='application/x-gzip'){
rename($path,$path.'.tgz');
$path.='.tgz';
}else{
OC_Log::write('core','Archives of type '.$mime.' are not supported',OC_Log::ERROR);
return false;
}
//extract the archive in a temporary folder
$extractDir=tempnam(get_temp_dir(),'oc_installer_uncompressed_');
unlink($extractDir);
$extractDir=OC_Helper::tmpFolder();
mkdir($extractDir);
$zip = new ZipArchive;
if($zip->open($path)===true){
$zip->extractTo($extractDir);
$zip->close();
if($archive=OC_Archive::open($path)){
$archive->extract($extractDir);
} else {
OC_Log::write('core','Failed to open archive when installing app',OC_Log::ERROR);
OC_Helper::rmdirr($extractDir);