fix namespace problems for external storage backends

This commit is contained in:
Robin Appelman 2012-10-11 23:17:59 +02:00
parent 542869114a
commit 141ff806c6
8 changed files with 65 additions and 70 deletions

View File

@ -20,10 +20,10 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
require_once 'aws-sdk/sdk.class.php';
namespace OC\Files\Storage; namespace OC\Files\Storage;
require_once 'aws-sdk/sdk.class.php';
class AmazonS3 extends \OC\Files\Storage\Common { class AmazonS3 extends \OC\Files\Storage\Common {
private $s3; private $s3;

View File

@ -20,10 +20,10 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
require_once 'Dropbox/autoload.php';
namespace OC\Files\Storage; namespace OC\Files\Storage;
require_once 'Dropbox/autoload.php';
class Dropbox extends \OC\Files\Storage\Common { class Dropbox extends \OC\Files\Storage\Common {
private $dropbox; private $dropbox;

View File

@ -26,7 +26,7 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
if(!$this->root || $this->root[0]!='/') { if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root; $this->root='/'.$this->root;
} }
//create the root folder if necesary //create the root folder if necessary
if (!$this->is_dir('')) { if (!$this->is_dir('')) {
$this->mkdir(''); $this->mkdir('');
} }
@ -38,7 +38,7 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
/** /**
* construct the ftp url * construct the ftp url
* @param string path * @param string $path
* @return string * @return string
*/ */
public function constructUrl($path) { public function constructUrl($path) {
@ -74,7 +74,7 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
}else{ }else{
$ext=''; $ext='';
} }
$tmpFile=OCP\Files::tmpFile($ext); $tmpFile=\OCP\Files::tmpFile($ext);
\OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack'); \OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
if($this->file_exists($path)) { if($this->file_exists($path)) {
$this->getFile($path,$tmpFile); $this->getFile($path,$tmpFile);
@ -82,6 +82,7 @@ class FTP extends \OC\Files\Storage\StreamWrapper{
self::$tempFiles[$tmpFile]=$path; self::$tempFiles[$tmpFile]=$path;
return fopen('close://'.$tmpFile,$mode); return fopen('close://'.$tmpFile,$mode);
} }
return false;
} }
public function writeBack($tmpFile) { public function writeBack($tmpFile) {

View File

@ -20,10 +20,10 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
require_once 'Google/common.inc.php';
namespace OC\Files\Storage; namespace OC\Files\Storage;
require_once 'Google/common.inc.php';
class Google extends \OC\Files\Storage\Common { class Google extends \OC\Files\Storage\Common {
private $consumer; private $consumer;
@ -62,7 +62,7 @@ class Google extends \OC\Files\Storage\Common {
$tempStr .= '&' . urlencode($key) . '=' . urlencode($value); $tempStr .= '&' . urlencode($key) . '=' . urlencode($value);
} }
$uri = preg_replace('/&/', '?', $tempStr, 1); $uri = preg_replace('/&/', '?', $tempStr, 1);
$request = OAuthRequest::from_consumer_and_token($this->consumer, $this->oauth_token, $httpMethod, $uri, $params); $request = \OAuthRequest::from_consumer_and_token($this->consumer, $this->oauth_token, $httpMethod, $uri, $params);
$request->sign_request($this->sig_method, $this->consumer, $this->oauth_token); $request->sign_request($this->sig_method, $this->consumer, $this->oauth_token);
$auth_header = $request->to_header(); $auth_header = $request->to_header();
$headers = array($auth_header, 'GData-Version: 3.0'); $headers = array($auth_header, 'GData-Version: 3.0');
@ -129,7 +129,7 @@ class Google extends \OC\Files\Storage\Common {
private function getFeed($feedUri, $httpMethod, $postData = null) { private function getFeed($feedUri, $httpMethod, $postData = null) {
$result = $this->sendRequest($feedUri, $httpMethod, $postData); $result = $this->sendRequest($feedUri, $httpMethod, $postData);
if ($result) { if ($result) {
$dom = new DOMDocument(); $dom = new \DOMDocument();
$dom->loadXML($result); $dom->loadXML($result);
return $dom; return $dom;
} }
@ -248,7 +248,7 @@ class Google extends \OC\Files\Storage\Common {
$this->entries[$name] = $entry; $this->entries[$name] = $entry;
} }
} }
OC_FakeDirStream::$dirs['google'.$path] = $files; \OC_FakeDirStream::$dirs['google'.$path] = $files;
return opendir('fakedir://google'.$path); return opendir('fakedir://google'.$path);
} }
@ -407,7 +407,7 @@ class Google extends \OC\Files\Storage\Common {
$ext = ''; $ext = '';
} }
$tmpFile = \OC_Helper::tmpFile($ext); $tmpFile = \OC_Helper::tmpFile($ext);
OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack'); \OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack');
if ($this->file_exists($path)) { if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r'); $source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source); file_put_contents($tmpFile, $source);

View File

@ -6,10 +6,10 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
require_once 'smb4php/smb.php';
namespace OC\Files\Storage; namespace OC\Files\Storage;
require_once 'smb4php/smb.php';
class SMB extends \OC\Files\Storage\StreamWrapper{ class SMB extends \OC\Files\Storage\StreamWrapper{
private $password; private $password;
private $user; private $user;
@ -70,6 +70,7 @@ class SMB extends \OC\Files\Storage\StreamWrapper{
/** /**
* check if a file or folder has been updated since $time * check if a file or folder has been updated since $time
* @param string $path
* @param int $time * @param int $time
* @return bool * @return bool
*/ */

View File

@ -6,10 +6,10 @@
* See the COPYING-README file. * See the COPYING-README file.
*/ */
require_once 'php-cloudfiles/cloudfiles.php';
namespace OC\Files\Storage; namespace OC\Files\Storage;
require_once 'php-cloudfiles/cloudfiles.php';
class SWIFT extends \OC\Files\Storage\Common{ class SWIFT extends \OC\Files\Storage\Common{
private $id; private $id;
private $host; private $host;
@ -18,15 +18,15 @@ class SWIFT extends \OC\Files\Storage\Common{
private $token; private $token;
private $secure; private $secure;
/** /**
* @var CF_Authentication auth * @var \CF_Authentication auth
*/ */
private $auth; private $auth;
/** /**
* @var CF_Connection conn * @var \CF_Connection conn
*/ */
private $conn; private $conn;
/** /**
* @var CF_Container rootContainer * @var \CF_Container rootContainer
*/ */
private $rootContainer; private $rootContainer;
@ -38,7 +38,7 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* translate directory path to container name * translate directory path to container name
* @param string path * @param string $path
* @return string * @return string
*/ */
private function getContainerName($path) { private function getContainerName($path) {
@ -48,8 +48,8 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* get container by path * get container by path
* @param string path * @param string $path
* @return CF_Container * @return \CF_Container
*/ */
private function getContainer($path) { private function getContainer($path) {
if($path=='' or $path=='/') { if($path=='' or $path=='/') {
@ -62,15 +62,15 @@ class SWIFT extends \OC\Files\Storage\Common{
$container=$this->conn->get_container($this->getContainerName($path)); $container=$this->conn->get_container($this->getContainerName($path));
$this->containers[$path]=$container; $this->containers[$path]=$container;
return $container; return $container;
}catch(NoSuchContainerException $e) { }catch(\NoSuchContainerException $e) {
return null; return null;
} }
} }
/** /**
* create container * create container
* @param string path * @param string $path
* @return CF_Container * @return \CF_Container
*/ */
private function createContainer($path) { private function createContainer($path) {
if($path=='' or $path=='/' or $path=='.') { if($path=='' or $path=='/' or $path=='.') {
@ -92,8 +92,8 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* get object by path * get object by path
* @param string path * @param string $path
* @return CF_Object * @return \CF_Object
*/ */
private function getObject($path) { private function getObject($path) {
if(isset($this->objects[$path])) { if(isset($this->objects[$path])) {
@ -110,7 +110,7 @@ class SWIFT extends \OC\Files\Storage\Common{
$obj=$container->get_object(basename($path)); $obj=$container->get_object(basename($path));
$this->objects[$path]=$obj; $this->objects[$path]=$obj;
return $obj; return $obj;
}catch(NoSuchObjectException $e) { }catch(\NoSuchObjectException $e) {
return null; return null;
} }
} }
@ -135,8 +135,8 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* create object * create object
* @param string path * @param string $path
* @return CF_Object * @return \CF_Object
*/ */
private function createObject($path) { private function createObject($path) {
$container=$this->getContainer(dirname($path)); $container=$this->getContainer(dirname($path));
@ -157,7 +157,7 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* check if container for path exists * check if container for path exists
* @param string path * @param string $path
* @return bool * @return bool
*/ */
private function containerExists($path) { private function containerExists($path) {
@ -166,15 +166,15 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* get the list of emulated sub containers * get the list of emulated sub containers
* @param CF_Container container * @param \CF_Container $container
* @return array * @return array
*/ */
private function getSubContainers($container) { private function getSubContainers($container) {
$tmpFile=OCP\Files::tmpFile(); $tmpFile=\OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container); $obj=$this->getSubContainerFile($container);
try{ try{
$obj->save_to_filename($tmpFile); $obj->save_to_filename($tmpFile);
}catch(Exception $e) { }catch(\Exception $e) {
return array(); return array();
} }
$obj->save_to_filename($tmpFile); $obj->save_to_filename($tmpFile);
@ -188,15 +188,15 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* add an emulated sub container * add an emulated sub container
* @param CF_Container container * @param CF_Container $container
* @param string name * @param string $name
* @return bool * @return bool
*/ */
private function addSubContainer($container,$name) { private function addSubContainer($container,$name) {
if(!$name) { if(!$name) {
return false; return false;
} }
$tmpFile=OCP\Files::tmpFile(); $tmpFile=\OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container); $obj=$this->getSubContainerFile($container);
try{ try{
$obj->save_to_filename($tmpFile); $obj->save_to_filename($tmpFile);
@ -211,8 +211,7 @@ class SWIFT extends \OC\Files\Storage\Common{
$fh=fopen($tmpFile,'a'); $fh=fopen($tmpFile,'a');
fwrite($fh,$name."\n"); fwrite($fh,$name."\n");
} }
}catch(Exception $e) { }catch(\Exception $e) {
$containers=array();
file_put_contents($tmpFile,$name."\n"); file_put_contents($tmpFile,$name."\n");
} }
@ -223,20 +222,20 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* remove an emulated sub container * remove an emulated sub container
* @param CF_Container container * @param CF_Container $container
* @param string name * @param string $name
* @return bool * @return bool
*/ */
private function removeSubContainer($container,$name) { private function removeSubContainer($container,$name) {
if(!$name) { if(!$name) {
return false; return false;
} }
$tmpFile=OCP\Files::tmpFile(); $tmpFile=\OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container); $obj=$this->getSubContainerFile($container);
try{ try{
$obj->save_to_filename($tmpFile); $obj->save_to_filename($tmpFile);
$containers=file($tmpFile); $containers=file($tmpFile);
}catch(Exception $e) { }catch(\Exception $e) {
return false; return false;
} }
foreach($containers as &$sub) { foreach($containers as &$sub) {
@ -258,13 +257,13 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* ensure a subcontainer file exists and return it's object * ensure a subcontainer file exists and return it's object
* @param CF_Container container * @param \CF_Container $container
* @return CF_Object * @return \CF_Object
*/ */
private function getSubContainerFile($container) { private function getSubContainerFile($container) {
try{ try{
return $container->get_object(self::SUBCONTAINER_FILE); return $container->get_object(self::SUBCONTAINER_FILE);
}catch(NoSuchObjectException $e) { }catch(\NoSuchObjectException $e) {
return $container->create_object(self::SUBCONTAINER_FILE); return $container->create_object(self::SUBCONTAINER_FILE);
} }
} }
@ -526,11 +525,11 @@ class SWIFT extends \OC\Files\Storage\Common{
private function getTmpFile($path) { private function getTmpFile($path) {
$obj=$this->getObject($path); $obj=$this->getObject($path);
if(!is_null($obj)) { if(!is_null($obj)) {
$tmpFile=OCP\Files::tmpFile(); $tmpFile=\OCP\Files::tmpFile();
$obj->save_to_filename($tmpFile); $obj->save_to_filename($tmpFile);
return $tmpFile; return $tmpFile;
}else{ }else{
return OCP\Files::tmpFile(); return \OCP\Files::tmpFile();
} }
} }
@ -545,7 +544,7 @@ class SWIFT extends \OC\Files\Storage\Common{
/** /**
* remove custom mtime metadata * remove custom mtime metadata
* @param CF_Object obj * @param \CF_Object $obj
*/ */
private function resetMTime($obj) { private function resetMTime($obj) {
if(isset($obj->metadata['Mtime'])) { if(isset($obj->metadata['Mtime'])) {

View File

@ -15,7 +15,7 @@ class DAV extends \OC\Files\Storage\Common{
private $secure; private $secure;
private $root; private $root;
/** /**
* @var Sabre_DAV_Client * @var \Sabre_DAV_Client
*/ */
private $client; private $client;
@ -92,7 +92,7 @@ class DAV extends \OC\Files\Storage\Common{
\OC_FakeDirStream::$dirs[$id][]=$file; \OC_FakeDirStream::$dirs[$id][]=$file;
} }
return opendir('fakedir://'.$id); return opendir('fakedir://'.$id);
}catch(Exception $e) { }catch(\Exception $e) {
return false; return false;
} }
} }
@ -103,7 +103,7 @@ class DAV extends \OC\Files\Storage\Common{
$response=$this->client->propfind($path, array('{DAV:}resourcetype')); $response=$this->client->propfind($path, array('{DAV:}resourcetype'));
$responseType=$response["{DAV:}resourcetype"]->resourceType; $responseType=$response["{DAV:}resourcetype"]->resourceType;
return (count($responseType)>0 and $responseType[0]=="{DAV:}collection")?'dir':'file'; return (count($responseType)>0 and $responseType[0]=="{DAV:}collection")?'dir':'file';
}catch(Exception $e) { }catch(\Exception $e) {
error_log($e->getMessage()); error_log($e->getMessage());
\OCP\Util::writeLog("webdav client", \OCP\Util::sanitizeHTML($e->getMessage()), \OCP\Util::ERROR); \OCP\Util::writeLog("webdav client", \OCP\Util::sanitizeHTML($e->getMessage()), \OCP\Util::ERROR);
return false; return false;
@ -123,7 +123,7 @@ class DAV extends \OC\Files\Storage\Common{
try{ try{
$this->client->propfind($path, array('{DAV:}resourcetype')); $this->client->propfind($path, array('{DAV:}resourcetype'));
return true;//no 404 exception return true;//no 404 exception
}catch(Exception $e) { }catch(\Exception $e) {
return false; return false;
} }
} }
@ -169,7 +169,7 @@ class DAV extends \OC\Files\Storage\Common{
}else{ }else{
$ext=''; $ext='';
} }
$tmpFile=OCP\Files::tmpFile($ext); $tmpFile=\OCP\Files::tmpFile($ext);
\OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack'); \OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
if($this->file_exists($path)) { if($this->file_exists($path)) {
$this->getFile($path,$tmpFile); $this->getFile($path,$tmpFile);
@ -195,7 +195,7 @@ class DAV extends \OC\Files\Storage\Common{
}else{ }else{
return 0; return 0;
} }
}catch(Exception $e) { }catch(\Exception $e) {
return 0; return 0;
} }
} }
@ -231,12 +231,9 @@ class DAV extends \OC\Files\Storage\Common{
$path1=$this->cleanPath($path1); $path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2); $path2=$this->root.$this->cleanPath($path2);
try{ try{
$response=$this->client->request('MOVE',$path1,null,array('Destination'=>$path2)); $this->client->request('MOVE',$path1,null,array('Destination'=>$path2));
return true; return true;
}catch(Exception $e) { }catch(\Exception $e) {
echo $e;
echo 'fail';
var_dump($response);
return false; return false;
} }
} }
@ -245,12 +242,9 @@ class DAV extends \OC\Files\Storage\Common{
$path1=$this->cleanPath($path1); $path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2); $path2=$this->root.$this->cleanPath($path2);
try{ try{
$response=$this->client->request('COPY',$path1,null,array('Destination'=>$path2)); $this->client->request('COPY',$path1,null,array('Destination'=>$path2));
return true; return true;
}catch(Exception $e) { }catch(\Exception $e) {
echo $e;
echo 'fail';
var_dump($response);
return false; return false;
} }
} }
@ -264,7 +258,7 @@ class DAV extends \OC\Files\Storage\Common{
'size'=>(int)isset($response['{DAV:}getcontentlength']) ? $response['{DAV:}getcontentlength'] : 0, 'size'=>(int)isset($response['{DAV:}getcontentlength']) ? $response['{DAV:}getcontentlength'] : 0,
'ctime'=>-1, 'ctime'=>-1,
); );
}catch(Exception $e) { }catch(\Exception $e) {
return array(); return array();
} }
} }
@ -282,7 +276,7 @@ class DAV extends \OC\Files\Storage\Common{
}else{ }else{
return false; return false;
} }
}catch(Exception $e) { }catch(\Exception $e) {
return false; return false;
} }
} }
@ -300,7 +294,7 @@ class DAV extends \OC\Files\Storage\Common{
try{ try{
$response=$this->client->request($method,$path,$body); $response=$this->client->request($method,$path,$body);
return $response['statusCode']==$expected; return $response['statusCode']==$expected;
}catch(Exception $e) { }catch(\Exception $e) {
return false; return false;
} }
} }

View File

@ -8,7 +8,7 @@ return array(
'root'=>'/test', 'root'=>'/test',
), ),
'webdav'=>array( 'webdav'=>array(
'run'=>false, 'run'=>true,
'host'=>'localhost', 'host'=>'localhost',
'user'=>'test', 'user'=>'test',
'password'=>'test', 'password'=>'test',