From d6a9af31389819c95084e33aab3c7f4a6d4cbef8 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Thu, 29 Mar 2012 00:07:28 +0200
Subject: add support for installing apps from tgz

---
 lib/installer.php | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

(limited to 'lib')

diff --git a/lib/installer.php b/lib/installer.php
index 2a9676998f6..db64d8e32d5 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -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);
-- 
cgit v1.2.3