summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGeorg Ehrke <dev@georgswebsite.de>2012-03-29 23:20:03 +0200
committerGeorg Ehrke <dev@georgswebsite.de>2012-03-29 23:20:03 +0200
commit90286353e24738006128b1801c55483d2103e6ae (patch)
tree869ece50a1b45b6d99d399890743e2cfb3c78d22 /lib
parent536a3ecb428b9450a188de4a0fcca2f9be6318f3 (diff)
parentf74d11c0c3c4a3bcd733499edd63f8e31389a3a3 (diff)
downloadnextcloud-server-90286353e24738006128b1801c55483d2103e6ae.tar.gz
nextcloud-server-90286353e24738006128b1801c55483d2103e6ae.zip
Merge branch 'master' into sabredav_1.6
Diffstat (limited to 'lib')
-rw-r--r--lib/db.php3
-rwxr-xr-xlib/helper.php15
-rw-r--r--lib/installer.php35
3 files changed, 42 insertions, 11 deletions
diff --git a/lib/db.php b/lib/db.php
index 9fab51edfcd..a0fb6c385d8 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -318,9 +318,6 @@ class OC_DB {
// Make changes and save them to an in-memory file
$file2 = 'static://db_scheme';
- if($file2 == ''){
- die('could not create tempfile in get_temp_dir() - aborting');
- }
$content = str_replace( '*dbname*', $CONFIG_DBNAME, $content );
$content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content );
if( $CONFIG_DBTYPE == 'pgsql' ){ //mysql support it too but sqlite doesn't
diff --git a/lib/helper.php b/lib/helper.php
index 66f31d929be..efff00c2fe6 100755
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -432,6 +432,19 @@ class OC_Helper {
self::$tmpFiles[]=$file;
return $file;
}
+
+ /**
+ * create a temporary folder with an unique filename
+ * @return string
+ *
+ * temporary files are automatically cleaned up after the script is finished
+ */
+ public static function tmpFolder(){
+ $path=get_temp_dir().'/'.md5(time().rand());
+ mkdir($path);
+ self::$tmpFiles[]=$path;
+ return $path.'/';
+ }
/**
* remove all files created by self::tmpFile
@@ -439,7 +452,7 @@ class OC_Helper {
public static function cleanTmp(){
foreach(self::$tmpFiles as $file){
if(file_exists($file)){
- unlink($file);
+ self::rmdirr($file);
}
}
}
diff --git a/lib/installer.php b/lib/installer.php
index 2a9676998f6..c5ecacae544 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);
@@ -95,6 +105,17 @@ class OC_Installer{
//load the info.xml file of the app
if(!is_file($extractDir.'/appinfo/info.xml')){
+ //try to find it in a subdir
+ $dh=opendir($extractDir);
+ while($folder=readdir($dh)){
+ if(substr($folder,0,1)!='.' and is_dir($extractDir.'/'.$folder)){
+ if(is_file($extractDir.'/'.$folder.'/appinfo/info.xml')){
+ $extractDir.='/'.$folder;
+ }
+ }
+ }
+ }
+ if(!is_file($extractDir.'/appinfo/info.xml')){
OC_Log::write('core','App does not provide an info.xml file',OC_Log::ERROR);
OC_Helper::rmdirr($extractDir);
if($data['source']=='http'){