@@ -23,32 +23,32 @@ |
||
23 | 23 | namespace OC\Memcache; |
24 | 24 | |
25 | 25 | trait CADTrait { |
26 | - abstract public function get($key); |
|
26 | + abstract public function get($key); |
|
27 | 27 | |
28 | - abstract public function remove($key); |
|
28 | + abstract public function remove($key); |
|
29 | 29 | |
30 | - abstract public function add($key, $value, $ttl = 0); |
|
30 | + abstract public function add($key, $value, $ttl = 0); |
|
31 | 31 | |
32 | - /** |
|
33 | - * Compare and delete |
|
34 | - * |
|
35 | - * @param string $key |
|
36 | - * @param mixed $old |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function cad($key, $old) { |
|
40 | - //no native cas, emulate with locking |
|
41 | - if ($this->add($key . '_lock', true)) { |
|
42 | - if ($this->get($key) === $old) { |
|
43 | - $this->remove($key); |
|
44 | - $this->remove($key . '_lock'); |
|
45 | - return true; |
|
46 | - } else { |
|
47 | - $this->remove($key . '_lock'); |
|
48 | - return false; |
|
49 | - } |
|
50 | - } else { |
|
51 | - return false; |
|
52 | - } |
|
53 | - } |
|
32 | + /** |
|
33 | + * Compare and delete |
|
34 | + * |
|
35 | + * @param string $key |
|
36 | + * @param mixed $old |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function cad($key, $old) { |
|
40 | + //no native cas, emulate with locking |
|
41 | + if ($this->add($key . '_lock', true)) { |
|
42 | + if ($this->get($key) === $old) { |
|
43 | + $this->remove($key); |
|
44 | + $this->remove($key . '_lock'); |
|
45 | + return true; |
|
46 | + } else { |
|
47 | + $this->remove($key . '_lock'); |
|
48 | + return false; |
|
49 | + } |
|
50 | + } else { |
|
51 | + return false; |
|
52 | + } |
|
53 | + } |
|
54 | 54 | } |
@@ -33,27 +33,27 @@ |
||
33 | 33 | */ |
34 | 34 | class CoreCapabilities implements ICapability { |
35 | 35 | |
36 | - /** @var IConfig */ |
|
37 | - private $config; |
|
36 | + /** @var IConfig */ |
|
37 | + private $config; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param IConfig $config |
|
41 | - */ |
|
42 | - public function __construct(IConfig $config) { |
|
43 | - $this->config = $config; |
|
44 | - } |
|
39 | + /** |
|
40 | + * @param IConfig $config |
|
41 | + */ |
|
42 | + public function __construct(IConfig $config) { |
|
43 | + $this->config = $config; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Return this classes capabilities |
|
48 | - * |
|
49 | - * @return array |
|
50 | - */ |
|
51 | - public function getCapabilities() { |
|
52 | - return [ |
|
53 | - 'core' => [ |
|
54 | - 'pollinterval' => $this->config->getSystemValue('pollinterval', 60), |
|
55 | - 'webdav-root' => $this->config->getSystemValue('webdav-root', 'remote.php/webdav'), |
|
56 | - ] |
|
57 | - ]; |
|
58 | - } |
|
46 | + /** |
|
47 | + * Return this classes capabilities |
|
48 | + * |
|
49 | + * @return array |
|
50 | + */ |
|
51 | + public function getCapabilities() { |
|
52 | + return [ |
|
53 | + 'core' => [ |
|
54 | + 'pollinterval' => $this->config->getSystemValue('pollinterval', 60), |
|
55 | + 'webdav-root' => $this->config->getSystemValue('webdav-root', 'remote.php/webdav'), |
|
56 | + ] |
|
57 | + ]; |
|
58 | + } |
|
59 | 59 | } |
@@ -27,19 +27,19 @@ |
||
27 | 27 | * Defines the mount point to be (re)moved by the user |
28 | 28 | */ |
29 | 29 | interface MoveableMount { |
30 | - /** |
|
31 | - * Move the mount point to $target |
|
32 | - * |
|
33 | - * @param string $target the target mount point |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function moveMount($target); |
|
30 | + /** |
|
31 | + * Move the mount point to $target |
|
32 | + * |
|
33 | + * @param string $target the target mount point |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function moveMount($target); |
|
37 | 37 | |
38 | - /** |
|
39 | - * Remove the mount points |
|
40 | - * |
|
41 | - * @return mixed |
|
42 | - * @return bool |
|
43 | - */ |
|
44 | - public function removeMount(); |
|
38 | + /** |
|
39 | + * Remove the mount points |
|
40 | + * |
|
41 | + * @return mixed |
|
42 | + * @return bool |
|
43 | + */ |
|
44 | + public function removeMount(); |
|
45 | 45 | } |
@@ -29,60 +29,60 @@ |
||
29 | 29 | use OCP\IUser; |
30 | 30 | |
31 | 31 | class LazyStorageMountInfo extends CachedMountInfo { |
32 | - /** @var IMountPoint */ |
|
33 | - private $mount; |
|
32 | + /** @var IMountPoint */ |
|
33 | + private $mount; |
|
34 | 34 | |
35 | - /** |
|
36 | - * CachedMountInfo constructor. |
|
37 | - * |
|
38 | - * @param IUser $user |
|
39 | - * @param IMountPoint $mount |
|
40 | - */ |
|
41 | - public function __construct(IUser $user, IMountPoint $mount) { |
|
42 | - $this->user = $user; |
|
43 | - $this->mount = $mount; |
|
44 | - } |
|
35 | + /** |
|
36 | + * CachedMountInfo constructor. |
|
37 | + * |
|
38 | + * @param IUser $user |
|
39 | + * @param IMountPoint $mount |
|
40 | + */ |
|
41 | + public function __construct(IUser $user, IMountPoint $mount) { |
|
42 | + $this->user = $user; |
|
43 | + $this->mount = $mount; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return int the numeric storage id of the mount |
|
48 | - */ |
|
49 | - public function getStorageId() { |
|
50 | - if (!$this->storageId) { |
|
51 | - $this->storageId = $this->mount->getNumericStorageId(); |
|
52 | - } |
|
53 | - return parent::getStorageId(); |
|
54 | - } |
|
46 | + /** |
|
47 | + * @return int the numeric storage id of the mount |
|
48 | + */ |
|
49 | + public function getStorageId() { |
|
50 | + if (!$this->storageId) { |
|
51 | + $this->storageId = $this->mount->getNumericStorageId(); |
|
52 | + } |
|
53 | + return parent::getStorageId(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @return int the fileid of the root of the mount |
|
58 | - */ |
|
59 | - public function getRootId() { |
|
60 | - if (!$this->rootId) { |
|
61 | - $this->rootId = $this->mount->getStorageRootId(); |
|
62 | - } |
|
63 | - return parent::getRootId(); |
|
64 | - } |
|
56 | + /** |
|
57 | + * @return int the fileid of the root of the mount |
|
58 | + */ |
|
59 | + public function getRootId() { |
|
60 | + if (!$this->rootId) { |
|
61 | + $this->rootId = $this->mount->getStorageRootId(); |
|
62 | + } |
|
63 | + return parent::getRootId(); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return string the mount point of the mount for the user |
|
68 | - */ |
|
69 | - public function getMountPoint() { |
|
70 | - if (!$this->mountPoint) { |
|
71 | - $this->mountPoint = $this->mount->getMountPoint(); |
|
72 | - } |
|
73 | - return parent::getMountPoint(); |
|
74 | - } |
|
66 | + /** |
|
67 | + * @return string the mount point of the mount for the user |
|
68 | + */ |
|
69 | + public function getMountPoint() { |
|
70 | + if (!$this->mountPoint) { |
|
71 | + $this->mountPoint = $this->mount->getMountPoint(); |
|
72 | + } |
|
73 | + return parent::getMountPoint(); |
|
74 | + } |
|
75 | 75 | |
76 | - public function getMountId() { |
|
77 | - return $this->mount->getMountId(); |
|
78 | - } |
|
76 | + public function getMountId() { |
|
77 | + return $this->mount->getMountId(); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Get the internal path (within the storage) of the root of the mount |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function getRootInternalPath() { |
|
86 | - return $this->mount->getInternalPath($this->mount->getMountPoint()); |
|
87 | - } |
|
80 | + /** |
|
81 | + * Get the internal path (within the storage) of the root of the mount |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function getRootInternalPath() { |
|
86 | + return $this->mount->getInternalPath($this->mount->getMountPoint()); |
|
87 | + } |
|
88 | 88 | } |
@@ -29,21 +29,21 @@ |
||
29 | 29 | * Listen to hooks and update the mount cache as needed |
30 | 30 | */ |
31 | 31 | class UserMountCacheListener { |
32 | - /** |
|
33 | - * @var IUserMountCache |
|
34 | - */ |
|
35 | - private $userMountCache; |
|
32 | + /** |
|
33 | + * @var IUserMountCache |
|
34 | + */ |
|
35 | + private $userMountCache; |
|
36 | 36 | |
37 | - /** |
|
38 | - * UserMountCacheListener constructor. |
|
39 | - * |
|
40 | - * @param IUserMountCache $userMountCache |
|
41 | - */ |
|
42 | - public function __construct(IUserMountCache $userMountCache) { |
|
43 | - $this->userMountCache = $userMountCache; |
|
44 | - } |
|
37 | + /** |
|
38 | + * UserMountCacheListener constructor. |
|
39 | + * |
|
40 | + * @param IUserMountCache $userMountCache |
|
41 | + */ |
|
42 | + public function __construct(IUserMountCache $userMountCache) { |
|
43 | + $this->userMountCache = $userMountCache; |
|
44 | + } |
|
45 | 45 | |
46 | - public function listen(Manager $manager) { |
|
47 | - $manager->listen('\OC\User', 'postDelete', [$this->userMountCache, 'removeUserMounts']); |
|
48 | - } |
|
46 | + public function listen(Manager $manager) { |
|
47 | + $manager->listen('\OC\User', 'postDelete', [$this->userMountCache, 'removeUserMounts']); |
|
48 | + } |
|
49 | 49 | } |
@@ -28,114 +28,114 @@ |
||
28 | 28 | use OCP\IUser; |
29 | 29 | |
30 | 30 | class CachedMountInfo implements ICachedMountInfo { |
31 | - /** |
|
32 | - * @var IUser |
|
33 | - */ |
|
34 | - protected $user; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var int |
|
38 | - */ |
|
39 | - protected $storageId; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var int |
|
43 | - */ |
|
44 | - protected $rootId; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $mountPoint; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var int|null |
|
53 | - */ |
|
54 | - protected $mountId; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - protected $rootInternalPath; |
|
60 | - |
|
61 | - /** |
|
62 | - * CachedMountInfo constructor. |
|
63 | - * |
|
64 | - * @param IUser $user |
|
65 | - * @param int $storageId |
|
66 | - * @param int $rootId |
|
67 | - * @param string $mountPoint |
|
68 | - * @param int|null $mountId |
|
69 | - * @param string $rootInternalPath |
|
70 | - */ |
|
71 | - public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId = null, $rootInternalPath = '') { |
|
72 | - $this->user = $user; |
|
73 | - $this->storageId = $storageId; |
|
74 | - $this->rootId = $rootId; |
|
75 | - $this->mountPoint = $mountPoint; |
|
76 | - $this->mountId = $mountId; |
|
77 | - $this->rootInternalPath = $rootInternalPath; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @return IUser |
|
82 | - */ |
|
83 | - public function getUser() { |
|
84 | - return $this->user; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return int the numeric storage id of the mount |
|
89 | - */ |
|
90 | - public function getStorageId() { |
|
91 | - return $this->storageId; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @return int the fileid of the root of the mount |
|
96 | - */ |
|
97 | - public function getRootId() { |
|
98 | - return $this->rootId; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return Node the root node of the mount |
|
103 | - */ |
|
104 | - public function getMountPointNode() { |
|
105 | - // TODO injection etc |
|
106 | - Filesystem::initMountPoints($this->getUser()->getUID()); |
|
107 | - $userNode = \OC::$server->getUserFolder($this->getUser()->getUID()); |
|
108 | - $nodes = $userNode->getParent()->getById($this->getRootId()); |
|
109 | - if (count($nodes) > 0) { |
|
110 | - return $nodes[0]; |
|
111 | - } else { |
|
112 | - return null; |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @return string the mount point of the mount for the user |
|
118 | - */ |
|
119 | - public function getMountPoint() { |
|
120 | - return $this->mountPoint; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Get the id of the configured mount |
|
125 | - * |
|
126 | - * @return int|null mount id or null if not applicable |
|
127 | - * @since 9.1.0 |
|
128 | - */ |
|
129 | - public function getMountId() { |
|
130 | - return $this->mountId; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Get the internal path (within the storage) of the root of the mount |
|
135 | - * |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public function getRootInternalPath() { |
|
139 | - return $this->rootInternalPath; |
|
140 | - } |
|
31 | + /** |
|
32 | + * @var IUser |
|
33 | + */ |
|
34 | + protected $user; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var int |
|
38 | + */ |
|
39 | + protected $storageId; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var int |
|
43 | + */ |
|
44 | + protected $rootId; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $mountPoint; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var int|null |
|
53 | + */ |
|
54 | + protected $mountId; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + protected $rootInternalPath; |
|
60 | + |
|
61 | + /** |
|
62 | + * CachedMountInfo constructor. |
|
63 | + * |
|
64 | + * @param IUser $user |
|
65 | + * @param int $storageId |
|
66 | + * @param int $rootId |
|
67 | + * @param string $mountPoint |
|
68 | + * @param int|null $mountId |
|
69 | + * @param string $rootInternalPath |
|
70 | + */ |
|
71 | + public function __construct(IUser $user, $storageId, $rootId, $mountPoint, $mountId = null, $rootInternalPath = '') { |
|
72 | + $this->user = $user; |
|
73 | + $this->storageId = $storageId; |
|
74 | + $this->rootId = $rootId; |
|
75 | + $this->mountPoint = $mountPoint; |
|
76 | + $this->mountId = $mountId; |
|
77 | + $this->rootInternalPath = $rootInternalPath; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @return IUser |
|
82 | + */ |
|
83 | + public function getUser() { |
|
84 | + return $this->user; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return int the numeric storage id of the mount |
|
89 | + */ |
|
90 | + public function getStorageId() { |
|
91 | + return $this->storageId; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @return int the fileid of the root of the mount |
|
96 | + */ |
|
97 | + public function getRootId() { |
|
98 | + return $this->rootId; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return Node the root node of the mount |
|
103 | + */ |
|
104 | + public function getMountPointNode() { |
|
105 | + // TODO injection etc |
|
106 | + Filesystem::initMountPoints($this->getUser()->getUID()); |
|
107 | + $userNode = \OC::$server->getUserFolder($this->getUser()->getUID()); |
|
108 | + $nodes = $userNode->getParent()->getById($this->getRootId()); |
|
109 | + if (count($nodes) > 0) { |
|
110 | + return $nodes[0]; |
|
111 | + } else { |
|
112 | + return null; |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @return string the mount point of the mount for the user |
|
118 | + */ |
|
119 | + public function getMountPoint() { |
|
120 | + return $this->mountPoint; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Get the id of the configured mount |
|
125 | + * |
|
126 | + * @return int|null mount id or null if not applicable |
|
127 | + * @since 9.1.0 |
|
128 | + */ |
|
129 | + public function getMountId() { |
|
130 | + return $this->mountId; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Get the internal path (within the storage) of the root of the mount |
|
135 | + * |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public function getRootInternalPath() { |
|
139 | + return $this->rootInternalPath; |
|
140 | + } |
|
141 | 141 | } |
@@ -31,25 +31,25 @@ |
||
31 | 31 | * Map a user to a bucket. |
32 | 32 | */ |
33 | 33 | class Mapper { |
34 | - /** @var IUser */ |
|
35 | - private $user; |
|
34 | + /** @var IUser */ |
|
35 | + private $user; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Mapper constructor. |
|
39 | - * |
|
40 | - * @param IUser $user |
|
41 | - */ |
|
42 | - public function __construct(IUser $user) { |
|
43 | - $this->user = $user; |
|
44 | - } |
|
37 | + /** |
|
38 | + * Mapper constructor. |
|
39 | + * |
|
40 | + * @param IUser $user |
|
41 | + */ |
|
42 | + public function __construct(IUser $user) { |
|
43 | + $this->user = $user; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param int $numBuckets |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getBucket($numBuckets = 64) { |
|
51 | - $hash = md5($this->user->getUID()); |
|
52 | - $num = hexdec(substr($hash, 0, 4)); |
|
53 | - return (string)($num % $numBuckets); |
|
54 | - } |
|
46 | + /** |
|
47 | + * @param int $numBuckets |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getBucket($numBuckets = 64) { |
|
51 | + $hash = md5($this->user->getUID()); |
|
52 | + $num = hexdec(substr($hash, 0, 4)); |
|
53 | + return (string)($num % $numBuckets); |
|
54 | + } |
|
55 | 55 | } |
@@ -37,45 +37,45 @@ |
||
37 | 37 | */ |
38 | 38 | trait LocalTempFileTrait { |
39 | 39 | |
40 | - /** @var string[] */ |
|
41 | - protected $cachedFiles = []; |
|
40 | + /** @var string[] */ |
|
41 | + protected $cachedFiles = []; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $path |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - protected function getCachedFile($path) { |
|
48 | - if (!isset($this->cachedFiles[$path])) { |
|
49 | - $this->cachedFiles[$path] = $this->toTmpFile($path); |
|
50 | - } |
|
51 | - return $this->cachedFiles[$path]; |
|
52 | - } |
|
43 | + /** |
|
44 | + * @param string $path |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + protected function getCachedFile($path) { |
|
48 | + if (!isset($this->cachedFiles[$path])) { |
|
49 | + $this->cachedFiles[$path] = $this->toTmpFile($path); |
|
50 | + } |
|
51 | + return $this->cachedFiles[$path]; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $path |
|
56 | - */ |
|
57 | - protected function removeCachedFile($path) { |
|
58 | - unset($this->cachedFiles[$path]); |
|
59 | - } |
|
54 | + /** |
|
55 | + * @param string $path |
|
56 | + */ |
|
57 | + protected function removeCachedFile($path) { |
|
58 | + unset($this->cachedFiles[$path]); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param string $path |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - protected function toTmpFile($path) { //no longer in the storage api, still useful here |
|
66 | - $source = $this->fopen($path, 'r'); |
|
67 | - if (!$source) { |
|
68 | - return false; |
|
69 | - } |
|
70 | - if ($pos = strrpos($path, '.')) { |
|
71 | - $extension = substr($path, $pos); |
|
72 | - } else { |
|
73 | - $extension = ''; |
|
74 | - } |
|
75 | - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($extension); |
|
76 | - $target = fopen($tmpFile, 'w'); |
|
77 | - \OC_Helper::streamCopy($source, $target); |
|
78 | - fclose($target); |
|
79 | - return $tmpFile; |
|
80 | - } |
|
61 | + /** |
|
62 | + * @param string $path |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + protected function toTmpFile($path) { //no longer in the storage api, still useful here |
|
66 | + $source = $this->fopen($path, 'r'); |
|
67 | + if (!$source) { |
|
68 | + return false; |
|
69 | + } |
|
70 | + if ($pos = strrpos($path, '.')) { |
|
71 | + $extension = substr($path, $pos); |
|
72 | + } else { |
|
73 | + $extension = ''; |
|
74 | + } |
|
75 | + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($extension); |
|
76 | + $target = fopen($tmpFile, 'w'); |
|
77 | + \OC_Helper::streamCopy($source, $target); |
|
78 | + fclose($target); |
|
79 | + return $tmpFile; |
|
80 | + } |
|
81 | 81 | } |
@@ -29,80 +29,80 @@ |
||
29 | 29 | use OCP\Files\Storage\IStorageFactory; |
30 | 30 | |
31 | 31 | class StorageFactory implements IStorageFactory { |
32 | - /** |
|
33 | - * @var array[] [$name=>['priority'=>$priority, 'wrapper'=>$callable] $storageWrappers |
|
34 | - */ |
|
35 | - private $storageWrappers = []; |
|
32 | + /** |
|
33 | + * @var array[] [$name=>['priority'=>$priority, 'wrapper'=>$callable] $storageWrappers |
|
34 | + */ |
|
35 | + private $storageWrappers = []; |
|
36 | 36 | |
37 | - /** |
|
38 | - * allow modifier storage behaviour by adding wrappers around storages |
|
39 | - * |
|
40 | - * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage |
|
41 | - * |
|
42 | - * @param string $wrapperName name of the wrapper |
|
43 | - * @param callable $callback callback |
|
44 | - * @param int $priority wrappers with the lower priority are applied last (meaning they get called first) |
|
45 | - * @param \OCP\Files\Mount\IMountPoint[] $existingMounts existing mount points to apply the wrapper to |
|
46 | - * @return bool true if the wrapper was added, false if there was already a wrapper with this |
|
47 | - * name registered |
|
48 | - */ |
|
49 | - public function addStorageWrapper($wrapperName, $callback, $priority = 50, $existingMounts = []) { |
|
50 | - if (isset($this->storageWrappers[$wrapperName])) { |
|
51 | - return false; |
|
52 | - } |
|
37 | + /** |
|
38 | + * allow modifier storage behaviour by adding wrappers around storages |
|
39 | + * |
|
40 | + * $callback should be a function of type (string $mountPoint, Storage $storage) => Storage |
|
41 | + * |
|
42 | + * @param string $wrapperName name of the wrapper |
|
43 | + * @param callable $callback callback |
|
44 | + * @param int $priority wrappers with the lower priority are applied last (meaning they get called first) |
|
45 | + * @param \OCP\Files\Mount\IMountPoint[] $existingMounts existing mount points to apply the wrapper to |
|
46 | + * @return bool true if the wrapper was added, false if there was already a wrapper with this |
|
47 | + * name registered |
|
48 | + */ |
|
49 | + public function addStorageWrapper($wrapperName, $callback, $priority = 50, $existingMounts = []) { |
|
50 | + if (isset($this->storageWrappers[$wrapperName])) { |
|
51 | + return false; |
|
52 | + } |
|
53 | 53 | |
54 | - // apply to existing mounts before registering it to prevent applying it double in MountPoint::createStorage |
|
55 | - foreach ($existingMounts as $mount) { |
|
56 | - $mount->wrapStorage($callback); |
|
57 | - } |
|
54 | + // apply to existing mounts before registering it to prevent applying it double in MountPoint::createStorage |
|
55 | + foreach ($existingMounts as $mount) { |
|
56 | + $mount->wrapStorage($callback); |
|
57 | + } |
|
58 | 58 | |
59 | - $this->storageWrappers[$wrapperName] = ['wrapper' => $callback, 'priority' => $priority]; |
|
60 | - return true; |
|
61 | - } |
|
59 | + $this->storageWrappers[$wrapperName] = ['wrapper' => $callback, 'priority' => $priority]; |
|
60 | + return true; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Remove a storage wrapper by name. |
|
65 | - * Note: internal method only to be used for cleanup |
|
66 | - * |
|
67 | - * @param string $wrapperName name of the wrapper |
|
68 | - * @internal |
|
69 | - */ |
|
70 | - public function removeStorageWrapper($wrapperName) { |
|
71 | - unset($this->storageWrappers[$wrapperName]); |
|
72 | - } |
|
63 | + /** |
|
64 | + * Remove a storage wrapper by name. |
|
65 | + * Note: internal method only to be used for cleanup |
|
66 | + * |
|
67 | + * @param string $wrapperName name of the wrapper |
|
68 | + * @internal |
|
69 | + */ |
|
70 | + public function removeStorageWrapper($wrapperName) { |
|
71 | + unset($this->storageWrappers[$wrapperName]); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Create an instance of a storage and apply the registered storage wrappers |
|
76 | - * |
|
77 | - * @param \OCP\Files\Mount\IMountPoint $mountPoint |
|
78 | - * @param string $class |
|
79 | - * @param array $arguments |
|
80 | - * @return \OCP\Files\Storage |
|
81 | - */ |
|
82 | - public function getInstance(IMountPoint $mountPoint, $class, $arguments) { |
|
83 | - return $this->wrap($mountPoint, new $class($arguments)); |
|
84 | - } |
|
74 | + /** |
|
75 | + * Create an instance of a storage and apply the registered storage wrappers |
|
76 | + * |
|
77 | + * @param \OCP\Files\Mount\IMountPoint $mountPoint |
|
78 | + * @param string $class |
|
79 | + * @param array $arguments |
|
80 | + * @return \OCP\Files\Storage |
|
81 | + */ |
|
82 | + public function getInstance(IMountPoint $mountPoint, $class, $arguments) { |
|
83 | + return $this->wrap($mountPoint, new $class($arguments)); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @param \OCP\Files\Mount\IMountPoint $mountPoint |
|
88 | - * @param \OCP\Files\Storage $storage |
|
89 | - * @return \OCP\Files\Storage |
|
90 | - */ |
|
91 | - public function wrap(IMountPoint $mountPoint, $storage) { |
|
92 | - $wrappers = array_values($this->storageWrappers); |
|
93 | - usort($wrappers, function ($a, $b) { |
|
94 | - return $b['priority'] - $a['priority']; |
|
95 | - }); |
|
96 | - /** @var callable[] $wrappers */ |
|
97 | - $wrappers = array_map(function ($wrapper) { |
|
98 | - return $wrapper['wrapper']; |
|
99 | - }, $wrappers); |
|
100 | - foreach ($wrappers as $wrapper) { |
|
101 | - $storage = $wrapper($mountPoint->getMountPoint(), $storage, $mountPoint); |
|
102 | - if (!($storage instanceof \OCP\Files\Storage)) { |
|
103 | - throw new \Exception('Invalid result from storage wrapper'); |
|
104 | - } |
|
105 | - } |
|
106 | - return $storage; |
|
107 | - } |
|
86 | + /** |
|
87 | + * @param \OCP\Files\Mount\IMountPoint $mountPoint |
|
88 | + * @param \OCP\Files\Storage $storage |
|
89 | + * @return \OCP\Files\Storage |
|
90 | + */ |
|
91 | + public function wrap(IMountPoint $mountPoint, $storage) { |
|
92 | + $wrappers = array_values($this->storageWrappers); |
|
93 | + usort($wrappers, function ($a, $b) { |
|
94 | + return $b['priority'] - $a['priority']; |
|
95 | + }); |
|
96 | + /** @var callable[] $wrappers */ |
|
97 | + $wrappers = array_map(function ($wrapper) { |
|
98 | + return $wrapper['wrapper']; |
|
99 | + }, $wrappers); |
|
100 | + foreach ($wrappers as $wrapper) { |
|
101 | + $storage = $wrapper($mountPoint->getMountPoint(), $storage, $mountPoint); |
|
102 | + if (!($storage instanceof \OCP\Files\Storage)) { |
|
103 | + throw new \Exception('Invalid result from storage wrapper'); |
|
104 | + } |
|
105 | + } |
|
106 | + return $storage; |
|
107 | + } |
|
108 | 108 | } |