diff options
Diffstat (limited to 'lib/public/Files')
44 files changed, 4096 insertions, 0 deletions
diff --git a/lib/public/Files/AlreadyExistsException.php b/lib/public/Files/AlreadyExistsException.php new file mode 100644 index 00000000000..243129cb1db --- /dev/null +++ b/lib/public/Files/AlreadyExistsException.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/AlreadyExistsException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for already existing files/folders + * @since 6.0.0 + */ +class AlreadyExistsException extends \Exception {} diff --git a/lib/public/Files/Cache/ICache.php b/lib/public/Files/Cache/ICache.php new file mode 100644 index 00000000000..4ef88f6480f --- /dev/null +++ b/lib/public/Files/Cache/ICache.php @@ -0,0 +1,256 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Cache; + +/** + * Metadata cache for a storage + * + * The cache stores the metadata for all files and folders in a storage and is kept up to date trough the following mechanisms: + * + * - Scanner: scans the storage and updates the cache where needed + * - Watcher: checks for changes made to the filesystem outside of the ownCloud instance and rescans files and folder when a change is detected + * - Updater: listens to changes made to the filesystem inside of the ownCloud instance and updates the cache where needed + * - ChangePropagator: updates the mtime and etags of parent folders whenever a change to the cache is made to the cache by the updater + * + * @since 9.0.0 + */ +interface ICache { + const NOT_FOUND = 0; + const PARTIAL = 1; //only partial data available, file not cached in the database + const SHALLOW = 2; //folder in cache, but not all child files are completely scanned + const COMPLETE = 3; + + /** + * Get the numeric storage id for this cache's storage + * + * @return int + * @since 9.0.0 + */ + public function getNumericStorageId(); + + /** + * get the stored metadata of a file or folder + * + * @param string | int $file either the path of a file or folder or the file id for a file or folder + * @return ICacheEntry|false the cache entry or false if the file is not found in the cache + * @since 9.0.0 + */ + public function get($file); + + /** + * get the metadata of all files stored in $folder + * + * Only returns files one level deep, no recursion + * + * @param string $folder + * @return ICacheEntry[] + * @since 9.0.0 + */ + public function getFolderContents($folder); + + /** + * get the metadata of all files stored in $folder + * + * Only returns files one level deep, no recursion + * + * @param int $fileId the file id of the folder + * @return ICacheEntry[] + * @since 9.0.0 + */ + public function getFolderContentsById($fileId); + + /** + * store meta data for a file or folder + * This will automatically call either insert or update depending on if the file exists + * + * @param string $file + * @param array $data + * + * @return int file id + * @throws \RuntimeException + * @since 9.0.0 + */ + public function put($file, array $data); + + /** + * insert meta data for a new file or folder + * + * @param string $file + * @param array $data + * + * @return int file id + * @throws \RuntimeException + * @since 9.0.0 + */ + public function insert($file, array $data); + + /** + * update the metadata of an existing file or folder in the cache + * + * @param int $id the fileid of the existing file or folder + * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged + * @since 9.0.0 + */ + public function update($id, array $data); + + /** + * get the file id for a file + * + * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file + * + * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing + * + * @param string $file + * @return int + * @since 9.0.0 + */ + public function getId($file); + + /** + * get the id of the parent folder of a file + * + * @param string $file + * @return int + * @since 9.0.0 + */ + public function getParentId($file); + + /** + * check if a file is available in the cache + * + * @param string $file + * @return bool + * @since 9.0.0 + */ + public function inCache($file); + + /** + * remove a file or folder from the cache + * + * when removing a folder from the cache all files and folders inside the folder will be removed as well + * + * @param string $file + * @since 9.0.0 + */ + public function remove($file); + + /** + * Move a file or folder in the cache + * + * @param string $source + * @param string $target + * @since 9.0.0 + */ + public function move($source, $target); + + /** + * Move a file or folder in the cache + * + * Note that this should make sure the entries are removed from the source cache + * + * @param \OCP\Files\Cache\ICache $sourceCache + * @param string $sourcePath + * @param string $targetPath + * @throws \OC\DatabaseException + * @since 9.0.0 + */ + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath); + + /** + * Get the scan status of a file + * + * - ICache::NOT_FOUND: File is not in the cache + * - ICache::PARTIAL: File is not stored in the cache but some incomplete data is known + * - ICache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned + * - ICache::COMPLETE: The file or folder, with all it's children) are fully scanned + * + * @param string $file + * + * @return int ICache::NOT_FOUND, ICache::PARTIAL, ICache::SHALLOW or ICache::COMPLETE + * @since 9.0.0 + */ + public function getStatus($file); + + /** + * search for files matching $pattern, files are matched if their filename matches the search pattern + * + * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%') + * @return ICacheEntry[] an array of cache entries where the name matches the search pattern + * @since 9.0.0 + * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this + */ + public function search($pattern); + + /** + * search for files by mimetype + * + * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image') + * where it will search for all mimetypes in the group ('image/*') + * @return ICacheEntry[] an array of cache entries where the mimetype matches the search + * @since 9.0.0 + * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this + */ + public function searchByMime($mimetype); + + /** + * Search for files by tag of a given users. + * + * Note that every user can tag files differently. + * + * @param string|int $tag name or tag id + * @param string $userId owner of the tags + * @return ICacheEntry[] file data + * @since 9.0.0 + * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this + */ + public function searchByTag($tag, $userId); + + /** + * find a folder in the cache which has not been fully scanned + * + * If multiple incomplete folders are in the cache, the one with the highest id will be returned, + * use the one with the highest id gives the best result with the background scanner, since that is most + * likely the folder where we stopped scanning previously + * + * @return string|bool the path of the folder or false when no folder matched + * @since 9.0.0 + */ + public function getIncomplete(); + + /** + * get the path of a file on this storage by it's file id + * + * @param int $id the file id of the file or folder to search + * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache + * @since 9.0.0 + */ + public function getPathById($id); + + /** + * normalize the given path for usage in the cache + * + * @param string $path + * @return string + * @since 9.0.0 + */ + public function normalize($path); +} diff --git a/lib/public/Files/Cache/ICacheEntry.php b/lib/public/Files/Cache/ICacheEntry.php new file mode 100644 index 00000000000..00c8e201b9a --- /dev/null +++ b/lib/public/Files/Cache/ICacheEntry.php @@ -0,0 +1,134 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Cache; + +/** + * meta data for a file or folder + * + * @since 9.0.0 + */ +interface ICacheEntry { + const DIRECTORY_MIMETYPE = 'httpd/unix-directory'; + + /** + * Get the numeric id of a file + * + * @return int + * @since 9.0.0 + */ + public function getId(); + + /** + * Get the numeric id for the storage + * + * @return int + * @since 9.0.0 + */ + public function getStorageId(); + + /** + * Get the path of the file relative to the storage root + * + * @return string + * @since 9.0.0 + */ + public function getPath(); + + /** + * Get the file name + * + * @return string + * @since 9.0.0 + */ + public function getName(); + + /** + * Get the full mimetype + * + * @return string + * @since 9.0.0 + */ + public function getMimeType(); + + /** + * Get the first part of the mimetype + * + * @return string + * @since 9.0.0 + */ + public function getMimePart(); + + /** + * Get the file size in bytes + * + * @return int + * @since 9.0.0 + */ + public function getSize(); + + /** + * Get the last modified date as unix timestamp + * + * @return int + * @since 9.0.0 + */ + public function getMTime(); + + /** + * Get the last modified date on the storage as unix timestamp + * + * Note that when a file is updated we also update the mtime of all parent folders to make it visible to the user which folder has had updates most recently + * This can differ from the mtime on the underlying storage which usually only changes when a direct child is added, removed or renamed + * + * @return int + * @since 9.0.0 + */ + public function getStorageMTime(); + + /** + * Get the etag for the file + * + * An etag is used for change detection of files and folders, an etag of a file changes whenever the content of the file changes + * Etag for folders change whenever a file in the folder has changed + * + * @return string + * @since 9.0.0 + */ + public function getEtag(); + + /** + * Get the permissions for the file stored as bitwise combination of \OCP\PERMISSION_READ, \OCP\PERMISSION_CREATE + * \OCP\PERMISSION_UPDATE, \OCP\PERMISSION_DELETE and \OCP\PERMISSION_SHARE + * + * @return int + * @since 9.0.0 + */ + public function getPermissions(); + + /** + * Check if the file is encrypted + * + * @return bool + * @since 9.0.0 + */ + public function isEncrypted(); +} diff --git a/lib/public/Files/Cache/IPropagator.php b/lib/public/Files/Cache/IPropagator.php new file mode 100644 index 00000000000..5494ec9a54e --- /dev/null +++ b/lib/public/Files/Cache/IPropagator.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Cache; + +/** + * Propagate etags and mtimes within the storage + * + * @since 9.0.0 + */ +interface IPropagator { + /** + * @param string $internalPath + * @param int $time + * @since 9.0.0 + */ + public function propagateChange($internalPath, $time); +} diff --git a/lib/public/Files/Cache/IScanner.php b/lib/public/Files/Cache/IScanner.php new file mode 100644 index 00000000000..ce1f408028c --- /dev/null +++ b/lib/public/Files/Cache/IScanner.php @@ -0,0 +1,81 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Cache; + +/** + * Scan files from the storage and save to the cache + * + * @since 9.0.0 + */ +interface IScanner { + const SCAN_RECURSIVE = true; + const SCAN_SHALLOW = false; + + const REUSE_ETAG = 1; + const REUSE_SIZE = 2; + + /** + * scan a single file and store it in the cache + * + * @param string $file + * @param int $reuseExisting + * @param int $parentId + * @param array | null $cacheData existing data in the cache for the file to be scanned + * @param bool $lock set to false to disable getting an additional read lock during scanning + * @return array an array of metadata of the scanned file + * @throws \OC\ServerNotAvailableException + * @throws \OCP\Lock\LockedException + * @since 9.0.0 + */ + public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true); + + /** + * scan a folder and all its children + * + * @param string $path + * @param bool $recursive + * @param int $reuse + * @param bool $lock set to false to disable getting an additional read lock during scanning + * @return array an array of the meta data of the scanned file or folder + * @since 9.0.0 + */ + public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true); + + /** + * check if the file should be ignored when scanning + * NOTE: files with a '.part' extension are ignored as well! + * prevents unfinished put requests to be scanned + * + * @param string $file + * @return boolean + * @since 9.0.0 + */ + public static function isPartialFile($file); + + /** + * walk over any folders that are not fully scanned yet and scan them + * + * @since 9.0.0 + */ + public function backgroundScan(); +} + diff --git a/lib/public/Files/Cache/IUpdater.php b/lib/public/Files/Cache/IUpdater.php new file mode 100644 index 00000000000..5267aa6f023 --- /dev/null +++ b/lib/public/Files/Cache/IUpdater.php @@ -0,0 +1,75 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Cache; + +use OCP\Files\Storage\IStorage; + +/** + * Update the cache and propagate changes + * + * @since 9.0.0 + */ +interface IUpdater { + /** + * Get the propagator for etags and mtime for the view the updater works on + * + * @return IPropagator + * @since 9.0.0 + */ + public function getPropagator(); + + /** + * Propagate etag and mtime changes for the parent folders of $path up to the root of the filesystem + * + * @param string $path the path of the file to propagate the changes for + * @param int|null $time the timestamp to set as mtime for the parent folders, if left out the current time is used + * @since 9.0.0 + */ + public function propagate($path, $time = null); + + /** + * Update the cache for $path and update the size, etag and mtime of the parent folders + * + * @param string $path + * @param int $time + * @since 9.0.0 + */ + public function update($path, $time = null); + + /** + * Remove $path from the cache and update the size, etag and mtime of the parent folders + * + * @param string $path + * @since 9.0.0 + */ + public function remove($path); + + /** + * Rename a file or folder in the cache and update the size, etag and mtime of the parent folders + * + * @param IStorage $sourceStorage + * @param string $source + * @param string $target + * @since 9.0.0 + */ + public function renameFromStorage(IStorage $sourceStorage, $source, $target); +} diff --git a/lib/public/Files/Cache/IWatcher.php b/lib/public/Files/Cache/IWatcher.php new file mode 100644 index 00000000000..c33129a2473 --- /dev/null +++ b/lib/public/Files/Cache/IWatcher.php @@ -0,0 +1,82 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Cache; + +/** + * check the storage backends for updates and change the cache accordingly + * + * @since 9.0.0 + */ +interface IWatcher { + const CHECK_NEVER = 0; // never check the underlying filesystem for updates + const CHECK_ONCE = 1; // check the underlying filesystem for updates once every request for each file + const CHECK_ALWAYS = 2; // always check the underlying filesystem for updates + + /** + * @param int $policy either IWatcher::CHECK_NEVER, IWatcher::CHECK_ONCE, IWatcher::CHECK_ALWAYS + * @since 9.0.0 + */ + public function setPolicy($policy); + + /** + * @return int either IWatcher::CHECK_NEVER, IWatcher::CHECK_ONCE, IWatcher::CHECK_ALWAYS + * @since 9.0.0 + */ + public function getPolicy(); + + /** + * check $path for updates and update if needed + * + * @param string $path + * @param ICacheEntry|null $cachedEntry + * @return boolean true if path was updated + * @since 9.0.0 + */ + public function checkUpdate($path, $cachedEntry = null); + + /** + * Update the cache for changes to $path + * + * @param string $path + * @param ICacheEntry $cachedData + * @since 9.0.0 + */ + public function update($path, $cachedData); + + /** + * Check if the cache for $path needs to be updated + * + * @param string $path + * @param ICacheEntry $cachedData + * @return bool + * @since 9.0.0 + */ + public function needsUpdate($path, $cachedData); + + /** + * remove deleted files in $path from the cache + * + * @param string $path + * @since 9.0.0 + */ + public function cleanFolder($path); +} diff --git a/lib/public/Files/Config/ICachedMountInfo.php b/lib/public/Files/Config/ICachedMountInfo.php new file mode 100644 index 00000000000..e09c1a7f014 --- /dev/null +++ b/lib/public/Files/Config/ICachedMountInfo.php @@ -0,0 +1,62 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Config; + +use OCP\Files\Node; +use OCP\IUser; + +/** + * Holds information about a mount for a user + * + * @since 9.0.0 + */ +interface ICachedMountInfo { + /** + * @return IUser + * @since 9.0.0 + */ + public function getUser(); + + /** + * @return int the numeric storage id of the mount + * @since 9.0.0 + */ + public function getStorageId(); + + /** + * @return int the fileid of the root of the mount + * @since 9.0.0 + */ + public function getRootId(); + + /** + * @return Node the root node of the mount + * @since 9.0.0 + */ + public function getMountPointNode(); + + /** + * @return string the mount point of the mount for the user + * @since 9.0.0 + */ + public function getMountPoint(); +} diff --git a/lib/public/Files/Config/IHomeMountProvider.php b/lib/public/Files/Config/IHomeMountProvider.php new file mode 100644 index 00000000000..bedcd3cfacc --- /dev/null +++ b/lib/public/Files/Config/IHomeMountProvider.php @@ -0,0 +1,43 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Config; + +use OCP\Files\Storage\IStorageFactory; +use OCP\IUser; + +/** + * Provides + * + * @since 9.1.0 + */ +interface IHomeMountProvider { + /** + * Get all mountpoints applicable for the user + * + * @param \OCP\IUser $user + * @param \OCP\Files\Storage\IStorageFactory $loader + * @return \OCP\Files\Mount\IMountPoint|null + * @since 9.1.0 + */ + public function getHomeMountForUser(IUser $user, IStorageFactory $loader); +} diff --git a/lib/public/Files/Config/IMountProvider.php b/lib/public/Files/Config/IMountProvider.php new file mode 100644 index 00000000000..d1498fd5f61 --- /dev/null +++ b/lib/public/Files/Config/IMountProvider.php @@ -0,0 +1,42 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Config; + +use OCP\Files\Storage\IStorageFactory; +use OCP\IUser; + +/** + * Provides + * @since 8.0.0 + */ +interface IMountProvider { + /** + * Get all mountpoints applicable for the user + * + * @param \OCP\IUser $user + * @param \OCP\Files\Storage\IStorageFactory $loader + * @return \OCP\Files\Mount\IMountPoint[] + * @since 8.0.0 + */ + public function getMountsForUser(IUser $user, IStorageFactory $loader); +} diff --git a/lib/public/Files/Config/IMountProviderCollection.php b/lib/public/Files/Config/IMountProviderCollection.php new file mode 100644 index 00000000000..29208cb6f53 --- /dev/null +++ b/lib/public/Files/Config/IMountProviderCollection.php @@ -0,0 +1,74 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Config; + +use OCP\Files\Mount\IMountPoint; +use OCP\IUser; + +/** + * Manages the different mount providers + * @since 8.0.0 + */ +interface IMountProviderCollection { + /** + * Get all configured mount points for the user + * + * @param \OCP\IUser $user + * @return \OCP\Files\Mount\IMountPoint[] + * @since 8.0.0 + */ + public function getMountsForUser(IUser $user); + + /** + * Get the configured home mount for this user + * + * @param \OCP\IUser $user + * @return \OCP\Files\Mount\IMountPoint + * @since 9.1.0 + */ + public function getHomeMountForUser(IUser $user); + + /** + * Add a provider for mount points + * + * @param \OCP\Files\Config\IMountProvider $provider + * @since 8.0.0 + */ + public function registerProvider(IMountProvider $provider); + + /** + * Add a provider for home mount points + * + * @param \OCP\Files\Config\IHomeMountProvider $provider + * @since 9.1.0 + */ + public function registerHomeProvider(IHomeMountProvider $provider); + + /** + * Get the mount cache which can be used to search for mounts without setting up the filesystem + * + * @return IUserMountCache + * @since 9.0.0 + */ + public function getMountCache(); +} diff --git a/lib/public/Files/Config/IUserMountCache.php b/lib/public/Files/Config/IUserMountCache.php new file mode 100644 index 00000000000..2f2c11da1a0 --- /dev/null +++ b/lib/public/Files/Config/IUserMountCache.php @@ -0,0 +1,104 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Config; + +use OCP\Files\Mount\IMountPoint; +use OCP\IUser; + +/** + * Cache mounts points per user in the cache so we can easily look them up + * + * @since 9.0.0 + */ +interface IUserMountCache { + /** + * Register mounts for a user to the cache + * + * @param IUser $user + * @param IMountPoint[] $mounts + * @since 9.0.0 + */ + public function registerMounts(IUser $user, array $mounts); + + /** + * Get all cached mounts for a user + * + * @param IUser $user + * @return ICachedMountInfo[] + * @since 9.0.0 + */ + public function getMountsForUser(IUser $user); + + /** + * Get all cached mounts by storage + * + * @param int $numericStorageId + * @return ICachedMountInfo[] + * @since 9.0.0 + */ + public function getMountsForStorageId($numericStorageId); + + /** + * Get all cached mounts by root + * + * @param int $rootFileId + * @return ICachedMountInfo[] + * @since 9.0.0 + */ + public function getMountsForRootId($rootFileId); + + /** + * Get all cached mounts that contain a file + * + * @param int $fileId + * @return ICachedMountInfo[] + * @since 9.0.0 + */ + public function getMountsForFileId($fileId); + + /** + * Remove all cached mounts for a user + * + * @param IUser $user + * @since 9.0.0 + */ + public function removeUserMounts(IUser $user); + + /** + * Remove all mounts for a user and storage + * + * @param $storageId + * @param string $userId + * @return mixed + * @since 9.0.0 + */ + public function removeUserStorageMount($storageId, $userId); + + /** + * Remove all cached mounts for a storage + * + * @param $storageId + * @return mixed + * @since 9.0.0 + */ + public function remoteStorageMounts($storageId); +} diff --git a/lib/public/Files/EntityTooLargeException.php b/lib/public/Files/EntityTooLargeException.php new file mode 100644 index 00000000000..8dabc08f8bb --- /dev/null +++ b/lib/public/Files/EntityTooLargeException.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/EntityTooLargeException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for too large entity + * @since 6.0.0 + */ +class EntityTooLargeException extends \Exception {} diff --git a/lib/public/Files/File.php b/lib/public/Files/File.php new file mode 100644 index 00000000000..553dd48c24f --- /dev/null +++ b/lib/public/Files/File.php @@ -0,0 +1,98 @@ +<?php +/** + * @author Jörn Friedrich Dreyer <jfd@butonic.de> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/File interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Interface File + * + * @package OCP\Files + * @since 6.0.0 + */ +interface File extends Node { + /** + * Get the content of the file as string + * + * @return string + * @throws \OCP\Files\NotPermittedException + * @since 6.0.0 + */ + public function getContent(); + + /** + * Write to the file from string data + * + * @param string $data + * @throws \OCP\Files\NotPermittedException + * @return void + * @since 6.0.0 + */ + public function putContent($data); + + /** + * Get the mimetype of the file + * + * @return string + * @since 6.0.0 + */ + public function getMimeType(); + + /** + * Open the file as stream, resulting resource can be operated as stream like the result from php's own fopen + * + * @param string $mode + * @return resource + * @throws \OCP\Files\NotPermittedException + * @since 6.0.0 + */ + public function fopen($mode); + + /** + * Compute the hash of the file + * Type of hash is set with $type and can be anything supported by php's hash_file + * + * @param string $type + * @param bool $raw + * @return string + * @since 6.0.0 + */ + public function hash($type, $raw = false); + + /** + * Get the stored checksum for this file + * + * @return string + * @since 9.0.0 + * @throws InvalidPathException + * @throws NotFoundException + */ + public function getChecksum(); +} diff --git a/lib/public/Files/FileInfo.php b/lib/public/Files/FileInfo.php new file mode 100644 index 00000000000..a9f05863e78 --- /dev/null +++ b/lib/public/Files/FileInfo.php @@ -0,0 +1,249 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * @author Robin McCorkell <robin@mccorkell.me.uk> + * @author Roeland Jago Douma <rullzer@owncloud.com> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Files; + +/** + * Interface FileInfo + * + * @package OCP\Files + * @since 7.0.0 + */ +interface FileInfo { + /** + * @since 7.0.0 + */ + const TYPE_FILE = 'file'; + /** + * @since 7.0.0 + */ + const TYPE_FOLDER = 'dir'; + + /** + * @const \OCP\Files\FileInfo::SPACE_NOT_COMPUTED Return value for a not computed space value + * @since 8.0.0 + */ + const SPACE_NOT_COMPUTED = -1; + /** + * @const \OCP\Files\FileInfo::SPACE_UNKNOWN Return value for unknown space value + * @since 8.0.0 + */ + const SPACE_UNKNOWN = -2; + /** + * @const \OCP\Files\FileInfo::SPACE_UNKNOWN Return value for unlimited space + * @since 8.0.0 + */ + const SPACE_UNLIMITED = -3; + + /** + * Get the Etag of the file or folder + * + * @return string + * @since 7.0.0 + */ + public function getEtag(); + + /** + * Get the size in bytes for the file or folder + * + * @return int + * @since 7.0.0 + */ + public function getSize(); + + /** + * Get the last modified date as timestamp for the file or folder + * + * @return int + * @since 7.0.0 + */ + public function getMtime(); + + /** + * Get the name of the file or folder + * + * @return string + * @since 7.0.0 + */ + public function getName(); + + /** + * Get the path relative to the storage + * + * @return string + * @since 7.0.0 + */ + public function getInternalPath(); + + /** + * Get the absolute path + * + * @return string + * @since 7.0.0 + */ + public function getPath(); + + /** + * Get the full mimetype of the file or folder i.e. 'image/png' + * + * @return string + * @since 7.0.0 + */ + public function getMimetype(); + + /** + * Get the first part of the mimetype of the file or folder i.e. 'image' + * + * @return string + * @since 7.0.0 + */ + public function getMimePart(); + + /** + * Get the storage the file or folder is storage on + * + * @return \OCP\Files\Storage + * @since 7.0.0 + */ + public function getStorage(); + + /** + * Get the file id of the file or folder + * + * @return int + * @since 7.0.0 + */ + public function getId(); + + /** + * Check whether the file is encrypted + * + * @return bool + * @since 7.0.0 + */ + public function isEncrypted(); + + /** + * Get the permissions of the file or folder as bitmasked combination of the following constants + * \OCP\Constants::PERMISSION_CREATE + * \OCP\Constants::PERMISSION_READ + * \OCP\Constants::PERMISSION_UPDATE + * \OCP\Constants::PERMISSION_DELETE + * \OCP\Constants::PERMISSION_SHARE + * \OCP\Constants::PERMISSION_ALL + * + * @return int + * @since 7.0.0 - namespace of constants has changed in 8.0.0 + */ + public function getPermissions(); + + /** + * Check whether this is a file or a folder + * + * @return \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER + * @since 7.0.0 + */ + public function getType(); + + /** + * Check if the file or folder is readable + * + * @return bool + * @since 7.0.0 + */ + public function isReadable(); + + /** + * Check if a file is writable + * + * @return bool + * @since 7.0.0 + */ + public function isUpdateable(); + + /** + * Check whether new files or folders can be created inside this folder + * + * @return bool + * @since 8.0.0 + */ + public function isCreatable(); + + /** + * Check if a file or folder can be deleted + * + * @return bool + * @since 7.0.0 + */ + public function isDeletable(); + + /** + * Check if a file or folder can be shared + * + * @return bool + * @since 7.0.0 + */ + public function isShareable(); + + /** + * Check if a file or folder is shared + * + * @return bool + * @since 7.0.0 + */ + public function isShared(); + + /** + * Check if a file or folder is mounted + * + * @return bool + * @since 7.0.0 + */ + public function isMounted(); + + /** + * Get the mountpoint the file belongs to + * + * @return \OCP\Files\Mount\IMountPoint + * @since 8.0.0 + */ + public function getMountPoint(); + + /** + * Get the owner of the file + * + * @return \OCP\IUser + * @since 9.0.0 + */ + public function getOwner(); + + /** + * Get the stored checksum for this file + * + * @return string + * @since 9.0.0 + */ + public function getChecksum(); +} diff --git a/lib/public/Files/FileNameTooLongException.php b/lib/public/Files/FileNameTooLongException.php new file mode 100644 index 00000000000..68fba4ad516 --- /dev/null +++ b/lib/public/Files/FileNameTooLongException.php @@ -0,0 +1,39 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/ReservedWordException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Class FileNameTooLongException + * + * @package OCP\Files + * @since 8.1.0 + */ +class FileNameTooLongException extends InvalidPathException { +} diff --git a/lib/public/Files/Folder.php b/lib/public/Files/Folder.php new file mode 100644 index 00000000000..0644ab62034 --- /dev/null +++ b/lib/public/Files/Folder.php @@ -0,0 +1,177 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * @author Vincent Petry <pvince81@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/Folder interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * @since 6.0.0 + */ +interface Folder extends Node { + /** + * Get the full path of an item in the folder within owncloud's filesystem + * + * @param string $path relative path of an item in the folder + * @return string + * @throws \OCP\Files\NotPermittedException + * @since 6.0.0 + */ + public function getFullPath($path); + + /** + * Get the path of an item in the folder relative to the folder + * + * @param string $path absolute path of an item in the folder + * @throws \OCP\Files\NotFoundException + * @return string + * @since 6.0.0 + */ + public function getRelativePath($path); + + /** + * check if a node is a (grand-)child of the folder + * + * @param \OCP\Files\Node $node + * @return bool + * @since 6.0.0 + */ + public function isSubNode($node); + + /** + * get the content of this directory + * + * @throws \OCP\Files\NotFoundException + * @return \OCP\Files\Node[] + * @since 6.0.0 + */ + public function getDirectoryListing(); + + /** + * Get the node at $path + * + * @param string $path relative path of the file or folder + * @return \OCP\Files\Node + * @throws \OCP\Files\NotFoundException + * @since 6.0.0 + */ + public function get($path); + + /** + * Check if a file or folder exists in the folder + * + * @param string $path relative path of the file or folder + * @return bool + * @since 6.0.0 + */ + public function nodeExists($path); + + /** + * Create a new folder + * + * @param string $path relative path of the new folder + * @return \OCP\Files\Folder + * @throws \OCP\Files\NotPermittedException + * @since 6.0.0 + */ + public function newFolder($path); + + /** + * Create a new file + * + * @param string $path relative path of the new file + * @return \OCP\Files\File + * @throws \OCP\Files\NotPermittedException + * @since 6.0.0 + */ + public function newFile($path); + + /** + * search for files with the name matching $query + * + * @param string $query + * @return \OCP\Files\Node[] + * @since 6.0.0 + */ + public function search($query); + + /** + * search for files by mimetype + * $mimetype can either be a full mimetype (image/png) or a wildcard mimetype (image) + * + * @param string $mimetype + * @return \OCP\Files\Node[] + * @since 6.0.0 + */ + public function searchByMime($mimetype); + + /** + * search for files by tag + * + * @param string|int $tag tag name or tag id + * @param string $userId owner of the tags + * @return \OCP\Files\Node[] + * @since 8.0.0 + */ + public function searchByTag($tag, $userId); + + /** + * get a file or folder inside the folder by it's internal id + * + * @param int $id + * @return \OCP\Files\Node[] + * @since 6.0.0 + */ + public function getById($id); + + /** + * Get the amount of free space inside the folder + * + * @return int + * @since 6.0.0 + */ + public function getFreeSpace(); + + /** + * Check if new files or folders can be created within the folder + * + * @return bool + * @since 6.0.0 + */ + public function isCreatable(); + + /** + * Add a suffix to the name in case the file exists + * + * @param string $name + * @return string + * @throws NotPermittedException + * @since 8.1.0 + */ + public function getNonExistingName($name); +} diff --git a/lib/public/Files/ForbiddenException.php b/lib/public/Files/ForbiddenException.php new file mode 100644 index 00000000000..5a4f03d176d --- /dev/null +++ b/lib/public/Files/ForbiddenException.php @@ -0,0 +1,55 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Class ForbiddenException + * + * @package OCP\Files + * @since 9.0.0 + */ +class ForbiddenException extends \Exception { + + /** @var bool */ + private $retry; + + /** + * @param string $message + * @param bool $retry + * @param \Exception $previous previous exception for cascading + * @since 9.0.0 + */ + public function __construct($message, $retry, \Exception $previous = null) { + parent::__construct($message, 0, $previous); + $this->retry = $retry; + } + + /** + * @return bool + * @since 9.0.0 + */ + public function getRetry() { + return (bool) $this->retry; + } +} diff --git a/lib/public/Files/IHomeStorage.php b/lib/public/Files/IHomeStorage.php new file mode 100644 index 00000000000..4101545aafe --- /dev/null +++ b/lib/public/Files/IHomeStorage.php @@ -0,0 +1,40 @@ +<?php +/** + * @author Joas Schilling <nickvergessen@owncloud.com> + * @author Morris Jobke <hey@morrisjobke.de> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/Storage interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Interface IHomeStorage + * + * @package OCP\Files + * @since 7.0.0 + */ +interface IHomeStorage { + +} diff --git a/lib/public/Files/IMimeTypeDetector.php b/lib/public/Files/IMimeTypeDetector.php new file mode 100644 index 00000000000..7d9cd606e69 --- /dev/null +++ b/lib/public/Files/IMimeTypeDetector.php @@ -0,0 +1,78 @@ +<?php +/** + * @author Roeland Jago Douma <rullzer@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + + +/** + * Interface IMimeTypeDetector + * @package OCP\Files + * @since 8.2.0 + * + * Interface to handle mimetypes (detection and icon retrieval) + **/ +interface IMimeTypeDetector { + + /** + * detect mimetype only based on filename, content of file is not used + * @param string $path + * @return string + * @since 8.2.0 + **/ + public function detectPath($path); + + /** + * detect mimetype based on both filename and content + * + * @param string $path + * @return string + * @since 8.2.0 + */ + public function detect($path); + + /** + * Get a secure mimetype that won't expose potential XSS. + * + * @param string $mimeType + * @return string + * @since 8.2.0 + */ + public function getSecureMimeType($mimeType); + + /** + * detect mimetype based on the content of a string + * + * @param string $data + * @return string + * @since 8.2.0 + */ + public function detectString($data); + + /** + * Get path to the icon of a file type + * @param string $mimeType the MIME type + * @return string the url + * @since 8.2.0 + */ + public function mimeTypeIcon($mimeType); +} diff --git a/lib/public/Files/IMimeTypeLoader.php b/lib/public/Files/IMimeTypeLoader.php new file mode 100644 index 00000000000..57a6d7ba309 --- /dev/null +++ b/lib/public/Files/IMimeTypeLoader.php @@ -0,0 +1,66 @@ +<?php +/** + * @author Robin McCorkell <robin@mccorkell.me.uk> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files; + +/** + * Interface IMimeTypeLoader + * @package OCP\Files + * @since 8.2.0 + * + * Interface to load mimetypes + **/ +interface IMimeTypeLoader { + + /** + * Get a mimetype from its ID + * + * @param int $id + * @return string|null + * @since 8.2.0 + */ + public function getMimetypeById($id); + + /** + * Get a mimetype ID, adding the mimetype to the DB if it does not exist + * + * @param string $mimetype + * @return int + * @since 8.2.0 + */ + public function getId($mimetype); + + /** + * Test if a mimetype exists in the database + * + * @param string $mimetype + * @return bool + * @since 8.2.0 + */ + public function exists($mimetype); + + /** + * Clear all loaded mimetypes, allow for re-loading + * + * @since 8.2.0 + */ + public function reset(); +} diff --git a/lib/public/Files/IRootFolder.php b/lib/public/Files/IRootFolder.php new file mode 100644 index 00000000000..3b6243f7638 --- /dev/null +++ b/lib/public/Files/IRootFolder.php @@ -0,0 +1,45 @@ +<?php +/** + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Morris Jobke <hey@morrisjobke.de> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + + +namespace OCP\Files; + +use OC\Hooks\Emitter; + +/** + * Interface IRootFolder + * + * @package OCP\Files + * @since 8.0.0 + */ +interface IRootFolder extends Folder, Emitter { + + /** + * Returns a view to user's files folder + * + * @param String $userId user ID + * @return \OCP\Files\Folder + * @since 8.2.0 + */ + public function getUserFolder($userId); +} + diff --git a/lib/public/Files/InvalidCharacterInPathException.php b/lib/public/Files/InvalidCharacterInPathException.php new file mode 100644 index 00000000000..8e649b5bb62 --- /dev/null +++ b/lib/public/Files/InvalidCharacterInPathException.php @@ -0,0 +1,38 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/InvalidCharacterInPathException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for invalid path + * @since 8.1.0 + */ +class InvalidCharacterInPathException extends InvalidPathException { + +} diff --git a/lib/public/Files/InvalidContentException.php b/lib/public/Files/InvalidContentException.php new file mode 100644 index 00000000000..f25b7fef87f --- /dev/null +++ b/lib/public/Files/InvalidContentException.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/InvalidContentException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for invalid content + * @since 6.0.0 + */ +class InvalidContentException extends \Exception {} diff --git a/lib/public/Files/InvalidPathException.php b/lib/public/Files/InvalidPathException.php new file mode 100644 index 00000000000..ee21d7432be --- /dev/null +++ b/lib/public/Files/InvalidPathException.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/InvalidPathException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for invalid path + * @since 6.0.0 + */ +class InvalidPathException extends \Exception {} diff --git a/lib/public/Files/LockNotAcquiredException.php b/lib/public/Files/LockNotAcquiredException.php new file mode 100644 index 00000000000..247c9f5f5cb --- /dev/null +++ b/lib/public/Files/LockNotAcquiredException.php @@ -0,0 +1,61 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Owen Winkler <a_github@midnightcircus.com> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/LockNotAcquiredException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for a file that is locked + * @since 7.0.0 + */ +class LockNotAcquiredException extends \Exception { + /** @var string $path The path that could not be locked */ + public $path; + + /** @var integer $lockType The type of the lock that was attempted */ + public $lockType; + + /** + * @since 7.0.0 + */ + public function __construct($path, $lockType, $code = 0, \Exception $previous = null) { + $message = \OC::$server->getL10N('core')->t('Could not obtain lock type %d on "%s".', array($lockType, $path)); + parent::__construct($message, $code, $previous); + } + + /** + * custom string representation of object + * + * @return string + * @since 7.0.0 + */ + public function __toString() { + return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; + } +} diff --git a/lib/public/Files/Mount/IMountManager.php b/lib/public/Files/Mount/IMountManager.php new file mode 100644 index 00000000000..9e3002a26d1 --- /dev/null +++ b/lib/public/Files/Mount/IMountManager.php @@ -0,0 +1,106 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Mount; + +/** + * Interface IMountManager + * + * Manages all mounted storages in the system + * @since 8.2.0 + */ +interface IMountManager { + + /** + * Add a new mount + * + * @param \OCP\Files\Mount\IMountPoint $mount + * @since 8.2.0 + */ + public function addMount(IMountPoint $mount); + + /** + * Remove a mount + * + * @param string $mountPoint + * @since 8.2.0 + */ + public function removeMount($mountPoint); + + /** + * Change the location of a mount + * + * @param string $mountPoint + * @param string $target + * @since 8.2.0 + */ + public function moveMount($mountPoint, $target); + + /** + * Find the mount for $path + * + * @param string $path + * @return \OCP\Files\Mount\IMountPoint + * @since 8.2.0 + */ + public function find($path); + + /** + * Find all mounts in $path + * + * @param string $path + * @return \OCP\Files\Mount\IMountPoint[] + * @since 8.2.0 + */ + public function findIn($path); + + /** + * Remove all registered mounts + * + * @since 8.2.0 + */ + public function clear(); + + /** + * Find mounts by storage id + * + * @param string $id + * @return \OCP\Files\Mount\IMountPoint[] + * @since 8.2.0 + */ + public function findByStorageId($id); + + /** + * @return \OCP\Files\Mount\IMountPoint[] + * @since 8.2.0 + */ + public function getAll(); + + /** + * Find mounts by numeric storage id + * + * @param int $id + * @return \OCP\Files\Mount\IMountPoint[] + * @since 8.2.0 + */ + public function findByNumericId($id); +} diff --git a/lib/public/Files/Mount/IMountPoint.php b/lib/public/Files/Mount/IMountPoint.php new file mode 100644 index 00000000000..bc7bf81709f --- /dev/null +++ b/lib/public/Files/Mount/IMountPoint.php @@ -0,0 +1,105 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Mount; + +/** + * A storage mounted to folder on the filesystem + * @since 8.0.0 + */ +interface IMountPoint { + + /** + * get complete path to the mount point + * + * @return string + * @since 8.0.0 + */ + public function getMountPoint(); + + /** + * Set the mountpoint + * + * @param string $mountPoint new mount point + * @since 8.0.0 + */ + public function setMountPoint($mountPoint); + + /** + * Get the storage that is mounted + * + * @return \OC\Files\Storage\Storage + * @since 8.0.0 + */ + public function getStorage(); + + /** + * Get the id of the storages + * + * @return string + * @since 8.0.0 + */ + public function getStorageId(); + + /** + * Get the path relative to the mountpoint + * + * @param string $path absolute path to a file or folder + * @return string + * @since 8.0.0 + */ + public function getInternalPath($path); + + /** + * Apply a storage wrapper to the mounted storage + * + * @param callable $wrapper + * @since 8.0.0 + */ + public function wrapStorage($wrapper); + + /** + * Get a mount option + * + * @param string $name Name of the mount option to get + * @param mixed $default Default value for the mount option + * @return mixed + * @since 8.0.0 + */ + public function getOption($name, $default); + + /** + * Get all options for the mount + * + * @return array + * @since 8.1.0 + */ + public function getOptions(); + + /** + * Get the file id of the root of the storage + * + * @return int + * @since 9.1.0 + */ + public function getStorageRootId(); +} diff --git a/lib/public/Files/Node.php b/lib/public/Files/Node.php new file mode 100644 index 00000000000..c69077c7f2a --- /dev/null +++ b/lib/public/Files/Node.php @@ -0,0 +1,279 @@ +<?php +/** + * @author Bernhard Posselt <dev@bernhard-posselt.com> + * @author Joas Schilling <nickvergessen@owncloud.com> + * @author Jörn Friedrich Dreyer <jfd@butonic.de> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/Node interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Interface Node + * + * @package OCP\Files + * @since 6.0.0 - extends FileInfo was added in 8.0.0 + */ +interface Node extends FileInfo { + /** + * Move the file or folder to a new location + * + * @param string $targetPath the absolute target path + * @throws \OCP\Files\NotPermittedException + * @return \OCP\Files\Node + * @since 6.0.0 + */ + public function move($targetPath); + + /** + * Delete the file or folder + * @return void + * @since 6.0.0 + */ + public function delete(); + + /** + * Cope the file or folder to a new location + * + * @param string $targetPath the absolute target path + * @return \OCP\Files\Node + * @since 6.0.0 + */ + public function copy($targetPath); + + /** + * Change the modified date of the file or folder + * If $mtime is omitted the current time will be used + * + * @param int $mtime (optional) modified date as unix timestamp + * @throws \OCP\Files\NotPermittedException + * @return void + * @since 6.0.0 + */ + public function touch($mtime = null); + + /** + * Get the storage backend the file or folder is stored on + * + * @return \OCP\Files\Storage + * @throws \OCP\Files\NotFoundException + * @since 6.0.0 + */ + public function getStorage(); + + /** + * Get the full path of the file or folder + * + * @return string + * @since 6.0.0 + */ + public function getPath(); + + /** + * Get the path of the file or folder relative to the mountpoint of it's storage + * + * @return string + * @since 6.0.0 + */ + public function getInternalPath(); + + /** + * Get the internal file id for the file or folder + * + * @return int + * @throws InvalidPathException + * @throws NotFoundException + * @since 6.0.0 + */ + public function getId(); + + /** + * Get metadata of the file or folder + * The returned array contains the following values: + * - mtime + * - size + * + * @return array + * @since 6.0.0 + */ + public function stat(); + + /** + * Get the modified date of the file or folder as unix timestamp + * + * @return int + * @throws InvalidPathException + * @throws NotFoundException + * @since 6.0.0 + */ + public function getMTime(); + + /** + * Get the size of the file or folder in bytes + * + * @return int + * @throws InvalidPathException + * @throws NotFoundException + * @since 6.0.0 + */ + public function getSize(); + + /** + * Get the Etag of the file or folder + * The Etag is an string id used to detect changes to a file or folder, + * every time the file or folder is changed the Etag will change to + * + * @return string + * @throws InvalidPathException + * @throws NotFoundException + * @since 6.0.0 + */ + public function getEtag(); + + + /** + * Get the permissions of the file or folder as a combination of one or more of the following constants: + * - \OCP\Constants::PERMISSION_READ + * - \OCP\Constants::PERMISSION_UPDATE + * - \OCP\Constants::PERMISSION_CREATE + * - \OCP\Constants::PERMISSION_DELETE + * - \OCP\Constants::PERMISSION_SHARE + * + * @return int + * @throws InvalidPathException + * @throws NotFoundException + * @since 6.0.0 - namespace of constants has changed in 8.0.0 + */ + public function getPermissions(); + + /** + * Check if the file or folder is readable + * + * @return bool + * @throws InvalidPathException + * @throws NotFoundException + * @since 6.0.0 + */ + public function isReadable(); + + /** + * Check if the file or folder is writable + * + * @return bool + * @throws InvalidPathException + * @throws NotFoundException + * @since 6.0.0 + */ + public function isUpdateable(); + + /** + * Check if the file or folder is deletable + * + * @return bool + * @throws InvalidPathException + * @throws NotFoundException + * @since 6.0.0 + */ + public function isDeletable(); + + /** + * Check if the file or folder is shareable + * + * @return bool + * @throws InvalidPathException + * @throws NotFoundException + * @since 6.0.0 + */ + public function isShareable(); + + /** + * Get the parent folder of the file or folder + * + * @return Folder + * @since 6.0.0 + */ + public function getParent(); + + /** + * Get the filename of the file or folder + * + * @return string + * @since 6.0.0 + */ + public function getName(); + + /** + * Acquire a lock on this file or folder. + * + * A shared (read) lock will prevent any exclusive (write) locks from being created but any number of shared locks + * can be active at the same time. + * An exclusive lock will prevent any other lock from being created (both shared and exclusive). + * + * A locked exception will be thrown if any conflicting lock already exists + * + * Note that this uses mandatory locking, if you acquire an exclusive lock on a file it will block *all* + * other operations for that file, even within the same php process. + * + * Acquiring any lock on a file will also create a shared lock on all parent folders of that file. + * + * Note that in most cases you won't need to manually manage the locks for any files you're working with, + * any filesystem operation will automatically acquire the relevant locks for that operation. + * + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * @throws \OCP\Lock\LockedException + * @since 9.1.0 + */ + public function lock($type); + + /** + * Check the type of an existing lock. + * + * A shared lock can be changed to an exclusive lock is there is exactly one shared lock on the file, + * an exclusive lock can always be changed to a shared lock since there can only be one exclusive lock int he first place. + * + * A locked exception will be thrown when these preconditions are not met. + * Note that this is also the case if no existing lock exists for the file. + * + * @param int $targetType \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * @throws \OCP\Lock\LockedException + * @since 9.1.0 + */ + public function changeLock($targetType); + + /** + * Release an existing lock. + * + * This will also free up the shared locks on any parent folder that were automatically acquired when locking the file. + * + * Note that this method will not give any sort of error when trying to free a lock that doesn't exist. + * + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * @throws \OCP\Lock\LockedException + * @since 9.1.0 + */ + public function unlock($type); +} diff --git a/lib/public/Files/NotEnoughSpaceException.php b/lib/public/Files/NotEnoughSpaceException.php new file mode 100644 index 00000000000..4e67ac26700 --- /dev/null +++ b/lib/public/Files/NotEnoughSpaceException.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/NotEnoughSpaceException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for not enough space + * @since 6.0.0 + */ +class NotEnoughSpaceException extends \Exception {} diff --git a/lib/public/Files/NotFoundException.php b/lib/public/Files/NotFoundException.php new file mode 100644 index 00000000000..10a3dacda44 --- /dev/null +++ b/lib/public/Files/NotFoundException.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/NotFoundException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for not found entity + * @since 6.0.0 + */ +class NotFoundException extends \Exception {} diff --git a/lib/public/Files/NotPermittedException.php b/lib/public/Files/NotPermittedException.php new file mode 100644 index 00000000000..3dcbd9e499b --- /dev/null +++ b/lib/public/Files/NotPermittedException.php @@ -0,0 +1,36 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/NotPermittedException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for not permitted action + * @since 6.0.0 + */ +class NotPermittedException extends \Exception {} diff --git a/lib/public/Files/ObjectStore/IObjectStore.php b/lib/public/Files/ObjectStore/IObjectStore.php new file mode 100644 index 00000000000..78be18fb2e9 --- /dev/null +++ b/lib/public/Files/ObjectStore/IObjectStore.php @@ -0,0 +1,62 @@ +<?php +/** + * @author Jörn Friedrich Dreyer <jfd@butonic.de> + * @author Morris Jobke <hey@morrisjobke.de> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Files\ObjectStore; + +/** + * Interface IObjectStore + * + * @package OCP\Files\ObjectStore + * @since 7.0.0 + */ +interface IObjectStore { + + /** + * @return string the container or bucket name where objects are stored + * @since 7.0.0 + */ + function getStorageId(); + + /** + * @param string $urn the unified resource name used to identify the object + * @return resource stream with the read data + * @throws \Exception when something goes wrong, message will be logged + * @since 7.0.0 + */ + function readObject($urn); + + /** + * @param string $urn the unified resource name used to identify the object + * @param resource $stream stream with the data to write + * @throws \Exception when something goes wrong, message will be logged + * @since 7.0.0 + */ + function writeObject($urn, $stream); + + /** + * @param string $urn the unified resource name used to identify the object + * @return void + * @throws \Exception when something goes wrong, message will be logged + * @since 7.0.0 + */ + function deleteObject($urn); + +} diff --git a/lib/public/Files/ReservedWordException.php b/lib/public/Files/ReservedWordException.php new file mode 100644 index 00000000000..6a560a563fe --- /dev/null +++ b/lib/public/Files/ReservedWordException.php @@ -0,0 +1,38 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/ReservedWordException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Exception for invalid path + * @since 8.1.0 + */ +class ReservedWordException extends InvalidPathException { + +} diff --git a/lib/public/Files/Storage.php b/lib/public/Files/Storage.php new file mode 100644 index 00000000000..2511690b7d3 --- /dev/null +++ b/lib/public/Files/Storage.php @@ -0,0 +1,459 @@ +<?php +/** + * @author Jörn Friedrich Dreyer <jfd@butonic.de> + * @author Michael Roth <michael.roth@rz.uni-augsburg.de> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * @author Robin McCorkell <robin@mccorkell.me.uk> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * @author Vincent Petry <pvince81@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/Storage interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +use OCP\Files\Storage\IStorage; +use OCP\Lock\ILockingProvider; + +/** + * Provide a common interface to all different storage options + * + * All paths passed to the storage are relative to the storage and should NOT have a leading slash. + * + * @since 6.0.0 + * @deprecated 9.0.0 use \OCP\Files\Storage\IStorage instead + */ +interface Storage extends IStorage { + /** + * $parameters is a free form array with the configuration options needed to construct the storage + * + * @param array $parameters + * @since 6.0.0 + */ + public function __construct($parameters); + + /** + * 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 + * @since 6.0.0 + */ + public function getId(); + + /** + * see http://php.net/manual/en/function.mkdir.php + * implementations need to implement a recursive mkdir + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function mkdir($path); + + /** + * see http://php.net/manual/en/function.rmdir.php + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function rmdir($path); + + /** + * see http://php.net/manual/en/function.opendir.php + * + * @param string $path + * @return resource|false + * @since 6.0.0 + */ + public function opendir($path); + + /** + * see http://php.net/manual/en/function.is-dir.php + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function is_dir($path); + + /** + * see http://php.net/manual/en/function.is-file.php + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function is_file($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 + * @since 6.0.0 + */ + public function stat($path); + + /** + * see http://php.net/manual/en/function.filetype.php + * + * @param string $path + * @return string|false + * @since 6.0.0 + */ + public function filetype($path); + + /** + * see http://php.net/manual/en/function.filesize.php + * The result for filesize when called on a folder is required to be 0 + * + * @param string $path + * @return int|false + * @since 6.0.0 + */ + public function filesize($path); + + /** + * check if a file can be created in $path + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function isCreatable($path); + + /** + * check if a file can be read + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function isReadable($path); + + /** + * check if a file can be written to + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function isUpdatable($path); + + /** + * check if a file can be deleted + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function isDeletable($path); + + /** + * check if a file can be shared + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function isSharable($path); + + /** + * get the full permissions of a path. + * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php + * + * @param string $path + * @return int + * @since 6.0.0 + */ + public function getPermissions($path); + + /** + * see http://php.net/manual/en/function.file_exists.php + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function file_exists($path); + + /** + * see http://php.net/manual/en/function.filemtime.php + * + * @param string $path + * @return int|false + * @since 6.0.0 + */ + public function filemtime($path); + + /** + * see http://php.net/manual/en/function.file_get_contents.php + * + * @param string $path + * @return string|false + * @since 6.0.0 + */ + public function file_get_contents($path); + + /** + * see http://php.net/manual/en/function.file_put_contents.php + * + * @param string $path + * @param string $data + * @return bool + * @since 6.0.0 + */ + public function file_put_contents($path, $data); + + /** + * see http://php.net/manual/en/function.unlink.php + * + * @param string $path + * @return bool + * @since 6.0.0 + */ + public function unlink($path); + + /** + * see http://php.net/manual/en/function.rename.php + * + * @param string $path1 + * @param string $path2 + * @return bool + * @since 6.0.0 + */ + public function rename($path1, $path2); + + /** + * see http://php.net/manual/en/function.copy.php + * + * @param string $path1 + * @param string $path2 + * @return bool + * @since 6.0.0 + */ + public function copy($path1, $path2); + + /** + * see http://php.net/manual/en/function.fopen.php + * + * @param string $path + * @param string $mode + * @return resource|false + * @since 6.0.0 + */ + public function fopen($path, $mode); + + /** + * get the mimetype for a file or folder + * The mimetype for a folder is required to be "httpd/unix-directory" + * + * @param string $path + * @return string|false + * @since 6.0.0 + */ + public function getMimeType($path); + + /** + * see http://php.net/manual/en/function.hash-file.php + * + * @param string $type + * @param string $path + * @param bool $raw + * @return string|false + * @since 6.0.0 + */ + public function hash($type, $path, $raw = false); + + /** + * see http://php.net/manual/en/function.free_space.php + * + * @param string $path + * @return int|false + * @since 6.0.0 + */ + public function free_space($path); + + /** + * search for occurrences of $query in file names + * + * @param string $query + * @return array|false + * @since 6.0.0 + */ + public function search($query); + + /** + * 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 + * @since 6.0.0 + */ + public function touch($path, $mtime = null); + + /** + * get the path to a local version of the file. + * The local version of the file can be temporary and doesn't have to be persistent across requests + * + * @param string $path + * @return string|false + * @since 6.0.0 + */ + public function getLocalFile($path); + + /** + * check if a file or folder has been updated since $time + * + * @param string $path + * @param int $time + * @return bool + * @since 6.0.0 + * + * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. + * returning true for other changes in the folder is optional + */ + public function hasUpdated($path, $time); + + /** + * get the ETag for a file or folder + * + * @param string $path + * @return string|false + * @since 6.0.0 + */ + public function getETag($path); + + /** + * Returns whether the storage is local, which means that files + * are stored on the local filesystem instead of remotely. + * Calling getLocalFile() for local storages should always + * return the local files, whereas for non-local storages + * it might return a temporary file. + * + * @return bool true if the files are stored locally, false otherwise + * @since 7.0.0 + */ + public function isLocal(); + + /** + * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class + * + * @param string $class + * @return bool + * @since 7.0.0 + */ + public function instanceOfStorage($class); + + /** + * A custom storage implementation can return an url for direct download of a give file. + * + * For now the returned array can hold the parameter url - in future more attributes might follow. + * + * @param string $path + * @return array|false + * @since 8.0.0 + */ + public function getDirectDownload($path); + + /** + * @param string $path the path of the target folder + * @param string $fileName the name of the file itself + * @return void + * @throws InvalidPathException + * @since 8.1.0 + */ + public function verifyPath($path, $fileName); + + /** + * @param \OCP\Files\Storage $sourceStorage + * @param string $sourceInternalPath + * @param string $targetInternalPath + * @return bool + * @since 8.1.0 + */ + public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); + + /** + * @param \OCP\Files\Storage $sourceStorage + * @param string $sourceInternalPath + * @param string $targetInternalPath + * @return bool + * @since 8.1.0 + */ + public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); + + /** + * @param string $path The path of the file to acquire the lock for + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * @param \OCP\Lock\ILockingProvider $provider + * @throws \OCP\Lock\LockedException + * @since 8.1.0 + */ + public function acquireLock($path, $type, ILockingProvider $provider); + + /** + * @param string $path The path of the file to acquire the lock for + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * @param \OCP\Lock\ILockingProvider $provider + * @since 8.1.0 + */ + public function releaseLock($path, $type, ILockingProvider $provider); + + /** + * @param string $path The path of the file to change the lock for + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * @param \OCP\Lock\ILockingProvider $provider + * @throws \OCP\Lock\LockedException + * @since 8.1.0 + */ + public function changeLock($path, $type, ILockingProvider $provider); + + /** + * Test a storage for availability + * + * @since 8.2.0 + * @return bool + */ + public function test(); + + /** + * @since 8.2.0 + * @return array [ available, last_checked ] + */ + public function getAvailability(); + + /** + * @since 8.2.0 + * @param bool $isAvailable + */ + public function setAvailability($isAvailable); +} diff --git a/lib/public/Files/Storage/ILockingStorage.php b/lib/public/Files/Storage/ILockingStorage.php new file mode 100644 index 00000000000..7c46391f425 --- /dev/null +++ b/lib/public/Files/Storage/ILockingStorage.php @@ -0,0 +1,60 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Storage; + +use OCP\Lock\ILockingProvider; + +/** + * Storage backends that require explicit locking + * + * Storage backends implementing this interface do not need to implement their own locking implementation but should use the provided lockingprovider instead + * The implementation of the locking methods only need to map internal storage paths to "lock keys" + * + * @since 9.0.0 + */ +interface ILockingStorage { + /** + * @param string $path The path of the file to acquire the lock for + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * @param \OCP\Lock\ILockingProvider $provider + * @throws \OCP\Lock\LockedException + * @since 9.0.0 + */ + public function acquireLock($path, $type, ILockingProvider $provider); + + /** + * @param string $path The path of the file to acquire the lock for + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * @param \OCP\Lock\ILockingProvider $provider + * @since 9.0.0 + */ + public function releaseLock($path, $type, ILockingProvider $provider); + + /** + * @param string $path The path of the file to change the lock for + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE + * @param \OCP\Lock\ILockingProvider $provider + * @throws \OCP\Lock\LockedException + * @since 9.0.0 + */ + public function changeLock($path, $type, ILockingProvider $provider); +} diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php new file mode 100644 index 00000000000..ab1915bb93e --- /dev/null +++ b/lib/public/Files/Storage/IStorage.php @@ -0,0 +1,457 @@ +<?php +/** + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/Storage interface + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files\Storage; + +use OCP\Files\Cache\ICache; +use OCP\Files\Cache\IPropagator; +use OCP\Files\Cache\IScanner; +use OCP\Files\Cache\IUpdater; +use OCP\Files\Cache\IWatcher; +use OCP\Files\InvalidPathException; + +/** + * Provide a common interface to all different storage options + * + * All paths passed to the storage are relative to the storage and should NOT have a leading slash. + * + * @since 9.0.0 + */ +interface IStorage { + /** + * $parameters is a free form array with the configuration options needed to construct the storage + * + * @param array $parameters + * @since 9.0.0 + */ + public function __construct($parameters); + + /** + * 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 + * @since 9.0.0 + */ + public function getId(); + + /** + * see http://php.net/manual/en/function.mkdir.php + * implementations need to implement a recursive mkdir + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function mkdir($path); + + /** + * see http://php.net/manual/en/function.rmdir.php + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function rmdir($path); + + /** + * see http://php.net/manual/en/function.opendir.php + * + * @param string $path + * @return resource|false + * @since 9.0.0 + */ + public function opendir($path); + + /** + * see http://php.net/manual/en/function.is-dir.php + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function is_dir($path); + + /** + * see http://php.net/manual/en/function.is-file.php + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function is_file($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 + * @since 9.0.0 + */ + public function stat($path); + + /** + * see http://php.net/manual/en/function.filetype.php + * + * @param string $path + * @return string|false + * @since 9.0.0 + */ + public function filetype($path); + + /** + * see http://php.net/manual/en/function.filesize.php + * The result for filesize when called on a folder is required to be 0 + * + * @param string $path + * @return int|false + * @since 9.0.0 + */ + public function filesize($path); + + /** + * check if a file can be created in $path + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function isCreatable($path); + + /** + * check if a file can be read + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function isReadable($path); + + /** + * check if a file can be written to + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function isUpdatable($path); + + /** + * check if a file can be deleted + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function isDeletable($path); + + /** + * check if a file can be shared + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function isSharable($path); + + /** + * get the full permissions of a path. + * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php + * + * @param string $path + * @return int + * @since 9.0.0 + */ + public function getPermissions($path); + + /** + * see http://php.net/manual/en/function.file_exists.php + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function file_exists($path); + + /** + * see http://php.net/manual/en/function.filemtime.php + * + * @param string $path + * @return int|false + * @since 9.0.0 + */ + public function filemtime($path); + + /** + * see http://php.net/manual/en/function.file_get_contents.php + * + * @param string $path + * @return string|false + * @since 9.0.0 + */ + public function file_get_contents($path); + + /** + * see http://php.net/manual/en/function.file_put_contents.php + * + * @param string $path + * @param string $data + * @return bool + * @since 9.0.0 + */ + public function file_put_contents($path, $data); + + /** + * see http://php.net/manual/en/function.unlink.php + * + * @param string $path + * @return bool + * @since 9.0.0 + */ + public function unlink($path); + + /** + * see http://php.net/manual/en/function.rename.php + * + * @param string $path1 + * @param string $path2 + * @return bool + * @since 9.0.0 + */ + public function rename($path1, $path2); + + /** + * see http://php.net/manual/en/function.copy.php + * + * @param string $path1 + * @param string $path2 + * @return bool + * @since 9.0.0 + */ + public function copy($path1, $path2); + + /** + * see http://php.net/manual/en/function.fopen.php + * + * @param string $path + * @param string $mode + * @return resource|false + * @since 9.0.0 + */ + public function fopen($path, $mode); + + /** + * get the mimetype for a file or folder + * The mimetype for a folder is required to be "httpd/unix-directory" + * + * @param string $path + * @return string|false + * @since 9.0.0 + */ + public function getMimeType($path); + + /** + * see http://php.net/manual/en/function.hash-file.php + * + * @param string $type + * @param string $path + * @param bool $raw + * @return string|false + * @since 9.0.0 + */ + public function hash($type, $path, $raw = false); + + /** + * see http://php.net/manual/en/function.free_space.php + * + * @param string $path + * @return int|false + * @since 9.0.0 + */ + public function free_space($path); + + /** + * 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 + * @since 9.0.0 + */ + public function touch($path, $mtime = null); + + /** + * get the path to a local version of the file. + * The local version of the file can be temporary and doesn't have to be persistent across requests + * + * @param string $path + * @return string|false + * @since 9.0.0 + */ + public function getLocalFile($path); + + /** + * check if a file or folder has been updated since $time + * + * @param string $path + * @param int $time + * @return bool + * @since 9.0.0 + * + * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. + * returning true for other changes in the folder is optional + */ + public function hasUpdated($path, $time); + + /** + * get the ETag for a file or folder + * + * @param string $path + * @return string|false + * @since 9.0.0 + */ + public function getETag($path); + + /** + * Returns whether the storage is local, which means that files + * are stored on the local filesystem instead of remotely. + * Calling getLocalFile() for local storages should always + * return the local files, whereas for non-local storages + * it might return a temporary file. + * + * @return bool true if the files are stored locally, false otherwise + * @since 9.0.0 + */ + public function isLocal(); + + /** + * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class + * + * @param string $class + * @return bool + * @since 9.0.0 + */ + public function instanceOfStorage($class); + + /** + * A custom storage implementation can return an url for direct download of a give file. + * + * For now the returned array can hold the parameter url - in future more attributes might follow. + * + * @param string $path + * @return array|false + * @since 9.0.0 + */ + public function getDirectDownload($path); + + /** + * @param string $path the path of the target folder + * @param string $fileName the name of the file itself + * @return void + * @throws InvalidPathException + * @since 9.0.0 + */ + public function verifyPath($path, $fileName); + + /** + * @param \OCP\Files\Storage $sourceStorage + * @param string $sourceInternalPath + * @param string $targetInternalPath + * @return bool + * @since 9.0.0 + */ + public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); + + /** + * @param \OCP\Files\Storage $sourceStorage + * @param string $sourceInternalPath + * @param string $targetInternalPath + * @return bool + * @since 9.0.0 + */ + public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); + + /** + * Test a storage for availability + * + * @since 9.0.0 + * @return bool + */ + public function test(); + + /** + * @since 9.0.0 + * @return array [ available, last_checked ] + */ + public function getAvailability(); + + /** + * @since 9.0.0 + * @param bool $isAvailable + */ + public function setAvailability($isAvailable); + + /** + * @param string $path path for which to retrieve the owner + * @since 9.0.0 + */ + public function getOwner($path); + + /** + * @return ICache + * @since 9.0.0 + */ + public function getCache(); + + /** + * @return IPropagator + * @since 9.0.0 + */ + public function getPropagator(); + + /** + * @return IScanner + * @since 9.0.0 + */ + public function getScanner(); + + /** + * @return IUpdater + * @since 9.0.0 + */ + public function getUpdater(); + + /** + * @return IWatcher + * @since 9.0.0 + */ + public function getWatcher(); +} diff --git a/lib/public/Files/Storage/IStorageFactory.php b/lib/public/Files/Storage/IStorageFactory.php new file mode 100644 index 00000000000..01a05eeff12 --- /dev/null +++ b/lib/public/Files/Storage/IStorageFactory.php @@ -0,0 +1,53 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * @author Vincent Petry <pvince81@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +namespace OCP\Files\Storage; +use OCP\Files\Mount\IMountPoint; + +/** + * Creates storage instances and manages and applies storage wrappers + * @since 8.0.0 + */ +interface IStorageFactory { + /** + * allow modifier storage behaviour by adding wrappers around storages + * + * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage + * + * @param string $wrapperName + * @param callable $callback + * @return bool true if the wrapper was added, false if there was already a wrapper with this + * name registered + * @since 8.0.0 + */ + public function addStorageWrapper($wrapperName, $callback); + + /** + * @param \OCP\Files\Mount\IMountPoint $mountPoint + * @param string $class + * @param array $arguments + * @return \OCP\Files\Storage + * @since 8.0.0 + */ + public function getInstance(IMountPoint $mountPoint, $class, $arguments); +} diff --git a/lib/public/Files/StorageAuthException.php b/lib/public/Files/StorageAuthException.php new file mode 100644 index 00000000000..35a2907b856 --- /dev/null +++ b/lib/public/Files/StorageAuthException.php @@ -0,0 +1,41 @@ +<?php +/** + * @author Jesús Macias <jmacias@solidgear.es> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Files; + +/** + * Storage authentication exception + * @since 9.0.0 + */ +class StorageAuthException extends StorageNotAvailableException { + + /** + * StorageAuthException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', \Exception $previous = null) { + $l = \OC::$server->getL10N('core'); + parent::__construct($l->t('Storage unauthorized. %s', $message), self::STATUS_UNAUTHORIZED, $previous); + } +} diff --git a/lib/public/Files/StorageBadConfigException.php b/lib/public/Files/StorageBadConfigException.php new file mode 100644 index 00000000000..1c340b18b7c --- /dev/null +++ b/lib/public/Files/StorageBadConfigException.php @@ -0,0 +1,42 @@ +<?php +/** + * @author Jesús Macias <jmacias@solidgear.es> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Files; + +/** + * Storage has bad or missing config params + * @since 9.0.0 + */ +class StorageBadConfigException extends StorageNotAvailableException { + + /** + * ExtStorageBadConfigException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', \Exception $previous = null) { + $l = \OC::$server->getL10N('core'); + parent::__construct($l->t('Storage incomplete configuration. %s', $message), self::STATUS_INCOMPLETE_CONF, $previous); + } + +} diff --git a/lib/public/Files/StorageConnectionException.php b/lib/public/Files/StorageConnectionException.php new file mode 100644 index 00000000000..8938a60265c --- /dev/null +++ b/lib/public/Files/StorageConnectionException.php @@ -0,0 +1,41 @@ +<?php +/** + * @author Jesús Macias <jmacias@solidgear.es> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Files; + +/** + * Storage authentication exception + * @since 9.0.0 + */ +class StorageConnectionException extends StorageNotAvailableException { + + /** + * StorageConnectionException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', \Exception $previous = null) { + $l = \OC::$server->getL10N('core'); + parent::__construct($l->t('Storage connection error. %s', $message), self::STATUS_NETWORK_ERROR, $previous); + } +} diff --git a/lib/public/Files/StorageInvalidException.php b/lib/public/Files/StorageInvalidException.php new file mode 100644 index 00000000000..a34ee7ae49a --- /dev/null +++ b/lib/public/Files/StorageInvalidException.php @@ -0,0 +1,37 @@ +<?php +/** + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/AlreadyExistsException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; + +/** + * Storage has invalid configuration + * @since 7.0.0 + */ +class StorageInvalidException extends \Exception { +} diff --git a/lib/public/Files/StorageNotAvailableException.php b/lib/public/Files/StorageNotAvailableException.php new file mode 100644 index 00000000000..7afb067f298 --- /dev/null +++ b/lib/public/Files/StorageNotAvailableException.php @@ -0,0 +1,88 @@ +<?php +/** + * @author Björn Schießle <schiessle@owncloud.com> + * @author Jesús Macias <jmacias@solidgear.es> + * @author Morris Jobke <hey@morrisjobke.de> + * @author Robin Appelman <icewind@owncloud.com> + * @author Robin McCorkell <robin@mccorkell.me.uk> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ + +/** + * Public interface of ownCloud for apps to use. + * Files/AlreadyExistsException class + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP\Files; +use OC\HintException; + +/** + * Storage is temporarily not available + * @since 6.0.0 - since 8.2.1 based on HintException + */ +class StorageNotAvailableException extends HintException { + + const STATUS_SUCCESS = 0; + const STATUS_ERROR = 1; + const STATUS_INDETERMINATE = 2; + const STATUS_INCOMPLETE_CONF = 3; + const STATUS_UNAUTHORIZED = 4; + const STATUS_TIMEOUT = 5; + const STATUS_NETWORK_ERROR = 6; + + /** + * StorageNotAvailableException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 6.0.0 + */ + public function __construct($message = '', $code = self::STATUS_ERROR, \Exception $previous = null) { + $l = \OC::$server->getL10N('core'); + parent::__construct($message, $l->t('Storage not available'), $code, $previous); + } + + /** + * Get the name for a status code + * + * @param int $code + * @return string + * @since 9.0.0 + */ + public static function getStateCodeName($code) { + switch ($code) { + case self::STATUS_SUCCESS: + return 'ok'; + case self::STATUS_ERROR: + return 'error'; + case self::STATUS_INDETERMINATE: + return 'indeterminate'; + case self::STATUS_UNAUTHORIZED: + return 'unauthorized'; + case self::STATUS_TIMEOUT: + return 'timeout'; + case self::STATUS_NETWORK_ERROR: + return 'network error'; + default: + return 'unknown'; + } + } +} diff --git a/lib/public/Files/StorageTimeoutException.php b/lib/public/Files/StorageTimeoutException.php new file mode 100644 index 00000000000..ed4d98af89b --- /dev/null +++ b/lib/public/Files/StorageTimeoutException.php @@ -0,0 +1,41 @@ +<?php +/** + * @author Jesús Macias <jmacias@solidgear.es> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 <http://www.gnu.org/licenses/> + * + */ +namespace OCP\Files; + +/** + * Storage authentication exception + * @since 9.0.0 + */ +class StorageTimeoutException extends StorageNotAvailableException { + + /** + * StorageTimeoutException constructor. + * + * @param string $message + * @param int $code + * @param \Exception $previous + * @since 9.0.0 + */ + public function __construct($message = '', \Exception $previous = null) { + $l = \OC::$server->getL10N('core'); + parent::__construct($l->t('Storage connection timeout. %s', $message), self::STATUS_TIMEOUT, $previous); + } +} |