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/>.
*/
require_once 'aws-sdk/sdk.class.php';
namespace OC\Files\Storage;
require_once 'aws-sdk/sdk.class.php';
class AmazonS3 extends \OC\Files\Storage\Common {
private $s3;

View File

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

View File

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

View File

@ -20,10 +20,10 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
require_once 'Google/common.inc.php';
namespace OC\Files\Storage;
require_once 'Google/common.inc.php';
class Google extends \OC\Files\Storage\Common {
private $consumer;
@ -62,7 +62,7 @@ class Google extends \OC\Files\Storage\Common {
$tempStr .= '&' . urlencode($key) . '=' . urlencode($value);
}
$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);
$auth_header = $request->to_header();
$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) {
$result = $this->sendRequest($feedUri, $httpMethod, $postData);
if ($result) {
$dom = new DOMDocument();
$dom = new \DOMDocument();
$dom->loadXML($result);
return $dom;
}
@ -248,7 +248,7 @@ class Google extends \OC\Files\Storage\Common {
$this->entries[$name] = $entry;
}
}
OC_FakeDirStream::$dirs['google'.$path] = $files;
\OC_FakeDirStream::$dirs['google'.$path] = $files;
return opendir('fakedir://google'.$path);
}
@ -407,7 +407,7 @@ class Google extends \OC\Files\Storage\Common {
$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)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);

View File

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

View File

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

View File

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

View File

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