summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-15 12:02:31 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-15 12:02:31 +0100
commit52040a3f237390baab75908150dcb12fba7e5411 (patch)
treea63b4004ad1bf2950ee8a2a507a92b367e319c3f /lib/public
parentcd840f01ae30e31a195d1f8eb15ef2d58dba3a7a (diff)
parent7530f66f52308cb2f24478495fcffdd44ce3db41 (diff)
downloadnextcloud-server-52040a3f237390baab75908150dcb12fba7e5411.tar.gz
nextcloud-server-52040a3f237390baab75908150dcb12fba7e5411.zip
Merge pull request #20898 from owncloud/cache-interfaces
Public Cache interfaces
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/files/cache/icache.php249
-rw-r--r--lib/public/files/cache/icacheentry.php132
-rw-r--r--lib/public/files/cache/ipropagator.php37
-rw-r--r--lib/public/files/cache/iscanner.php81
-rw-r--r--lib/public/files/cache/iupdater.php75
-rw-r--r--lib/public/files/cache/iwatcher.php82
-rw-r--r--lib/public/files/storage.php13
-rw-r--r--lib/public/files/storage/ilockingstorage.php60
-rw-r--r--lib/public/files/storage/istorage.php482
9 files changed, 1203 insertions, 8 deletions
diff --git a/lib/public/files/cache/icache.php b/lib/public/files/cache/icache.php
new file mode 100644
index 00000000000..07396db4588
--- /dev/null
+++ b/lib/public/files/cache/icache.php
@@ -0,0 +1,249 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>>
+ *
+ * @copyright Copyright (c) 2015, 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
+ *
+ * @param string $folder
+ * @return ICacheEntry[]
+ * @since 9.0.0
+ */
+ public function getFolderContents($folder);
+
+ /**
+ * get the metadata of all files stored in $folder
+ *
+ * @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
+ *
+ * @param string $file
+ * @param array $data
+ *
+ * @return int file id
+ * @throws \RuntimeException
+ * @since 9.0.0
+ */
+ public function put($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
+ *
+ * @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);
+
+ /**
+ * remove all entries for files that are stored on the storage from the cache
+ *
+ * @since 9.0.0
+ */
+ public function clear();
+
+ /**
+ * 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
+ *
+ * @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
+ */
+ 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
+ */
+ 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
+ */
+ public function searchByTag($tag, $userId);
+
+ /**
+ * get all file ids on the files on the storage
+ *
+ * @return int[]
+ * @since 9.0.0
+ */
+ public function getAll();
+
+ /**
+ * 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..8d14bd2c555
--- /dev/null
+++ b/lib/public/files/cache/icacheentry.php
@@ -0,0 +1,132 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>>
+ *
+ * @copyright Copyright (c) 2015, 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 {
+ /**
+ * 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..7f7dbada532
--- /dev/null
+++ b/lib/public/files/cache/ipropagator.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>>
+ *
+ * @copyright Copyright (c) 2015, 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
+ * @return array[] all propagated cache entries
+ * @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..47e33a98bae
--- /dev/null
+++ b/lib/public/files/cache/iscanner.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>>
+ *
+ * @copyright Copyright (c) 2015, 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..241cd8636a1
--- /dev/null
+++ b/lib/public/files/cache/iupdater.php
@@ -0,0 +1,75 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>>
+ *
+ * @copyright Copyright (c) 2015, 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..a61975036f8
--- /dev/null
+++ b/lib/public/files/cache/iwatcher.php
@@ -0,0 +1,82 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>>
+ *
+ * @copyright Copyright (c) 2015, 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/storage.php b/lib/public/files/storage.php
index f6f5081abaa..1c125221449 100644
--- a/lib/public/files/storage.php
+++ b/lib/public/files/storage.php
@@ -33,16 +33,19 @@
// 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\InvalidPathException;
+
+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 {
+interface Storage extends IStorage {
/**
* $parameters is a free form array with the configuration options needed to construct the storage
*
@@ -462,10 +465,4 @@ interface Storage {
* @param bool $isAvailable
*/
public function setAvailability($isAvailable);
-
- /**
- * @param $path path for which to retrieve the owner
- * @since 9.0.0
- */
- public function getOwner($path);
}
diff --git a/lib/public/files/storage/ilockingstorage.php b/lib/public/files/storage/ilockingstorage.php
new file mode 100644
index 00000000000..32cc32ffb05
--- /dev/null
+++ b/lib/public/files/storage/ilockingstorage.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, 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..4bc5e3536dc
--- /dev/null
+++ b/lib/public/files/storage/istorage.php
@@ -0,0 +1,482 @@
+<?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 <rmccorkell@karoshi.org.uk>
+ * @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Vincent Petry <pvince81@owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, 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);
+
+ /**
+ * search for occurrences of $query in file names
+ *
+ * @param string $query
+ * @return array|false
+ * @since 9.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 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);
+
+ /**
+ * get the path to a local version of the folder.
+ * The local version of the folder can be temporary and doesn't have to be persistent across requests
+ *
+ * @param string $path
+ * @return string|false
+ * @since 9.0.0
+ */
+ public function getLocalFolder($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();
+}