add OC_FileStorage::getLocalFolder
This commit is contained in:
parent
eb42148210
commit
9b44d0cb32
|
@ -50,6 +50,7 @@ abstract class OC_Filestorage{
|
|||
abstract public function search($query);
|
||||
abstract public function touch($path, $mtime=null);
|
||||
abstract public function getLocalFile($path);// get a path to a local version of the file, whether the original file is local or remote
|
||||
abstract public function getLocalFolder($path);// get a path to a local version of the folder, whether the original file is local or remote
|
||||
/**
|
||||
* check if a file or folder has been updated since $time
|
||||
* @param int $time
|
||||
|
|
|
@ -223,6 +223,26 @@ abstract class OC_Filestorage_Common extends OC_Filestorage {
|
|||
OC_Helper::streamCopy($source,$target);
|
||||
return $tmpFile;
|
||||
}
|
||||
public function getLocalFolder($path){
|
||||
$baseDir=OC_Helper::tmpFolder();
|
||||
$this->addLocalFolder($path,$baseDir);
|
||||
return $baseDir;
|
||||
}
|
||||
private function addLocalFolder($path,$target){
|
||||
if($dh=$this->opendir($path)){
|
||||
while($file=readdir($dh)){
|
||||
if($file!=='.' and $file!=='..'){
|
||||
if($this->is_dir($path.'/'.$file)){
|
||||
mkdir($target.'/'.$file);
|
||||
$this->addLocalFolder($path.'/'.$file,$target.'/'.$file);
|
||||
}else{
|
||||
$tmp=$this->toTmpFile($path.'/'.$file);
|
||||
rename($tmp,$target.'/'.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// abstract public function touch($path, $mtime=null);
|
||||
|
||||
protected function searchInDir($query,$dir=''){
|
||||
|
|
|
@ -168,7 +168,10 @@ class OC_Filestorage_Local extends OC_Filestorage_Common{
|
|||
return $this->searchInDir($query);
|
||||
}
|
||||
public function getLocalFile($path){
|
||||
return $this->datadir.$path;
|
||||
return $this->datadir.$path;
|
||||
}
|
||||
public function getLocalFolder($path){
|
||||
return $this->datadir.$path;
|
||||
}
|
||||
|
||||
protected function searchInDir($query,$dir=''){
|
||||
|
|
|
@ -129,12 +129,25 @@ abstract class Test_FileStorage extends UnitTestCase {
|
|||
$this->assertEqual(file_get_contents($textFile),$this->instance->file_get_contents('/target.txt'));
|
||||
}
|
||||
|
||||
public function testLocalFile(){
|
||||
public function testLocal(){
|
||||
$textFile=OC::$SERVERROOT.'/tests/data/lorem.txt';
|
||||
$this->instance->file_put_contents('/lorem.txt',file_get_contents($textFile));
|
||||
$localFile=$this->instance->getLocalFile('/lorem.txt');
|
||||
$this->assertTrue(file_exists($localFile));
|
||||
$this->assertEqual(file_get_contents($localFile),file_get_contents($textFile));
|
||||
|
||||
$this->instance->mkdir('/folder');
|
||||
$this->instance->file_put_contents('/folder/lorem.txt',file_get_contents($textFile));
|
||||
$this->instance->file_put_contents('/folder/bar.txt','asd');
|
||||
$this->instance->mkdir('/folder/recursive');
|
||||
$this->instance->file_put_contents('/folder/recursive/file.txt','foo');
|
||||
$localFolder=$this->instance->getLocalFolder('/folder');
|
||||
|
||||
$this->assertTrue(is_dir($localFolder));
|
||||
$this->assertTrue(file_exists($localFolder.'/lorem.txt'));
|
||||
$this->assertEqual(file_get_contents($localFolder.'/lorem.txt'),file_get_contents($textFile));
|
||||
$this->assertEqual(file_get_contents($localFolder.'/bar.txt'),'asd');
|
||||
$this->assertEqual(file_get_contents($localFolder.'/recursive/file.txt'),'foo');
|
||||
}
|
||||
|
||||
public function testStat(){
|
||||
|
|
Loading…
Reference in New Issue