summaryrefslogtreecommitdiffstats
path: root/apps/files_archive
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-03-28 22:31:45 +0200
committerRobin Appelman <icewind@owncloud.com>2012-03-28 23:47:44 +0200
commite57de98bbedfbf71841235fe01b10787d5e41962 (patch)
treeee13246387822d88901e8f2b7017ab9687ac8d0a /apps/files_archive
parentd8e9db207f94d8a46cd8a81caa1b49cd64843259 (diff)
downloadnextcloud-server-e57de98bbedfbf71841235fe01b10787d5e41962.tar.gz
nextcloud-server-e57de98bbedfbf71841235fe01b10787d5e41962.zip
add extract all option to OC_Archive
Diffstat (limited to 'apps/files_archive')
-rw-r--r--apps/files_archive/lib/archive.php7
-rw-r--r--apps/files_archive/lib/zip.php9
-rw-r--r--apps/files_archive/tests/archive.php15
3 files changed, 29 insertions, 2 deletions
diff --git a/apps/files_archive/lib/archive.php b/apps/files_archive/lib/archive.php
index be89f894fb7..3be3388a3b0 100644
--- a/apps/files_archive/lib/archive.php
+++ b/apps/files_archive/lib/archive.php
@@ -78,6 +78,13 @@ abstract class OC_Archive{
*/
abstract function extractFile($path,$dest);
/**
+ * extract the archive
+ * @param string path
+ * @param string dest
+ * @return bool
+ */
+ abstract function extract($dest);
+ /**
* check if a file or folder exists in the archive
* @param string path
* @return bool
diff --git a/apps/files_archive/lib/zip.php b/apps/files_archive/lib/zip.php
index eab101b3a5c..16f2273f443 100644
--- a/apps/files_archive/lib/zip.php
+++ b/apps/files_archive/lib/zip.php
@@ -129,6 +129,15 @@ class OC_Archive_ZIP extends OC_Archive{
file_put_contents($dest,$fp);
}
/**
+ * extract the archive
+ * @param string path
+ * @param string dest
+ * @return bool
+ */
+ function extract($dest){
+ return $this->zip->extractTo($dest);
+ }
+ /**
* check if a file or folder exists in the archive
* @param string path
* @return bool
diff --git a/apps/files_archive/tests/archive.php b/apps/files_archive/tests/archive.php
index 2e26b5e03b5..2619d91b3b8 100644
--- a/apps/files_archive/tests/archive.php
+++ b/apps/files_archive/tests/archive.php
@@ -27,10 +27,10 @@ abstract class Test_Archive extends UnitTestCase {
$this->instance=$this->getExisting();
$allFiles=$this->instance->getFiles();
$expected=array('lorem.txt','logo-wide.png','dir/','dir/lorem.txt');
- $this->assertEqual(4,count($allFiles));
+ $this->assertEqual(4,count($allFiles),'only found '.count($allFiles).' out of 4 expected files');
foreach($expected as $file){
$this->assertNotIdentical(false,array_search($file,$allFiles),'cant find '.$file.' in archive');
- $this->assertTrue($this->instance->fileExists($file));
+ $this->assertTrue($this->instance->fileExists($file),'file '.$file.' does not exist in archive');
}
$this->assertFalse($this->instance->fileExists('non/existing/file'));
@@ -94,4 +94,15 @@ abstract class Test_Archive extends UnitTestCase {
$this->assertTrue($this->instance->fileExists('lorem.txt'));
$this->assertEqual(file_get_contents($dir.'/lorem.txt'),$this->instance->getFile('lorem.txt'));
}
+ public function testExtract(){
+ $dir=OC::$SERVERROOT.'/apps/files_archive/tests/data';
+ $this->instance=$this->getExisting();
+ $tmpDir=OC_Helper::tmpFolder();
+ $this->instance->extract($tmpDir);
+ $this->assertEqual(true,file_exists($tmpDir.'lorem.txt'));
+ $this->assertEqual(true,file_exists($tmpDir.'dir/lorem.txt'));
+ $this->assertEqual(true,file_exists($tmpDir.'logo-wide.png'));
+ $this->assertEqual(file_get_contents($dir.'/lorem.txt'),file_get_contents($tmpDir.'lorem.txt'));
+ OC_Helper::rmdirr($tmpDir);
+ }
}