From ad902a9848a66135ae85a04b1c66b663219a53ea Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Fri, 28 Dec 2012 12:00:48 -0500 Subject: [PATCH] Move storage backend tests from constructor to test function --- apps/files_external/lib/amazons3.php | 12 ++++++++---- apps/files_external/lib/config.php | 4 ++-- apps/files_external/lib/dropbox.php | 4 ---- apps/files_external/lib/ftp.php | 4 ---- apps/files_external/lib/google.php | 11 +++++++---- apps/files_external/lib/smb.php | 4 ---- apps/files_external/lib/webdav.php | 4 ---- lib/filestorage.php | 1 + lib/filestorage/common.php | 8 ++++++++ 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index c1b2e889bb..5ab89df732 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -36,10 +36,6 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { if (isset($params['key']) && isset($params['secret']) && isset($params['bucket'])) { $this->s3 = new AmazonS3(array('key' => $params['key'], 'secret' => $params['secret'])); $this->bucket = $params['bucket']; - $test = $this->s3->get_canonical_user_id(); - if (!isset($test['id']) || $test['id'] == '') { - throw new Exception(); - } } else { throw new Exception(); } @@ -250,4 +246,12 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { return $response->isOK(); } + public function test() { + $test = $this->s3->get_canonical_user_id(); + if (isset($test['id']) && $test['id'] != '') { + return true; + } + return false; + } + } diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 99d31c5aa2..fd654f04e9 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -192,8 +192,8 @@ class OC_Mount_Config { } if (class_exists($class)) { try { - new $class($options); - return true; + $storage = new $class($options); + return $storage->test(); } catch (Exception $exception) { return false; } diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php index a4f3f67834..66dfd3e595 100755 --- a/apps/files_external/lib/dropbox.php +++ b/apps/files_external/lib/dropbox.php @@ -41,10 +41,6 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { $oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']); $oauth->setToken($params['token'], $params['token_secret']); $this->dropbox = new Dropbox_API($oauth, 'dropbox'); - $test = $this->stat(''); - if (!$test) { - throw new Exception('Creating OC_Filestorage_Dropbox storage failed'); - } } else { throw new Exception('Creating OC_Filestorage_Dropbox storage failed'); } diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index ac487156c1..ca408d5d22 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -33,10 +33,6 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ if ( ! $this->root || $this->root[0]!='/') { $this->root='/'.$this->root; } - $test = $this->stat(''); - if (!$test) { - throw new Exception(); - } //create the root folder if necesary if ( ! $this->is_dir('')) { $this->mkdir(''); diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index 19772d4d37..8710c97911 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -42,10 +42,6 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { $this->oauth_token = new OAuthToken($params['token'], $params['token_secret']); $this->sig_method = new OAuthSignatureMethod_HMAC_SHA1(); $this->entries = array(); - $test = $this->free_space(''); - if (!$test) { - throw new Exception(); - } } else { throw new Exception('Creating OC_Filestorage_Google storage failed'); } @@ -594,4 +590,11 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { } + public function test() { + if ($this->free_space('')) { + return true; + } + return false; + } + } \ No newline at end of file diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index 97454b4601..5b73e993e4 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -34,10 +34,6 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ if (substr($this->share, -1, 1)=='/') { $this->share=substr($this->share, 0, -1); } - $test = $this->stat(''); - if (!$test) { - throw new Exception(); - } //create the root folder if necesary if ( ! $this->is_dir('')) { $this->mkdir(''); diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index cfe073a1f1..31d36f1e78 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -60,10 +60,6 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ $this->client->addTrustedCertificates($certPath); } } - $test = $this->stat(''); - if (!$test) { - throw new Exception(); - } //create the root folder if necesary $this->mkdir(''); } else { diff --git a/lib/filestorage.php b/lib/filestorage.php index dd65f4421b..9d42c0bcb6 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -64,4 +64,5 @@ abstract class OC_Filestorage{ */ abstract public function hasUpdated($path, $time); abstract public function getOwner($path); + abstract public function test(); } diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index b97eb79d8d..e2af0c6d7f 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -288,4 +288,12 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { public function getOwner($path) { return OC_User::getUser(); } + + public function test() { + if ($this->stat('')) { + return true; + } + return false; + } + }