From 596246989217143d78e8987fa7b2c4154806a644 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 18 Aug 2012 01:17:28 +0200 Subject: [PATCH] add OC_Archive::addRecursive --- lib/archive.php | 21 +++++++++++++++++++++ tests/lib/archive.php | 8 ++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/archive.php b/lib/archive.php index 113f92e960..fabd7cc7a5 100644 --- a/lib/archive.php +++ b/lib/archive.php @@ -112,4 +112,25 @@ abstract class OC_Archive{ * @return resource */ abstract function getStream($path,$mode); + /** + * add a folder and all it's content + * @param string $path + * @param string source + * @return bool + */ + function addRecursive($path,$source){ + if($dh=opendir($source)){ + $this->addFolder($path); + while($file=readdir($dh)){ + if($file=='.' or $file=='..'){ + continue; + } + if(is_dir($source.'/'.$file)){ + $this->addRecursive($path.'/'.$file,$source.'/'.$file); + }else{ + $this->addFile($path.'/'.$file,$source.'/'.$file); + } + } + } + } } diff --git a/tests/lib/archive.php b/tests/lib/archive.php index 1779127c93..1711be58e0 100644 --- a/tests/lib/archive.php +++ b/tests/lib/archive.php @@ -130,4 +130,12 @@ abstract class Test_Archive extends UnitTestCase { $this->instance->remove('target.txt'); $this->assertFalse($this->instance->fileExists('target.txt')); } + public function testRecursive(){ + $dir=OC::$SERVERROOT.'/apps/files_archive/tests/data'; + $this->instance=$this->getNew(); + $this->instance->addRecursive('/dir',$dir); + $this->assertTrue($this->instance->fileExists('/dir/lorem.txt')); + $this->assertTrue($this->instance->fileExists('/dir/data.zip')); + $this->assertTrue($this->instance->fileExists('/dir/data.tar.gz')); + } }