summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-03-20 16:15:18 +0100
committerVincent Petry <pvince81@owncloud.com>2014-03-24 12:57:11 +0100
commit10c9b8eb996bcabbe4ef40c51248fd6fca70814a (patch)
tree349246a3f79e37ba8f04e950253d9af5fa8f1251 /lib
parentabdc823bb69600c3a4fc23e09f9de5819b57f56e (diff)
downloadnextcloud-server-10c9b8eb996bcabbe4ef40c51248fd6fca70814a.tar.gz
nextcloud-server-10c9b8eb996bcabbe4ef40c51248fd6fca70814a.zip
Cache folder is now configurable
When using an external cache folder, it is automatically mounted in FileSystem::initFileSystem so that any app can use it transparently by creating a view on the "/$user/cache" directory.
Diffstat (limited to 'lib')
-rw-r--r--lib/private/cache/file.php15
-rw-r--r--lib/private/files/filesystem.php36
-rw-r--r--lib/private/forbiddenexception.php16
3 files changed, 60 insertions, 7 deletions
diff --git a/lib/private/cache/file.php b/lib/private/cache/file.php
index 8a6ef39f61b..be6805a9a57 100644
--- a/lib/private/cache/file.php
+++ b/lib/private/cache/file.php
@@ -1,6 +1,7 @@
<?php
/**
* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
+ * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
@@ -10,22 +11,22 @@ namespace OC\Cache;
class File {
protected $storage;
+
+ /**
+ * Returns the cache storage for the logged in user
+ * @return cache storage
+ */
protected function getStorage() {
if (isset($this->storage)) {
return $this->storage;
}
if(\OC_User::isLoggedIn()) {
\OC\Files\Filesystem::initMountPoints(\OC_User::getUser());
- $subdir = 'cache';
- $view = new \OC\Files\View('/' . \OC_User::getUser());
- if(!$view->file_exists($subdir)) {
- $view->mkdir($subdir);
- }
- $this->storage = new \OC\Files\View('/' . \OC_User::getUser().'/'.$subdir);
+ $this->storage = new \OC\Files\View('/' . \OC_User::getUser() . '/cache');
return $this->storage;
}else{
\OC_Log::write('core', 'Can\'t get cache storage, user not logged in', \OC_Log::ERROR);
- return false;
+ throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in');
}
}
diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php
index c31e0c38180..56bafc7e974 100644
--- a/lib/private/files/filesystem.php
+++ b/lib/private/files/filesystem.php
@@ -321,11 +321,47 @@ class Filesystem {
self::mount('\OC\Files\Storage\Local', array('datadir' => $root), $user);
}
+ self::mountCacheDir($user);
+
// Chance to mount for other storages
\OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', array('user' => $user, 'user_dir' => $root));
}
/**
+ * Mounts the cache directory
+ * @param string $user user name
+ */
+ private static function mountCacheDir($user) {
+ $cacheBaseDir = \OC_Config::getValue('cache_path', '');
+ if ($cacheBaseDir === '') {
+ // use local cache dir relative to the user's home
+ $subdir = 'cache';
+ $view = new \OC\Files\View('/' . $user);
+ if(!$view->file_exists($subdir)) {
+ $view->mkdir($subdir);
+ }
+ } else {
+ $cacheDir = rtrim($cacheBaseDir, '/') . '/' . $user;
+ if (!file_exists($cacheDir)) {
+ mkdir($cacheDir, 0770, true);
+ }
+ // mount external cache dir to "/$user/cache" mount point
+ self::mount('\OC\Files\Storage\Local', array('datadir' => $cacheDir), '/' . $user . '/cache');
+ }
+ }
+
+ /**
+ * fill in the correct values for $user
+ *
+ * @param string $user
+ * @param string $input
+ * @return string
+ */
+ private static function setUserVars($user, $input) {
+ return str_replace('$user', $user, $input);
+ }
+
+ /**
* get the default filesystem view
*
* @return View
diff --git a/lib/private/forbiddenexception.php b/lib/private/forbiddenexception.php
new file mode 100644
index 00000000000..14a4cd14984
--- /dev/null
+++ b/lib/private/forbiddenexception.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC;
+
+/**
+ * Exception thrown whenever access to a resource has
+ * been forbidden or whenever a user isn't authenticated.
+ */
+class ForbiddenException extends \Exception {
+}