summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-11-07 17:18:56 +0100
committerRobin Appelman <icewind@owncloud.com>2012-11-07 17:18:56 +0100
commit961ff01a93dd69cb12196a1b8507cce925e74fbc (patch)
tree4956c9a42d6286b0851ca73641439e5c002f6a9a /apps/files_external
parent4b940955ddb3266f625eae83da412a655efef319 (diff)
parent5cad2d7ccc3d2b4ccd9e1b090e28787f1c28b6ca (diff)
downloadnextcloud-server-961ff01a93dd69cb12196a1b8507cce925e74fbc.tar.gz
nextcloud-server-961ff01a93dd69cb12196a1b8507cce925e74fbc.zip
merge master into filesystem
Diffstat (limited to 'apps/files_external')
-rwxr-xr-xapps/files_external/lib/config.php7
-rw-r--r--apps/files_external/lib/ftp.php10
-rw-r--r--apps/files_external/lib/smb.php12
-rw-r--r--apps/files_external/lib/swift.php54
-rw-r--r--apps/files_external/lib/webdav.php12
-rw-r--r--apps/files_external/tests/ftp.php18
6 files changed, 79 insertions, 34 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 6c6c23b55c1..81225586326 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -285,7 +285,12 @@ class OC_Mount_Config {
public static function getCertificates() {
$view = \OCP\Files::getStorage('files_external');
$path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
- if (!is_dir($path)) mkdir($path);
+ \OCP\Util::writeLog('files_external', 'checking path '.$path, \OCP\Util::INFO);
+ if(!is_dir($path)) {
+ //path might not exist (e.g. non-standard OC_User::getHome() value)
+ //in this case create full path using 3rd (recursive=true) parameter.
+ mkdir($path, 0777, true);
+ }
$result = array();
$handle = opendir($path);
if (!$handle) {
diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php
index a3677e82e2e..0b60d42219a 100644
--- a/apps/files_external/lib/ftp.php
+++ b/apps/files_external/lib/ftp.php
@@ -21,7 +21,15 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
$this->host=$params['host'];
$this->user=$params['user'];
$this->password=$params['password'];
- $this->secure=isset($params['secure'])?(bool)$params['secure']:false;
+ if(isset($params['secure'])){
+ if(is_string($params['secure'])){
+ $this->secure = ($params['secure'] === 'true');
+ }else{
+ $this->secure = (bool)$params['secure'];
+ }
+ }else{
+ $this->secure = false;
+ }
$this->root=isset($params['root'])?$params['root']:'/';
if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php
index 4382f630031..bf0d780d27b 100644
--- a/apps/files_external/lib/smb.php
+++ b/apps/files_external/lib/smb.php
@@ -26,30 +26,28 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
- if(substr($this->root,-1,1)!='/') {
+ if(substr($this->root, -1, 1)!='/') {
$this->root.='/';
}
if(!$this->share || $this->share[0]!='/') {
$this->share='/'.$this->share;
}
- if(substr($this->share,-1,1)=='/') {
- $this->share=substr($this->share,0,-1);
+ if(substr($this->share, -1, 1)=='/') {
+ $this->share = substr($this->share,0,-1);
}
- }
public function getId(){
return 'smb::' . $this->user . '@' . $this->host . '/' . $this->share . '/' . $this->root;
}
public function constructUrl($path) {
- if(substr($path,-1)=='/') {
- $path=substr($path,0,-1);
+ if(substr($path, -1)=='/') {
+ $path=substr($path, 0, -1);
}
return 'smb://'.$this->user.':'.$this->password.'@'.$this->host.$this->share.$this->root.$path;
}
public function stat($path) {
- $this->init();
if(!$path and $this->root=='/') {//mtime doesn't work for shares
$mtime=$this->shareMTime();
$stat=stat($this->constructUrl($path));
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php
index 7fb9b7e640d..844b54aaeea 100644
--- a/apps/files_external/lib/swift.php
+++ b/apps/files_external/lib/swift.php
@@ -205,15 +205,15 @@ class SWIFT extends \OC\Files\Storage\Common{
foreach($containers as &$sub) {
$sub=trim($sub);
}
- if(array_search($name,$containers)!==false) {
+ if(array_search($name, $containers) !== false) {
unlink($tmpFile);
return false;
}else{
- $fh=fopen($tmpFile,'a');
- fwrite($fh,$name."\n");
+ $fh=fopen($tmpFile, 'a');
+ fwrite($fh,$name . "\n");
}
}catch(\Exception $e) {
- file_put_contents($tmpFile,$name."\n");
+ file_put_contents($tmpFile, $name . "\n");
}
$obj->load_from_filename($tmpFile);
@@ -227,7 +227,7 @@ class SWIFT extends \OC\Files\Storage\Common{
* @param string $name
* @return bool
*/
- private function removeSubContainer($container,$name) {
+ private function removeSubContainer($container, $name) {
if(!$name) {
return false;
}
@@ -242,13 +242,13 @@ class SWIFT extends \OC\Files\Storage\Common{
foreach($containers as &$sub) {
$sub=trim($sub);
}
- $i=array_search($name,$containers);
+ $i=array_search($name, $containers);
if($i===false) {
unlink($tmpFile);
return false;
}else{
unset($containers[$i]);
- file_put_contents($tmpFile, implode("\n",$containers)."\n");
+ file_put_contents($tmpFile, implode("\n", $containers)."\n");
}
$obj->load_from_filename($tmpFile);
@@ -264,7 +264,7 @@ class SWIFT extends \OC\Files\Storage\Common{
private function getSubContainerFile($container) {
try{
return $container->get_object(self::SUBCONTAINER_FILE);
- }catch(\NoSuchObjectException $e) {
+ }catch(NoSuchObjectException $e) {
return $container->create_object(self::SUBCONTAINER_FILE);
}
}
@@ -274,9 +274,15 @@ class SWIFT extends \OC\Files\Storage\Common{
$this->host=$params['host'];
$this->user=$params['user'];
$this->root=isset($params['root'])?$params['root']:'/';
- $this->secure=isset($params['secure'])?(bool)$params['secure']:true;
-
- $this->id = 'swift::' . $this->user . '@' . $this->host . '/' . $this->root;
+ if(isset($params['secure'])){
+ if(is_string($params['secure'])){
+ $this->secure = ($params['secure'] === 'true');
+ }else{
+ $this->secure = (bool)$params['secure'];
+ }
+ }else{
+ $this->secure = false;
+ }
if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
@@ -358,12 +364,12 @@ class SWIFT extends \OC\Files\Storage\Common{
$this->init();
$container=$this->getContainer($path);
$files=$this->getObjects($container);
- $i=array_search(self::SUBCONTAINER_FILE,$files);
+ $i=array_search(self::SUBCONTAINER_FILE, $files);
if($i!==false) {
unset($files[$i]);
}
$subContainers=$this->getSubContainers($container);
- $files=array_merge($files,$subContainers);
+ $files=array_merge($files, $subContainers);
$id=$this->getContainerName($path);
\OC_FakeDirStream::$dirs[$id]=$files;
return opendir('fakedir://'.$id);
@@ -404,7 +410,7 @@ class SWIFT extends \OC\Files\Storage\Common{
return $obj->read();
}
- public function file_put_contents($path,$content) {
+ public function file_put_contents($path, $content) {
$this->init();
$obj=$this->getObject($path);
if(is_null($obj)) {
@@ -432,7 +438,7 @@ class SWIFT extends \OC\Files\Storage\Common{
}
}
- public function fopen($path,$mode) {
+ public function fopen($path, $mode) {
$this->init();
switch($mode) {
case 'r':
@@ -459,9 +465,9 @@ class SWIFT extends \OC\Files\Storage\Common{
case 'c':
case 'c+':
$tmpFile=$this->getTmpFile($path);
- \OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
+ OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this, 'writeBack');
self::$tempFiles[$tmpFile]=$path;
- return fopen('close://'.$tmpFile,$mode);
+ return fopen('close://'.$tmpFile, $mode);
}
}
@@ -476,7 +482,7 @@ class SWIFT extends \OC\Files\Storage\Common{
return 1024*1024*1024*8;
}
- public function touch($path,$mtime=null) {
+ public function touch($path, $mtime=null) {
$this->init();
$obj=$this->getObject($path);
if(is_null($obj)) {
@@ -491,11 +497,11 @@ class SWIFT extends \OC\Files\Storage\Common{
$obj->sync_metadata();
}
- public function rename($path1,$path2) {
+ public function rename($path1, $path2) {
$this->init();
$sourceContainer=$this->getContainer(dirname($path1));
$targetContainer=$this->getContainer(dirname($path2));
- $result=$sourceContainer->move_object_to(basename($path1),$targetContainer, basename($path2));
+ $result=$sourceContainer->move_object_to(basename($path1), $targetContainer, basename($path2));
unset($this->objects[$path1]);
if($result) {
$targetObj=$this->getObject($path2);
@@ -504,11 +510,11 @@ class SWIFT extends \OC\Files\Storage\Common{
return $result;
}
- public function copy($path1,$path2) {
+ public function copy($path1, $path2) {
$this->init();
$sourceContainer=$this->getContainer(dirname($path1));
$targetContainer=$this->getContainer(dirname($path2));
- $result=$sourceContainer->copy_object_to(basename($path1),$targetContainer, basename($path2));
+ $result=$sourceContainer->copy_object_to(basename($path1), $targetContainer, basename($path2));
if($result) {
$targetObj=$this->getObject($path2);
$this->resetMTime($targetObj);
@@ -523,6 +529,7 @@ class SWIFT extends \OC\Files\Storage\Common{
return array(
'mtime'=>-1,
'size'=>$container->bytes_used,
+ 'ctime'=>-1
);
}
@@ -540,6 +547,7 @@ class SWIFT extends \OC\Files\Storage\Common{
return array(
'mtime'=>$mtime,
'size'=>$obj->content_length,
+ 'ctime'=>-1,
);
}
@@ -555,7 +563,7 @@ class SWIFT extends \OC\Files\Storage\Common{
}
}
- private function fromTmpFile($tmpFile,$path) {
+ private function fromTmpFile($tmpFile, $path) {
$this->init();
$obj=$this->getObject($path);
if(is_null($obj)) {
diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php
index 26d24ceff03..5fc0111f2ae 100644
--- a/apps/files_external/lib/webdav.php
+++ b/apps/files_external/lib/webdav.php
@@ -30,7 +30,15 @@ class DAV extends \OC\Files\Storage\Common{
$this->host=$host;
$this->user=$params['user'];
$this->password=$params['password'];
- $this->secure=(isset($params['secure']) && $params['secure'] == 'true')?true:false;
+ if(isset($params['secure'])){
+ if(is_string($params['secure'])){
+ $this->secure = ($params['secure'] === 'true');
+ }else{
+ $this->secure = (bool)$params['secure'];
+ }
+ }else{
+ $this->secure = false;
+ }
$this->root=isset($params['root'])?$params['root']:'/';
if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
@@ -56,7 +64,7 @@ class DAV extends \OC\Files\Storage\Common{
if($caview = \OCP\Files::getStorage('files_external')) {
$certPath=\OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt';
- if (file_exists($certPath)) {
+ if (file_exists($certPath)) {
$this->client->addTrustedCertificates($certPath);
}
}
diff --git a/apps/files_external/tests/ftp.php b/apps/files_external/tests/ftp.php
index 3e6208e4a0d..970c83b0bca 100644
--- a/apps/files_external/tests/ftp.php
+++ b/apps/files_external/tests/ftp.php
@@ -26,4 +26,22 @@ class FTP extends Storage {
\OCP\Files::rmdirr($this->instance->constructUrl(''));
}
}
+
+ public function testConstructUrl(){
+ $config = array ( 'host' => 'localhost', 'user' => 'ftp', 'password' => 'ftp', 'root' => '/', 'secure' => false );
+ $instance = new OC_Filestorage_FTP($config);
+ $this->assertEqual('ftp://ftp:ftp@localhost/', $instance->constructUrl(''));
+
+ $config['secure'] = true;
+ $instance = new OC_Filestorage_FTP($config);
+ $this->assertEqual('ftps://ftp:ftp@localhost/', $instance->constructUrl(''));
+
+ $config['secure'] = 'false';
+ $instance = new OC_Filestorage_FTP($config);
+ $this->assertEqual('ftp://ftp:ftp@localhost/', $instance->constructUrl(''));
+
+ $config['secure'] = 'true';
+ $instance = new OC_Filestorage_FTP($config);
+ $this->assertEqual('ftps://ftp:ftp@localhost/', $instance->constructUrl(''));
+ }
}