diff options
Diffstat (limited to 'apps/files_external')
-rw-r--r-- | apps/files_external/lib/amazons3.php | 3 | ||||
-rwxr-xr-x | apps/files_external/lib/config.php | 21 | ||||
-rwxr-xr-x | apps/files_external/lib/dropbox.php | 5 | ||||
-rw-r--r-- | apps/files_external/lib/google.php | 7 | ||||
-rw-r--r-- | apps/files_external/lib/irods.php | 1 | ||||
-rw-r--r-- | apps/files_external/lib/sftp.php | 6 | ||||
-rw-r--r-- | apps/files_external/lib/streamwrapper.php | 12 | ||||
-rw-r--r-- | apps/files_external/lib/swift.php | 6 | ||||
-rw-r--r-- | apps/files_external/lib/webdav.php | 75 | ||||
-rw-r--r-- | apps/files_external/tests/config.php | 6 | ||||
-rw-r--r-- | apps/files_external/tests/webdav.php | 3 |
11 files changed, 114 insertions, 31 deletions
diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index 00baacd488c..06ccd5d16fa 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -54,6 +54,9 @@ class AmazonS3 extends \OC\Files\Storage\Common { */ private $timeout = 15; + /** + * @param string $path + */ private function normalizePath($path) { $path = trim($path, '/'); diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 3118e1ac68d..b2109e5eacd 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -35,7 +35,7 @@ class OC_Mount_Config { * If the configuration parameter is a boolean, add a '!' to the beginning of the value * If the configuration parameter is optional, add a '&' to the beginning of the value * If the configuration parameter is hidden, add a '#' to the beginning of the value - * @return array + * @return string */ public static function getBackends() { @@ -61,7 +61,7 @@ class OC_Mount_Config { 'configuration' => array( 'configured' => '#configured', 'app_key' => 'App key', - 'app_secret' => 'App secret', + 'app_secret' => '*App secret', 'token' => '#token', 'token_secret' => '#token_secret'), 'custom' => 'dropbox'); @@ -69,7 +69,7 @@ class OC_Mount_Config { if(OC_Mount_Config::checkphpftp()) $backends['\OC\Files\Storage\FTP']=array( 'backend' => 'FTP', 'configuration' => array( - 'host' => 'URL', + 'host' => 'Hostname', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', @@ -80,7 +80,7 @@ class OC_Mount_Config { 'configuration' => array( 'configured' => '#configured', 'client_id' => 'Client ID', - 'client_secret' => 'Client secret', + 'client_secret' => '*Client secret', 'token' => '#token'), 'custom' => 'google'); @@ -263,13 +263,13 @@ class OC_Mount_Config { /** * Add a mount point to the filesystem - * @param string Mount point - * @param string Backend class + * @param string $mountPoint Mount point + * @param string $class Backend class * @param array Backend parameters for the class - * @param string MOUNT_TYPE_GROUP | MOUNT_TYPE_USER - * @param string User or group to apply mount to + * @param string $mountType MOUNT_TYPE_GROUP | MOUNT_TYPE_USER + * @param string $applicable User or group to apply mount to * @param bool Personal or system mount point i.e. is this being called from the personal or admin page - * @return bool + * @return boolean */ public static function addMountPoint($mountPoint, $class, @@ -343,7 +343,7 @@ class OC_Mount_Config { /** * Read the mount points in the config file into an array - * @param bool Personal or system config file + * @param boolean $isPersonal Personal or system config file * @return array */ private static function readData($isPersonal) { @@ -373,6 +373,7 @@ class OC_Mount_Config { * Write the mount points to the config file * @param bool Personal or system config file * @param array Mount points + * @param boolean $isPersonal */ private static function writeData($isPersonal, $data) { if ($isPersonal) { diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php index f7d8d98cf03..0214e18020c 100755 --- a/apps/files_external/lib/dropbox.php +++ b/apps/files_external/lib/dropbox.php @@ -50,6 +50,9 @@ class Dropbox extends \OC\Files\Storage\Common { } } + /** + * @param string $path + */ private function deleteMetaData($path) { $path = $this->root.$path; if (isset($this->metaData[$path])) { @@ -61,7 +64,7 @@ class Dropbox extends \OC\Files\Storage\Common { /** * @brief Returns the path's metadata - * @param $path path for which to return the metadata + * @param string $path path for which to return the metadata * @param $list if true, also return the directory's contents * @return directory contents if $list is true, file metadata if $list is * false, null if the file doesn't exist or "false" if the operation failed diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index 426caf008ec..35457f68528 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -67,7 +67,7 @@ class Google extends \OC\Files\Storage\Common { /** * Get the Google_DriveFile object for the specified path * @param string $path - * @return Google_DriveFile + * @return string */ private function getDriveFile($path) { // Remove leading and trailing slashes @@ -524,6 +524,7 @@ class Google extends \OC\Files\Storage\Common { } public function hasUpdated($path, $time) { + $appConfig = \OC::$server->getAppConfig(); if ($this->is_file($path)) { return parent::hasUpdated($path, $time); } else { @@ -533,7 +534,7 @@ class Google extends \OC\Files\Storage\Common { if ($folder) { $result = false; $folderId = $folder->getId(); - $startChangeId = \OC_Appconfig::getValue('files_external', $this->getId().'cId'); + $startChangeId = $appConfig->getValue('files_external', $this->getId().'cId'); $params = array( 'includeDeleted' => true, 'includeSubscribed' => true, @@ -578,7 +579,7 @@ class Google extends \OC\Files\Storage\Common { break; } } - \OC_Appconfig::setValue('files_external', $this->getId().'cId', $largestChangeId); + $appConfig->setValue('files_external', $this->getId().'cId', $largestChangeId); return $result; } } diff --git a/apps/files_external/lib/irods.php b/apps/files_external/lib/irods.php index 6d4f66e856e..7a7e900fbf0 100644 --- a/apps/files_external/lib/irods.php +++ b/apps/files_external/lib/irods.php @@ -134,6 +134,7 @@ class iRODS extends \OC\Files\Storage\StreamWrapper{ /** * get the best guess for the modification time of an iRODS collection + * @param string $path */ private function collectionMTime($path) { $dh = $this->opendir($path); diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php index cd8a0e78864..a0816e2870d 100644 --- a/apps/files_external/lib/sftp.php +++ b/apps/files_external/lib/sftp.php @@ -75,6 +75,9 @@ class SFTP extends \OC\Files\Storage\Common { return 'sftp::' . $this->user . '@' . $this->host . '/' . $this->root; } + /** + * @param string $path + */ private function absPath($path) { return $this->root . $this->cleanPath($path); } @@ -277,6 +280,9 @@ class SFTP extends \OC\Files\Storage\Common { } } + /** + * @param string $path + */ public function constructUrl($path) { $url = 'sftp://'.$this->user.':'.$this->password.'@'.$this->host.$this->root.$path; return $url; diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php index e484325e2fb..44bd9a0161a 100644 --- a/apps/files_external/lib/streamwrapper.php +++ b/apps/files_external/lib/streamwrapper.php @@ -9,6 +9,11 @@ namespace OC\Files\Storage; abstract class StreamWrapper extends Common { + + /** + * @param string $path + * @return string|null + */ abstract public function constructUrl($path); public function mkdir($path) { @@ -76,10 +81,17 @@ abstract class StreamWrapper extends Common { } } + /** + * @param string $path + * @param string $target + */ public function getFile($path, $target) { return copy($this->constructUrl($path), $target); } + /** + * @param string $target + */ public function uploadFile($path, $target) { return copy($path, $this->constructUrl($target)); } diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index b615d24ce76..7a56fcfc8b7 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -52,6 +52,9 @@ class Swift extends \OC\Files\Storage\Common { */ private static $tmpFiles = array(); + /** + * @param string $path + */ private function normalizePath($path) { $path = trim($path, '/'); @@ -62,6 +65,9 @@ class Swift extends \OC\Files\Storage\Common { return $path; } + /** + * @param string $path + */ private function doesObjectExist($path) { try { $object = $this->container->DataObject($path); diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index f6f4cb16e87..9afe73aebd7 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -99,7 +99,9 @@ class DAV extends \OC\Files\Storage\Common{ public function rmdir($path) { $this->init(); - $path=$this->cleanPath($path); + $path=$this->cleanPath($path) . '/'; + // FIXME: some WebDAV impl return 403 when trying to DELETE + // a non-empty folder return $this->simpleResponse('DELETE', $path, null, 204); } @@ -107,7 +109,7 @@ class DAV extends \OC\Files\Storage\Common{ $this->init(); $path=$this->cleanPath($path); try { - $response=$this->client->propfind($path, array(), 1); + $response=$this->client->propfind($this->encodePath($path), array(), 1); $id=md5('webdav'.$this->root.$path); $content = array(); $files=array_keys($response); @@ -127,8 +129,11 @@ class DAV extends \OC\Files\Storage\Common{ $this->init(); $path=$this->cleanPath($path); try { - $response=$this->client->propfind($path, array('{DAV:}resourcetype')); - $responseType=$response["{DAV:}resourcetype"]->resourceType; + $response=$this->client->propfind($this->encodePath($path), array('{DAV:}resourcetype')); + $responseType = array(); + if (isset($response["{DAV:}resourcetype"])) { + $responseType=$response["{DAV:}resourcetype"]->resourceType; + } return (count($responseType)>0 and $responseType[0]=="{DAV:}collection")?'dir':'file'; } catch(\Exception $e) { error_log($e->getMessage()); @@ -141,7 +146,7 @@ class DAV extends \OC\Files\Storage\Common{ $this->init(); $path=$this->cleanPath($path); try { - $this->client->propfind($path, array('{DAV:}resourcetype')); + $this->client->propfind($this->encodePath($path), array('{DAV:}resourcetype')); return true;//no 404 exception } catch(\Exception $e) { return false; @@ -166,7 +171,7 @@ class DAV extends \OC\Files\Storage\Common{ $curl = curl_init(); $fp = fopen('php://temp', 'r+'); curl_setopt($curl, CURLOPT_USERPWD, $this->user.':'.$this->password); - curl_setopt($curl, CURLOPT_URL, $this->createBaseUri().str_replace(' ', '%20', $path)); + curl_setopt($curl, CURLOPT_URL, $this->createBaseUri().$this->encodePath($path)); curl_setopt($curl, CURLOPT_FILE, $fp); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); if ($this->secure === true) { @@ -178,6 +183,10 @@ class DAV extends \OC\Files\Storage\Common{ } curl_exec ($curl); + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + if ($statusCode !== 200) { + \OCP\Util::writeLog("webdav client", 'curl GET ' . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL) . ' returned status code ' . $statusCode, \OCP\Util::ERROR); + } curl_close ($curl); rewind($fp); return $fp; @@ -220,7 +229,7 @@ class DAV extends \OC\Files\Storage\Common{ $this->init(); $path=$this->cleanPath($path); try { - $response=$this->client->propfind($path, array('{DAV:}quota-available-bytes')); + $response=$this->client->propfind($this->encodePath($path), array('{DAV:}quota-available-bytes')); if (isset($response['{DAV:}quota-available-bytes'])) { return (int)$response['{DAV:}quota-available-bytes']; } else { @@ -240,13 +249,22 @@ class DAV extends \OC\Files\Storage\Common{ // if file exists, update the mtime, else create a new empty file if ($this->file_exists($path)) { - $this->client->proppatch($path, array('{DAV:}lastmodified' => $mtime)); + try { + $this->client->proppatch($this->encodePath($path), array('{DAV:}lastmodified' => $mtime)); + } + catch (\Sabre_DAV_Exception_NotImplemented $e) { + return false; + } } else { $this->file_put_contents($path, ''); } return true; } + /** + * @param string $path + * @param string $target + */ public function getFile($path, $target) { $this->init(); $source=$this->fopen($path, 'r'); @@ -272,13 +290,17 @@ class DAV extends \OC\Files\Storage\Common{ } } curl_exec ($curl); + $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + if ($statusCode !== 200) { + \OCP\Util::writeLog("webdav client", 'curl GET ' . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL) . ' returned status code ' . $statusCode, \OCP\Util::ERROR); + } curl_close ($curl); } public function rename($path1, $path2) { $this->init(); - $path1=$this->cleanPath($path1); - $path2=$this->createBaseUri().$this->cleanPath($path2); + $path1 = $this->encodePath($this->cleanPath($path1)); + $path2 = $this->createBaseUri().$this->encodePath($this->cleanPath($path2)); try { $this->client->request('MOVE', $path1, null, array('Destination'=>$path2)); return true; @@ -289,8 +311,8 @@ class DAV extends \OC\Files\Storage\Common{ public function copy($path1, $path2) { $this->init(); - $path1=$this->cleanPath($path1); - $path2=$this->createBaseUri().$this->cleanPath($path2); + $path1 = $this->encodePath($this->cleanPath($path1)); + $path2 = $this->createBaseUri().$this->encodePath($this->cleanPath($path2)); try { $this->client->request('COPY', $path1, null, array('Destination'=>$path2)); return true; @@ -303,7 +325,7 @@ class DAV extends \OC\Files\Storage\Common{ $this->init(); $path=$this->cleanPath($path); try { - $response=$this->client->propfind($path, array('{DAV:}getlastmodified', '{DAV:}getcontentlength')); + $response = $this->client->propfind($this->encodePath($path), array('{DAV:}getlastmodified', '{DAV:}getcontentlength')); return array( 'mtime'=>strtotime($response['{DAV:}getlastmodified']), 'size'=>(int)isset($response['{DAV:}getcontentlength']) ? $response['{DAV:}getcontentlength'] : 0, @@ -317,8 +339,11 @@ class DAV extends \OC\Files\Storage\Common{ $this->init(); $path=$this->cleanPath($path); try { - $response=$this->client->propfind($path, array('{DAV:}getcontenttype', '{DAV:}resourcetype')); - $responseType=$response["{DAV:}resourcetype"]->resourceType; + $response=$this->client->propfind($this->encodePath($path), array('{DAV:}getcontenttype', '{DAV:}resourcetype')); + $responseType = array(); + if (isset($response["{DAV:}resourcetype"])) { + $responseType=$response["{DAV:}resourcetype"]->resourceType; + } $type=(count($responseType)>0 and $responseType[0]=="{DAV:}collection")?'dir':'file'; if ($type=='dir') { return 'httpd/unix-directory'; @@ -332,16 +357,34 @@ class DAV extends \OC\Files\Storage\Common{ } } + /** + * @param string $path + */ public function cleanPath($path) { $path = \OC\Files\Filesystem::normalizePath($path); // remove leading slash return substr($path, 1); } + /** + * URL encodes the given path but keeps the slashes + * @param string $path to encode + * @return string encoded path + */ + private function encodePath($path) { + // slashes need to stay + return str_replace('%2F', '/', rawurlencode($path)); + } + + /** + * @param string $method + * @param string $path + * @param integer $expected + */ private function simpleResponse($method, $path, $body, $expected) { $path=$this->cleanPath($path); try { - $response=$this->client->request($method, $path, $body); + $response=$this->client->request($method, $this->encodePath($path), $body); return $response['statusCode']==$expected; } catch(\Exception $e) { return false; diff --git a/apps/files_external/tests/config.php b/apps/files_external/tests/config.php index e296bfcb5b2..767c0adf58e 100644 --- a/apps/files_external/tests/config.php +++ b/apps/files_external/tests/config.php @@ -21,7 +21,11 @@ return array( 'host'=>'localhost', 'user'=>'test', 'password'=>'test', - 'root'=>'/owncloud/files/webdav.php', + 'root'=>'', + // wait delay in seconds after write operations + // (only in tests) + // set to higher value for lighttpd webdav + 'wait'=> 0 ), 'owncloud'=>array( 'run'=>true, diff --git a/apps/files_external/tests/webdav.php b/apps/files_external/tests/webdav.php index 1f9b767eca6..74e905ccc89 100644 --- a/apps/files_external/tests/webdav.php +++ b/apps/files_external/tests/webdav.php @@ -18,6 +18,9 @@ class DAV extends Storage { if ( ! is_array($this->config) or ! isset($this->config['webdav']) or ! $this->config['webdav']['run']) { $this->markTestSkipped('WebDAV backend not configured'); } + if (isset($this->config['webdav']['wait'])) { + $this->waitDelay = $this->config['webdav']['wait']; + } $this->config['webdav']['root'] .= '/' . $id; //make sure we have an new empty folder to work in $this->instance = new \OC\Files\Storage\DAV($this->config['webdav']); $this->instance->mkdir('/'); |