diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 6fdb43d564f0..09982bf3877d 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -43,7 +43,7 @@ use Aws\S3\Exception\S3Exception; use Icewind\Streams\IteratorDirectory; -class AmazonS3 extends \OC\Files\Storage\Common { +class AmazonS3 extends \OCP\Files\Storage\StorageAdapter { /** * @var \Aws\S3\S3Client diff --git a/apps/files_external/lib/Lib/Storage/Dropbox.php b/apps/files_external/lib/Lib/Storage/Dropbox.php index 5da8d88b005b..1d032b9cbec5 100644 --- a/apps/files_external/lib/Lib/Storage/Dropbox.php +++ b/apps/files_external/lib/Lib/Storage/Dropbox.php @@ -36,7 +36,7 @@ require_once __DIR__ . '/../../../3rdparty/Dropbox/autoload.php'; -class Dropbox extends \OC\Files\Storage\Common { +class Dropbox extends \OCP\Files\Storage\StorageAdapter { private $dropbox; private $root; diff --git a/apps/files_external/lib/Lib/Storage/Google.php b/apps/files_external/lib/Lib/Storage/Google.php index 7907bf60fae7..37f28b2e3bd3 100644 --- a/apps/files_external/lib/Lib/Storage/Google.php +++ b/apps/files_external/lib/Lib/Storage/Google.php @@ -42,7 +42,7 @@ \OC_App::getAppPath('files_external').'/3rdparty/google-api-php-client/src'); require_once 'Google/autoload.php'; -class Google extends \OC\Files\Storage\Common { +class Google extends \OCP\Files\Storage\StorageAdapter { private $client; private $id; diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php index b8c339893689..2dfc3d5c5f2d 100644 --- a/apps/files_external/lib/Lib/Storage/SFTP.php +++ b/apps/files_external/lib/Lib/Storage/SFTP.php @@ -40,7 +40,7 @@ * Uses phpseclib's Net\SFTP class and the Net\SFTP\Stream stream wrapper to * provide access to SFTP servers. */ -class SFTP extends \OC\Files\Storage\Common { +class SFTP extends \OCP\Files\Storage\StorageAdapter { private $host; private $user; private $root; diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index 19d5b499e284..49ac8c86ed60 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -43,11 +43,10 @@ use Icewind\Streams\IteratorDirectory; use OC\Cache\CappedMemoryCache; use OC\Files\Filesystem; -use OC\Files\Storage\Common; use OCP\Files\StorageNotAvailableException; use OCP\Util; -class SMB extends Common { +class SMB extends \OCP\Files\Storage\StorageAdapter { /** * @var \Icewind\SMB\Server */ diff --git a/apps/files_external/lib/Lib/Storage/StreamWrapper.php b/apps/files_external/lib/Lib/Storage/StreamWrapper.php index 910c85247965..ffd4a8fd3afb 100644 --- a/apps/files_external/lib/Lib/Storage/StreamWrapper.php +++ b/apps/files_external/lib/Lib/Storage/StreamWrapper.php @@ -27,7 +27,7 @@ namespace OCA\Files_External\Lib\Storage; -abstract class StreamWrapper extends \OC\Files\Storage\Common { +abstract class StreamWrapper extends \OCP\Files\Storage\StorageAdapter { /** * @param string $path diff --git a/apps/files_external/lib/Lib/Storage/Swift.php b/apps/files_external/lib/Lib/Storage/Swift.php index 35da3b13618b..2924d8bda7c6 100644 --- a/apps/files_external/lib/Lib/Storage/Swift.php +++ b/apps/files_external/lib/Lib/Storage/Swift.php @@ -44,7 +44,7 @@ use OpenCloud\ObjectStore\Resource\DataObject; use OpenCloud\ObjectStore\Exception; -class Swift extends \OC\Files\Storage\Common { +class Swift extends \OCP\Files\Storage\StorageAdapter { /** * @var \OpenCloud\ObjectStore\Service diff --git a/lib/public/Files/Storage/FlysystemStorageAdapter.php b/lib/public/Files/Storage/FlysystemStorageAdapter.php new file mode 100644 index 000000000000..1b82682d24f5 --- /dev/null +++ b/lib/public/Files/Storage/FlysystemStorageAdapter.php @@ -0,0 +1,41 @@ + + * + * @copyright Copyright (c) 2016, ownCloud GmbH. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCP\Files\Storage; + +/** + * Public storage adapter to be extended to connect to + * flysystem adapters + * + * @since 9.2 + */ +abstract class FlysystemStorageAdapter extends \OC\Files\Storage\Flysystem { + + /** + * Get the identifier for the storage, + * the returned id should be the same for every storage object that is created with the same parameters + * and two storage objects with the same id should refer to two storages that display the same files. + * + * @return string storage id + * @since 9.2 + */ + abstract public function getId(); +} diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index e2272c48fe14..8311f051fab5 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -34,6 +34,7 @@ use OCP\Files\Cache\IUpdater; use OCP\Files\Cache\IWatcher; use OCP\Files\InvalidPathException; +use OCP\Files\StorageNotAvailableException; /** * Provide a common interface to all different storage options @@ -56,7 +57,7 @@ public function __construct($parameters); * the returned id should be the same for every storage object that is created with the same parameters * and two storage objects with the same id should refer to two storages that display the same files. * - * @return string + * @return string storage id * @since 9.0.0 */ public function getId(); @@ -66,7 +67,8 @@ public function getId(); * implementations need to implement a recursive mkdir * * @param string $path - * @return bool + * @return bool true on success, false otherwise + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function mkdir($path); @@ -75,7 +77,8 @@ public function mkdir($path); * see http://php.net/manual/en/function.rmdir.php * * @param string $path - * @return bool + * @return bool true on success, false otherwise + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function rmdir($path); @@ -85,6 +88,7 @@ public function rmdir($path); * * @param string $path * @return resource|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function opendir($path); @@ -94,6 +98,7 @@ public function opendir($path); * * @param string $path * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function is_dir($path); @@ -103,6 +108,7 @@ public function is_dir($path); * * @param string $path * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function is_file($path); @@ -113,6 +119,7 @@ public function is_file($path); * * @param string $path * @return array|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function stat($path); @@ -122,6 +129,7 @@ public function stat($path); * * @param string $path * @return string|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function filetype($path); @@ -132,6 +140,7 @@ public function filetype($path); * * @param string $path * @return int|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function filesize($path); @@ -141,6 +150,7 @@ public function filesize($path); * * @param string $path * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function isCreatable($path); @@ -150,6 +160,7 @@ public function isCreatable($path); * * @param string $path * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function isReadable($path); @@ -159,6 +170,7 @@ public function isReadable($path); * * @param string $path * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function isUpdatable($path); @@ -168,6 +180,7 @@ public function isUpdatable($path); * * @param string $path * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function isDeletable($path); @@ -177,6 +190,7 @@ public function isDeletable($path); * * @param string $path * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function isSharable($path); @@ -187,6 +201,7 @@ public function isSharable($path); * * @param string $path * @return int + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getPermissions($path); @@ -196,6 +211,7 @@ public function getPermissions($path); * * @param string $path * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function file_exists($path); @@ -205,6 +221,7 @@ public function file_exists($path); * * @param string $path * @return int|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function filemtime($path); @@ -214,6 +231,7 @@ public function filemtime($path); * * @param string $path * @return string|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function file_get_contents($path); @@ -224,6 +242,7 @@ public function file_get_contents($path); * @param string $path * @param string $data * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function file_put_contents($path, $data); @@ -232,7 +251,8 @@ public function file_put_contents($path, $data); * see http://php.net/manual/en/function.unlink.php * * @param string $path - * @return bool + * @return bool true on success, false otherwise + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function unlink($path); @@ -243,6 +263,7 @@ public function unlink($path); * @param string $path1 * @param string $path2 * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function rename($path1, $path2); @@ -253,6 +274,7 @@ public function rename($path1, $path2); * @param string $path1 * @param string $path2 * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function copy($path1, $path2); @@ -263,6 +285,7 @@ public function copy($path1, $path2); * @param string $path * @param string $mode * @return resource|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function fopen($path, $mode); @@ -273,6 +296,7 @@ public function fopen($path, $mode); * * @param string $path * @return string|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getMimeType($path); @@ -284,6 +308,7 @@ public function getMimeType($path); * @param string $path * @param bool $raw * @return string|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function hash($type, $path, $raw = false); @@ -293,6 +318,7 @@ public function hash($type, $path, $raw = false); * * @param string $path * @return int|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function free_space($path); @@ -303,7 +329,8 @@ public function free_space($path); * * @param string $path * @param int $mtime - * @return bool + * @return bool true on success, false otherwise + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function touch($path, $mtime = null); @@ -314,6 +341,7 @@ public function touch($path, $mtime = null); * * @param string $path * @return string|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getLocalFile($path); @@ -324,6 +352,7 @@ public function getLocalFile($path); * @param string $path * @param int $time * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 * * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. @@ -336,6 +365,7 @@ public function hasUpdated($path, $time); * * @param string $path * @return string|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getETag($path); @@ -368,6 +398,7 @@ public function instanceOfStorage($class); * * @param string $path * @return array|false + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getDirectDownload($path); @@ -386,6 +417,7 @@ public function verifyPath($path, $fileName); * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); @@ -395,6 +427,7 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); @@ -408,49 +441,72 @@ public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern public function test(); /** + * Returns the availability info + * * @since 9.0.0 * @return array [ available, last_checked ] */ public function getAvailability(); /** + * Sets availability flag + * * @since 9.0.0 * @param bool $isAvailable */ public function setAvailability($isAvailable); /** + * Returns the owner name + * * @param string $path path for which to retrieve the owner + * @return string owner name + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getOwner($path); /** + * Returns the storage cache instance + * * @return ICache + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getCache(); /** + * Returns the change propagator instance + * * @return IPropagator + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getPropagator(); /** + * Returns the scanner instance + * * @return IScanner + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getScanner(); /** + * Returns the updater instance + * * @return IUpdater + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getUpdater(); /** + * Returns the watched instance + * * @return IWatcher + * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ public function getWatcher(); diff --git a/lib/public/Files/Storage/PolyFill/CopyDirectory.php b/lib/public/Files/Storage/PolyFill/CopyDirectory.php new file mode 100644 index 000000000000..994f48c13a95 --- /dev/null +++ b/lib/public/Files/Storage/PolyFill/CopyDirectory.php @@ -0,0 +1,30 @@ + + * + * @copyright Copyright (c) 2016, ownCloud GmbH. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCP\Files\Storage\PolyFill; + +/** + * @since 9.2 + */ +trait CopyDirectory { + use \OC\Files\Storage\PolyFill\CopyDirectory; +} + diff --git a/lib/public/Files/Storage/StorageAdapter.php b/lib/public/Files/Storage/StorageAdapter.php new file mode 100644 index 000000000000..37dee8557df8 --- /dev/null +++ b/lib/public/Files/Storage/StorageAdapter.php @@ -0,0 +1,137 @@ + + * + * @copyright Copyright (c) 2016, ownCloud GmbH. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCP\Files\Storage; + +use OCP\Files\StorageNotAvailableException; + +/** + * Storage adapter implementing most of the common methods from IStorage. + * + * @since 9.2 + */ +abstract class StorageAdapter extends \OC\Files\Storage\Common { + + /** + * Get the identifier for the storage, + * the returned id should be the same for every storage object that is created with the same parameters + * and two storage objects with the same id should refer to two storages that display the same files. + * + * @return string storage id + * @since 9.2 + */ + abstract public function getId(); + + /** + * see http://php.net/manual/en/function.mkdir.php + * implementations need to implement a recursive mkdir + * + * @param string $path + * @return bool true on success, false otherwise + * @throws StorageNotAvailableException if the storage is temporarily not available + * @since 9.2 + */ + abstract public function mkdir($path); + + /** + * see http://php.net/manual/en/function.rmdir.php + * + * @param string $path + * @return bool true on success, false otherwise + * @throws StorageNotAvailableException if the storage is temporarily not available + * @since 9.2 + */ + abstract public function rmdir($path); + + /** + * see http://php.net/manual/en/function.opendir.php + * + * @param string $path + * @return resource|false + * @throws StorageNotAvailableException if the storage is temporarily not available + * @since 9.2 + */ + abstract public function opendir($path); + + /** + * see http://php.net/manual/en/function.stat.php + * only the following keys are required in the result: size and mtime + * + * @param string $path + * @return array|false + * @throws StorageNotAvailableException if the storage is temporarily not available + * @since 9.2 + */ + abstract public function stat($path); + + /** + * see http://php.net/manual/en/function.filetype.php + * + * @param string $path + * @return string|false + * @throws StorageNotAvailableException if the storage is temporarily not available + * @since 9.2 + */ + abstract public function filetype($path); + + /** + * see http://php.net/manual/en/function.file_exists.php + * + * @param string $path + * @return bool + * @throws StorageNotAvailableException if the storage is temporarily not available + * @since 9.2 + */ + abstract public function file_exists($path); + + /** + * see http://php.net/manual/en/function.unlink.php + * + * @param string $path + * @return bool true on success, false otherwise + * @throws StorageNotAvailableException if the storage is temporarily not available + * @since 9.2 + */ + abstract public function unlink($path); + + /** + * see http://php.net/manual/en/function.fopen.php + * + * @param string $path + * @param string $mode + * @return resource|false + * @throws StorageNotAvailableException if the storage is temporarily not available + * @since 9.2 + */ + abstract public function fopen($path, $mode); + + /** + * see http://php.net/manual/en/function.touch.php + * If the backend does not support the operation, false should be returned + * + * @param string $path + * @param int $mtime + * @return bool true on success, false otherwise + * @throws StorageNotAvailableException if the storage is temporarily not available + * @since 9.2 + */ + abstract public function touch($path, $mtime = NULL); +}