@@ -33,89 +33,89 @@ |
||
33 | 33 | * Specialized version of Local storage for home directory usage |
34 | 34 | */ |
35 | 35 | class Home extends Local implements \OCP\Files\IHomeStorage { |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $id; |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $id; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var \OC\User\User $user |
|
43 | - */ |
|
44 | - protected $user; |
|
41 | + /** |
|
42 | + * @var \OC\User\User $user |
|
43 | + */ |
|
44 | + protected $user; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Construct a Home storage instance |
|
48 | - * |
|
49 | - * @param array $arguments array with "user" containing the |
|
50 | - * storage owner |
|
51 | - */ |
|
52 | - public function __construct($arguments) { |
|
53 | - $this->user = $arguments['user']; |
|
54 | - $datadir = $this->user->getHome(); |
|
55 | - $this->id = 'home::' . $this->user->getUID(); |
|
46 | + /** |
|
47 | + * Construct a Home storage instance |
|
48 | + * |
|
49 | + * @param array $arguments array with "user" containing the |
|
50 | + * storage owner |
|
51 | + */ |
|
52 | + public function __construct($arguments) { |
|
53 | + $this->user = $arguments['user']; |
|
54 | + $datadir = $this->user->getHome(); |
|
55 | + $this->id = 'home::' . $this->user->getUID(); |
|
56 | 56 | |
57 | - try { |
|
58 | - parent::__construct(array('datadir' => $datadir)); |
|
59 | - } catch (NotFoundException $e) { |
|
60 | - if (file_exists(dirname($datadir))) { |
|
61 | - mkdir($datadir); |
|
62 | - parent::__construct(array('datadir' => $datadir)); |
|
63 | - } else { |
|
64 | - throw $e; |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
57 | + try { |
|
58 | + parent::__construct(array('datadir' => $datadir)); |
|
59 | + } catch (NotFoundException $e) { |
|
60 | + if (file_exists(dirname($datadir))) { |
|
61 | + mkdir($datadir); |
|
62 | + parent::__construct(array('datadir' => $datadir)); |
|
63 | + } else { |
|
64 | + throw $e; |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - public function getId() { |
|
70 | - return $this->id; |
|
71 | - } |
|
69 | + public function getId() { |
|
70 | + return $this->id; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return \OC\Files\Cache\HomeCache |
|
75 | - */ |
|
76 | - public function getCache($path = '', $storage = null) { |
|
77 | - if (!$storage) { |
|
78 | - $storage = $this; |
|
79 | - } |
|
80 | - if (!isset($this->cache)) { |
|
81 | - $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
82 | - } |
|
83 | - return $this->cache; |
|
84 | - } |
|
73 | + /** |
|
74 | + * @return \OC\Files\Cache\HomeCache |
|
75 | + */ |
|
76 | + public function getCache($path = '', $storage = null) { |
|
77 | + if (!$storage) { |
|
78 | + $storage = $this; |
|
79 | + } |
|
80 | + if (!isset($this->cache)) { |
|
81 | + $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
82 | + } |
|
83 | + return $this->cache; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * get a propagator instance for the cache |
|
88 | - * |
|
89 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
90 | - * @return \OC\Files\Cache\Propagator |
|
91 | - */ |
|
92 | - public function getPropagator($storage = null) { |
|
93 | - if (!$storage) { |
|
94 | - $storage = $this; |
|
95 | - } |
|
96 | - if (!isset($this->propagator)) { |
|
97 | - $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
98 | - } |
|
99 | - return $this->propagator; |
|
100 | - } |
|
86 | + /** |
|
87 | + * get a propagator instance for the cache |
|
88 | + * |
|
89 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
90 | + * @return \OC\Files\Cache\Propagator |
|
91 | + */ |
|
92 | + public function getPropagator($storage = null) { |
|
93 | + if (!$storage) { |
|
94 | + $storage = $this; |
|
95 | + } |
|
96 | + if (!isset($this->propagator)) { |
|
97 | + $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
98 | + } |
|
99 | + return $this->propagator; |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Returns the owner of this home storage |
|
105 | - * |
|
106 | - * @return \OC\User\User owner of this home storage |
|
107 | - */ |
|
108 | - public function getUser() { |
|
109 | - return $this->user; |
|
110 | - } |
|
103 | + /** |
|
104 | + * Returns the owner of this home storage |
|
105 | + * |
|
106 | + * @return \OC\User\User owner of this home storage |
|
107 | + */ |
|
108 | + public function getUser() { |
|
109 | + return $this->user; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * get the owner of a path |
|
114 | - * |
|
115 | - * @param string $path The path to get the owner |
|
116 | - * @return string uid or false |
|
117 | - */ |
|
118 | - public function getOwner($path) { |
|
119 | - return $this->user->getUID(); |
|
120 | - } |
|
112 | + /** |
|
113 | + * get the owner of a path |
|
114 | + * |
|
115 | + * @param string $path The path to get the owner |
|
116 | + * @return string uid or false |
|
117 | + */ |
|
118 | + public function getOwner($path) { |
|
119 | + return $this->user->getUID(); |
|
120 | + } |
|
121 | 121 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | public function __construct($arguments) { |
53 | 53 | $this->user = $arguments['user']; |
54 | 54 | $datadir = $this->user->getHome(); |
55 | - $this->id = 'home::' . $this->user->getUID(); |
|
55 | + $this->id = 'home::'.$this->user->getUID(); |
|
56 | 56 | |
57 | 57 | try { |
58 | 58 | parent::__construct(array('datadir' => $datadir)); |
@@ -35,247 +35,247 @@ |
||
35 | 35 | use OCP\Files\Mount\IMountPoint; |
36 | 36 | |
37 | 37 | class MountPoint implements IMountPoint { |
38 | - /** |
|
39 | - * @var \OC\Files\Storage\Storage $storage |
|
40 | - */ |
|
41 | - protected $storage = null; |
|
42 | - protected $class; |
|
43 | - protected $storageId; |
|
44 | - protected $rootId = null; |
|
38 | + /** |
|
39 | + * @var \OC\Files\Storage\Storage $storage |
|
40 | + */ |
|
41 | + protected $storage = null; |
|
42 | + protected $class; |
|
43 | + protected $storageId; |
|
44 | + protected $rootId = null; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Configuration options for the storage backend |
|
48 | - * |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - protected $arguments = array(); |
|
52 | - protected $mountPoint; |
|
46 | + /** |
|
47 | + * Configuration options for the storage backend |
|
48 | + * |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + protected $arguments = array(); |
|
52 | + protected $mountPoint; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Mount specific options |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - protected $mountOptions = array(); |
|
54 | + /** |
|
55 | + * Mount specific options |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + protected $mountOptions = array(); |
|
60 | 60 | |
61 | - /** |
|
62 | - * @var \OC\Files\Storage\StorageFactory $loader |
|
63 | - */ |
|
64 | - private $loader; |
|
61 | + /** |
|
62 | + * @var \OC\Files\Storage\StorageFactory $loader |
|
63 | + */ |
|
64 | + private $loader; |
|
65 | 65 | |
66 | - /** |
|
67 | - * Specified whether the storage is invalid after failing to |
|
68 | - * instantiate it. |
|
69 | - * |
|
70 | - * @var bool |
|
71 | - */ |
|
72 | - private $invalidStorage = false; |
|
66 | + /** |
|
67 | + * Specified whether the storage is invalid after failing to |
|
68 | + * instantiate it. |
|
69 | + * |
|
70 | + * @var bool |
|
71 | + */ |
|
72 | + private $invalidStorage = false; |
|
73 | 73 | |
74 | - /** @var int|null */ |
|
75 | - protected $mountId; |
|
74 | + /** @var int|null */ |
|
75 | + protected $mountId; |
|
76 | 76 | |
77 | - /** |
|
78 | - * @param string|\OC\Files\Storage\Storage $storage |
|
79 | - * @param string $mountpoint |
|
80 | - * @param array $arguments (optional) configuration for the storage backend |
|
81 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
82 | - * @param array $mountOptions mount specific options |
|
83 | - * @param int|null $mountId |
|
84 | - * @throws \Exception |
|
85 | - */ |
|
86 | - public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { |
|
87 | - if (is_null($arguments)) { |
|
88 | - $arguments = array(); |
|
89 | - } |
|
90 | - if (is_null($loader)) { |
|
91 | - $this->loader = new StorageFactory(); |
|
92 | - } else { |
|
93 | - $this->loader = $loader; |
|
94 | - } |
|
77 | + /** |
|
78 | + * @param string|\OC\Files\Storage\Storage $storage |
|
79 | + * @param string $mountpoint |
|
80 | + * @param array $arguments (optional) configuration for the storage backend |
|
81 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
82 | + * @param array $mountOptions mount specific options |
|
83 | + * @param int|null $mountId |
|
84 | + * @throws \Exception |
|
85 | + */ |
|
86 | + public function __construct($storage, $mountpoint, $arguments = null, $loader = null, $mountOptions = null, $mountId = null) { |
|
87 | + if (is_null($arguments)) { |
|
88 | + $arguments = array(); |
|
89 | + } |
|
90 | + if (is_null($loader)) { |
|
91 | + $this->loader = new StorageFactory(); |
|
92 | + } else { |
|
93 | + $this->loader = $loader; |
|
94 | + } |
|
95 | 95 | |
96 | - if (!is_null($mountOptions)) { |
|
97 | - $this->mountOptions = $mountOptions; |
|
98 | - } |
|
96 | + if (!is_null($mountOptions)) { |
|
97 | + $this->mountOptions = $mountOptions; |
|
98 | + } |
|
99 | 99 | |
100 | - $mountpoint = $this->formatPath($mountpoint); |
|
101 | - $this->mountPoint = $mountpoint; |
|
102 | - if ($storage instanceof Storage) { |
|
103 | - $this->class = get_class($storage); |
|
104 | - $this->storage = $this->loader->wrap($this, $storage); |
|
105 | - } else { |
|
106 | - // Update old classes to new namespace |
|
107 | - if (strpos($storage, 'OC_Filestorage_') !== false) { |
|
108 | - $storage = '\OC\Files\Storage\\' . substr($storage, 15); |
|
109 | - } |
|
110 | - $this->class = $storage; |
|
111 | - $this->arguments = $arguments; |
|
112 | - } |
|
113 | - $this->mountId = $mountId; |
|
114 | - } |
|
100 | + $mountpoint = $this->formatPath($mountpoint); |
|
101 | + $this->mountPoint = $mountpoint; |
|
102 | + if ($storage instanceof Storage) { |
|
103 | + $this->class = get_class($storage); |
|
104 | + $this->storage = $this->loader->wrap($this, $storage); |
|
105 | + } else { |
|
106 | + // Update old classes to new namespace |
|
107 | + if (strpos($storage, 'OC_Filestorage_') !== false) { |
|
108 | + $storage = '\OC\Files\Storage\\' . substr($storage, 15); |
|
109 | + } |
|
110 | + $this->class = $storage; |
|
111 | + $this->arguments = $arguments; |
|
112 | + } |
|
113 | + $this->mountId = $mountId; |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * get complete path to the mount point, relative to data/ |
|
118 | - * |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public function getMountPoint() { |
|
122 | - return $this->mountPoint; |
|
123 | - } |
|
116 | + /** |
|
117 | + * get complete path to the mount point, relative to data/ |
|
118 | + * |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public function getMountPoint() { |
|
122 | + return $this->mountPoint; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Sets the mount point path, relative to data/ |
|
127 | - * |
|
128 | - * @param string $mountPoint new mount point |
|
129 | - */ |
|
130 | - public function setMountPoint($mountPoint) { |
|
131 | - $this->mountPoint = $this->formatPath($mountPoint); |
|
132 | - } |
|
125 | + /** |
|
126 | + * Sets the mount point path, relative to data/ |
|
127 | + * |
|
128 | + * @param string $mountPoint new mount point |
|
129 | + */ |
|
130 | + public function setMountPoint($mountPoint) { |
|
131 | + $this->mountPoint = $this->formatPath($mountPoint); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * create the storage that is mounted |
|
136 | - */ |
|
137 | - private function createStorage() { |
|
138 | - if ($this->invalidStorage) { |
|
139 | - return; |
|
140 | - } |
|
134 | + /** |
|
135 | + * create the storage that is mounted |
|
136 | + */ |
|
137 | + private function createStorage() { |
|
138 | + if ($this->invalidStorage) { |
|
139 | + return; |
|
140 | + } |
|
141 | 141 | |
142 | - if (class_exists($this->class)) { |
|
143 | - try { |
|
144 | - $class = $this->class; |
|
145 | - // prevent recursion by setting the storage before applying wrappers |
|
146 | - $this->storage = new $class($this->arguments); |
|
147 | - $this->storage = $this->loader->wrap($this, $this->storage); |
|
148 | - } catch (\Exception $exception) { |
|
149 | - $this->storage = null; |
|
150 | - $this->invalidStorage = true; |
|
151 | - if ($this->mountPoint === '/') { |
|
152 | - // the root storage could not be initialized, show the user! |
|
153 | - throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception); |
|
154 | - } else { |
|
155 | - \OC::$server->getLogger()->logException($exception, ['level' => \OCP\Util::ERROR]); |
|
156 | - } |
|
157 | - return; |
|
158 | - } |
|
159 | - } else { |
|
160 | - \OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', \OCP\Util::ERROR); |
|
161 | - $this->invalidStorage = true; |
|
162 | - return; |
|
163 | - } |
|
164 | - } |
|
142 | + if (class_exists($this->class)) { |
|
143 | + try { |
|
144 | + $class = $this->class; |
|
145 | + // prevent recursion by setting the storage before applying wrappers |
|
146 | + $this->storage = new $class($this->arguments); |
|
147 | + $this->storage = $this->loader->wrap($this, $this->storage); |
|
148 | + } catch (\Exception $exception) { |
|
149 | + $this->storage = null; |
|
150 | + $this->invalidStorage = true; |
|
151 | + if ($this->mountPoint === '/') { |
|
152 | + // the root storage could not be initialized, show the user! |
|
153 | + throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception); |
|
154 | + } else { |
|
155 | + \OC::$server->getLogger()->logException($exception, ['level' => \OCP\Util::ERROR]); |
|
156 | + } |
|
157 | + return; |
|
158 | + } |
|
159 | + } else { |
|
160 | + \OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', \OCP\Util::ERROR); |
|
161 | + $this->invalidStorage = true; |
|
162 | + return; |
|
163 | + } |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * @return \OC\Files\Storage\Storage |
|
168 | - */ |
|
169 | - public function getStorage() { |
|
170 | - if (is_null($this->storage)) { |
|
171 | - $this->createStorage(); |
|
172 | - } |
|
173 | - return $this->storage; |
|
174 | - } |
|
166 | + /** |
|
167 | + * @return \OC\Files\Storage\Storage |
|
168 | + */ |
|
169 | + public function getStorage() { |
|
170 | + if (is_null($this->storage)) { |
|
171 | + $this->createStorage(); |
|
172 | + } |
|
173 | + return $this->storage; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - public function getStorageId() { |
|
180 | - if (!$this->storageId) { |
|
181 | - if (is_null($this->storage)) { |
|
182 | - $storage = $this->createStorage(); //FIXME: start using exceptions |
|
183 | - if (is_null($storage)) { |
|
184 | - return null; |
|
185 | - } |
|
176 | + /** |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + public function getStorageId() { |
|
180 | + if (!$this->storageId) { |
|
181 | + if (is_null($this->storage)) { |
|
182 | + $storage = $this->createStorage(); //FIXME: start using exceptions |
|
183 | + if (is_null($storage)) { |
|
184 | + return null; |
|
185 | + } |
|
186 | 186 | |
187 | - $this->storage = $storage; |
|
188 | - } |
|
189 | - $this->storageId = $this->storage->getId(); |
|
190 | - if (strlen($this->storageId) > 64) { |
|
191 | - $this->storageId = md5($this->storageId); |
|
192 | - } |
|
193 | - } |
|
194 | - return $this->storageId; |
|
195 | - } |
|
187 | + $this->storage = $storage; |
|
188 | + } |
|
189 | + $this->storageId = $this->storage->getId(); |
|
190 | + if (strlen($this->storageId) > 64) { |
|
191 | + $this->storageId = md5($this->storageId); |
|
192 | + } |
|
193 | + } |
|
194 | + return $this->storageId; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @return int |
|
199 | - */ |
|
200 | - public function getNumericStorageId() { |
|
201 | - return $this->getStorage()->getStorageCache()->getNumericId(); |
|
202 | - } |
|
197 | + /** |
|
198 | + * @return int |
|
199 | + */ |
|
200 | + public function getNumericStorageId() { |
|
201 | + return $this->getStorage()->getStorageCache()->getNumericId(); |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * @param string $path |
|
206 | - * @return string |
|
207 | - */ |
|
208 | - public function getInternalPath($path) { |
|
209 | - $path = Filesystem::normalizePath($path, true, false, true); |
|
210 | - if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) { |
|
211 | - $internalPath = ''; |
|
212 | - } else { |
|
213 | - $internalPath = substr($path, strlen($this->mountPoint)); |
|
214 | - } |
|
215 | - // substr returns false instead of an empty string, we always want a string |
|
216 | - return (string)$internalPath; |
|
217 | - } |
|
204 | + /** |
|
205 | + * @param string $path |
|
206 | + * @return string |
|
207 | + */ |
|
208 | + public function getInternalPath($path) { |
|
209 | + $path = Filesystem::normalizePath($path, true, false, true); |
|
210 | + if ($this->mountPoint === $path or $this->mountPoint . '/' === $path) { |
|
211 | + $internalPath = ''; |
|
212 | + } else { |
|
213 | + $internalPath = substr($path, strlen($this->mountPoint)); |
|
214 | + } |
|
215 | + // substr returns false instead of an empty string, we always want a string |
|
216 | + return (string)$internalPath; |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @param string $path |
|
221 | - * @return string |
|
222 | - */ |
|
223 | - private function formatPath($path) { |
|
224 | - $path = Filesystem::normalizePath($path); |
|
225 | - if (strlen($path) > 1) { |
|
226 | - $path .= '/'; |
|
227 | - } |
|
228 | - return $path; |
|
229 | - } |
|
219 | + /** |
|
220 | + * @param string $path |
|
221 | + * @return string |
|
222 | + */ |
|
223 | + private function formatPath($path) { |
|
224 | + $path = Filesystem::normalizePath($path); |
|
225 | + if (strlen($path) > 1) { |
|
226 | + $path .= '/'; |
|
227 | + } |
|
228 | + return $path; |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * @param callable $wrapper |
|
233 | - */ |
|
234 | - public function wrapStorage($wrapper) { |
|
235 | - $storage = $this->getStorage(); |
|
236 | - // storage can be null if it couldn't be initialized |
|
237 | - if ($storage != null) { |
|
238 | - $this->storage = $wrapper($this->mountPoint, $storage, $this); |
|
239 | - } |
|
240 | - } |
|
231 | + /** |
|
232 | + * @param callable $wrapper |
|
233 | + */ |
|
234 | + public function wrapStorage($wrapper) { |
|
235 | + $storage = $this->getStorage(); |
|
236 | + // storage can be null if it couldn't be initialized |
|
237 | + if ($storage != null) { |
|
238 | + $this->storage = $wrapper($this->mountPoint, $storage, $this); |
|
239 | + } |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * Get a mount option |
|
244 | - * |
|
245 | - * @param string $name Name of the mount option to get |
|
246 | - * @param mixed $default Default value for the mount option |
|
247 | - * @return mixed |
|
248 | - */ |
|
249 | - public function getOption($name, $default) { |
|
250 | - return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; |
|
251 | - } |
|
242 | + /** |
|
243 | + * Get a mount option |
|
244 | + * |
|
245 | + * @param string $name Name of the mount option to get |
|
246 | + * @param mixed $default Default value for the mount option |
|
247 | + * @return mixed |
|
248 | + */ |
|
249 | + public function getOption($name, $default) { |
|
250 | + return isset($this->mountOptions[$name]) ? $this->mountOptions[$name] : $default; |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * Get all options for the mount |
|
255 | - * |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - public function getOptions() { |
|
259 | - return $this->mountOptions; |
|
260 | - } |
|
253 | + /** |
|
254 | + * Get all options for the mount |
|
255 | + * |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + public function getOptions() { |
|
259 | + return $this->mountOptions; |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * Get the file id of the root of the storage |
|
264 | - * |
|
265 | - * @return int |
|
266 | - */ |
|
267 | - public function getStorageRootId() { |
|
268 | - if (is_null($this->rootId)) { |
|
269 | - $this->rootId = (int)$this->getStorage()->getCache()->getId(''); |
|
270 | - } |
|
271 | - return $this->rootId; |
|
272 | - } |
|
262 | + /** |
|
263 | + * Get the file id of the root of the storage |
|
264 | + * |
|
265 | + * @return int |
|
266 | + */ |
|
267 | + public function getStorageRootId() { |
|
268 | + if (is_null($this->rootId)) { |
|
269 | + $this->rootId = (int)$this->getStorage()->getCache()->getId(''); |
|
270 | + } |
|
271 | + return $this->rootId; |
|
272 | + } |
|
273 | 273 | |
274 | - public function getMountId() { |
|
275 | - return $this->mountId; |
|
276 | - } |
|
274 | + public function getMountId() { |
|
275 | + return $this->mountId; |
|
276 | + } |
|
277 | 277 | |
278 | - public function getMountType() { |
|
279 | - return ''; |
|
280 | - } |
|
278 | + public function getMountType() { |
|
279 | + return ''; |
|
280 | + } |
|
281 | 281 | } |
@@ -24,144 +24,144 @@ |
||
24 | 24 | namespace OC\App\CodeChecker; |
25 | 25 | |
26 | 26 | class DeprecationCheck extends AbstractCheck implements ICheck { |
27 | - /** |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - protected function getLocalDescription() { |
|
31 | - return 'deprecated'; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @return array E.g.: `'ClassName' => 'oc version',` |
|
36 | - */ |
|
37 | - protected function getLocalClasses() { |
|
38 | - return [ |
|
39 | - 'OC_JSON' => '8.2.0', |
|
40 | - |
|
41 | - 'OCP\Contacts' => '8.1.0', |
|
42 | - 'OCP\DB' => '8.1.0', |
|
43 | - 'OCP\IHelper' => '8.1.0', |
|
44 | - 'OCP\JSON' => '8.1.0', |
|
45 | - 'OCP\Response' => '8.1.0', |
|
46 | - 'OCP\AppFramework\IApi' => '8.0.0', |
|
47 | - 'OCP\User' => '13.0.0', |
|
48 | - ]; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` |
|
53 | - */ |
|
54 | - protected function getLocalConstants() { |
|
55 | - return [ |
|
56 | - 'OC_API::GUEST_AUTH' => '8.2.0', |
|
57 | - 'OC_API::USER_AUTH' => '8.2.0', |
|
58 | - 'OC_API::SUBADMIN_AUTH' => '8.2.0', |
|
59 | - 'OC_API::ADMIN_AUTH' => '8.2.0', |
|
60 | - 'OC_API::RESPOND_UNAUTHORISED' => '8.2.0', |
|
61 | - 'OC_API::RESPOND_SERVER_ERROR' => '8.2.0', |
|
62 | - 'OC_API::RESPOND_NOT_FOUND' => '8.2.0', |
|
63 | - 'OC_API::RESPOND_UNKNOWN_ERROR' => '8.2.0', |
|
64 | - |
|
65 | - 'OCP::PERMISSION_CREATE' => '8.0.0', |
|
66 | - 'OCP::PERMISSION_READ' => '8.0.0', |
|
67 | - 'OCP::PERMISSION_UPDATE' => '8.0.0', |
|
68 | - 'OCP::PERMISSION_DELETE' => '8.0.0', |
|
69 | - 'OCP::PERMISSION_SHARE' => '8.0.0', |
|
70 | - 'OCP::PERMISSION_ALL' => '8.0.0', |
|
71 | - 'OCP::FILENAME_INVALID_CHARS' => '8.0.0', |
|
72 | - ]; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @return array E.g.: `'functionName' => 'oc version',` |
|
77 | - */ |
|
78 | - protected function getLocalFunctions() { |
|
79 | - return [ |
|
80 | - 'OCP::image_path' => '8.0.0', |
|
81 | - 'OCP::mimetype_icon' => '8.0.0', |
|
82 | - 'OCP::preview_icon' => '8.0.0', |
|
83 | - 'OCP::publicPreview_icon' => '8.0.0', |
|
84 | - 'OCP::human_file_size' => '8.0.0', |
|
85 | - 'OCP::relative_modified_date' => '8.0.0', |
|
86 | - 'OCP::simple_file_size' => '8.0.0', |
|
87 | - 'OCP::html_select_options' => '8.0.0', |
|
88 | - ]; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @return array E.g.: `'ClassName::methodName' => 'oc version',` |
|
93 | - */ |
|
94 | - protected function getLocalMethods() { |
|
95 | - return [ |
|
96 | - 'OC_L10N::get' => '8.2.0', |
|
97 | - |
|
98 | - 'OCP\Activity\IManager::publishActivity' => '8.2.0', |
|
99 | - |
|
100 | - 'OCP\App::register' => '8.1.0', |
|
101 | - 'OCP\App::addNavigationEntry' => '8.1.0', |
|
102 | - 'OCP\App::getActiveNavigationEntry' => '8.2.0', |
|
103 | - 'OCP\App::setActiveNavigationEntry' => '8.1.0', |
|
104 | - |
|
105 | - 'OCP\AppFramework\Controller::params' => '7.0.0', |
|
106 | - 'OCP\AppFramework\Controller::getParams' => '7.0.0', |
|
107 | - 'OCP\AppFramework\Controller::method' => '7.0.0', |
|
108 | - 'OCP\AppFramework\Controller::getUploadedFile' => '7.0.0', |
|
109 | - 'OCP\AppFramework\Controller::env' => '7.0.0', |
|
110 | - 'OCP\AppFramework\Controller::cookie' => '7.0.0', |
|
111 | - 'OCP\AppFramework\Controller::render' => '7.0.0', |
|
112 | - |
|
113 | - 'OCP\AppFramework\IAppContainer::getCoreApi' => '8.0.0', |
|
114 | - 'OCP\AppFramework\IAppContainer::isLoggedIn' => '8.0.0', |
|
115 | - 'OCP\AppFramework\IAppContainer::isAdminUser' => '8.0.0', |
|
116 | - 'OCP\AppFramework\IAppContainer::log' => '8.0.0', |
|
117 | - |
|
118 | - 'OCP\BackgroundJob::registerJob' => '8.1.0', |
|
119 | - |
|
120 | - 'OCP\Files::tmpFile' => '8.1.0', |
|
121 | - 'OCP\Files::tmpFolder' => '8.1.0', |
|
122 | - |
|
123 | - 'OCP\IAppConfig::getValue' => '8.0.0', |
|
124 | - 'OCP\IAppConfig::deleteKey' => '8.0.0', |
|
125 | - 'OCP\IAppConfig::getKeys' => '8.0.0', |
|
126 | - 'OCP\IAppConfig::setValue' => '8.0.0', |
|
127 | - 'OCP\IAppConfig::deleteApp' => '8.0.0', |
|
128 | - |
|
129 | - 'OCP\IDBConnection::createQueryBuilder' => '8.2.0', |
|
130 | - 'OCP\IDBConnection::getExpressionBuilder' => '8.2.0', |
|
131 | - |
|
132 | - 'OCP\ISearch::search' => '8.0.0', |
|
133 | - |
|
134 | - 'OCP\IServerContainer::getCache' => '8.2.0', |
|
135 | - 'OCP\IServerContainer::getDb' => '8.1.0', |
|
136 | - 'OCP\IServerContainer::getHTTPHelper' => '8.1.0', |
|
137 | - |
|
138 | - 'OCP\User::getUser' => '8.0.0', |
|
139 | - 'OCP\User::getUsers' => '8.1.0', |
|
140 | - 'OCP\User::getDisplayName' => '8.1.0', |
|
141 | - 'OCP\User::getDisplayNames' => '8.1.0', |
|
142 | - 'OCP\User::userExists' => '8.1.0', |
|
143 | - 'OCP\User::logout' => '8.1.0', |
|
144 | - 'OCP\User::checkPassword' => '8.1.0', |
|
145 | - 'OCP\User::isLoggedIn' => '13.0.0', |
|
146 | - 'OCP\User::checkAdminUser' => '13.0.0', |
|
147 | - 'OCP\User::checkLoggedIn' => '13.0.0', |
|
148 | - |
|
149 | - 'OCP\Util::encryptedFiles' => '8.1.0', |
|
150 | - 'OCP\Util::formatDate' => '8.0.0', |
|
151 | - 'OCP\Util::generateRandomBytes' => '8.1.0', |
|
152 | - 'OCP\Util::getServerHost' => '8.1.0', |
|
153 | - 'OCP\Util::getServerProtocol' => '8.1.0', |
|
154 | - 'OCP\Util::getRequestUri' => '8.1.0', |
|
155 | - 'OCP\Util::getScriptName' => '8.1.0', |
|
156 | - 'OCP\Util::imagePath' => '8.1.0', |
|
157 | - 'OCP\Util::isValidFileName' => '8.1.0', |
|
158 | - 'OCP\Util::linkToRoute' => '8.1.0', |
|
159 | - 'OCP\Util::linkTo' => '8.1.0', |
|
160 | - 'OCP\Util::logException' => '8.2.0', |
|
161 | - 'OCP\Util::mb_str_replace' => '8.2.0', |
|
162 | - 'OCP\Util::mb_substr_replace' => '8.2.0', |
|
163 | - 'OCP\Util::sendMail' => '8.1.0', |
|
164 | - 'OCP\Util::writeLog' => '13.0.0', |
|
165 | - ]; |
|
166 | - } |
|
27 | + /** |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + protected function getLocalDescription() { |
|
31 | + return 'deprecated'; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @return array E.g.: `'ClassName' => 'oc version',` |
|
36 | + */ |
|
37 | + protected function getLocalClasses() { |
|
38 | + return [ |
|
39 | + 'OC_JSON' => '8.2.0', |
|
40 | + |
|
41 | + 'OCP\Contacts' => '8.1.0', |
|
42 | + 'OCP\DB' => '8.1.0', |
|
43 | + 'OCP\IHelper' => '8.1.0', |
|
44 | + 'OCP\JSON' => '8.1.0', |
|
45 | + 'OCP\Response' => '8.1.0', |
|
46 | + 'OCP\AppFramework\IApi' => '8.0.0', |
|
47 | + 'OCP\User' => '13.0.0', |
|
48 | + ]; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @return array E.g.: `'ClassName::CONSTANT_NAME' => 'oc version',` |
|
53 | + */ |
|
54 | + protected function getLocalConstants() { |
|
55 | + return [ |
|
56 | + 'OC_API::GUEST_AUTH' => '8.2.0', |
|
57 | + 'OC_API::USER_AUTH' => '8.2.0', |
|
58 | + 'OC_API::SUBADMIN_AUTH' => '8.2.0', |
|
59 | + 'OC_API::ADMIN_AUTH' => '8.2.0', |
|
60 | + 'OC_API::RESPOND_UNAUTHORISED' => '8.2.0', |
|
61 | + 'OC_API::RESPOND_SERVER_ERROR' => '8.2.0', |
|
62 | + 'OC_API::RESPOND_NOT_FOUND' => '8.2.0', |
|
63 | + 'OC_API::RESPOND_UNKNOWN_ERROR' => '8.2.0', |
|
64 | + |
|
65 | + 'OCP::PERMISSION_CREATE' => '8.0.0', |
|
66 | + 'OCP::PERMISSION_READ' => '8.0.0', |
|
67 | + 'OCP::PERMISSION_UPDATE' => '8.0.0', |
|
68 | + 'OCP::PERMISSION_DELETE' => '8.0.0', |
|
69 | + 'OCP::PERMISSION_SHARE' => '8.0.0', |
|
70 | + 'OCP::PERMISSION_ALL' => '8.0.0', |
|
71 | + 'OCP::FILENAME_INVALID_CHARS' => '8.0.0', |
|
72 | + ]; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @return array E.g.: `'functionName' => 'oc version',` |
|
77 | + */ |
|
78 | + protected function getLocalFunctions() { |
|
79 | + return [ |
|
80 | + 'OCP::image_path' => '8.0.0', |
|
81 | + 'OCP::mimetype_icon' => '8.0.0', |
|
82 | + 'OCP::preview_icon' => '8.0.0', |
|
83 | + 'OCP::publicPreview_icon' => '8.0.0', |
|
84 | + 'OCP::human_file_size' => '8.0.0', |
|
85 | + 'OCP::relative_modified_date' => '8.0.0', |
|
86 | + 'OCP::simple_file_size' => '8.0.0', |
|
87 | + 'OCP::html_select_options' => '8.0.0', |
|
88 | + ]; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @return array E.g.: `'ClassName::methodName' => 'oc version',` |
|
93 | + */ |
|
94 | + protected function getLocalMethods() { |
|
95 | + return [ |
|
96 | + 'OC_L10N::get' => '8.2.0', |
|
97 | + |
|
98 | + 'OCP\Activity\IManager::publishActivity' => '8.2.0', |
|
99 | + |
|
100 | + 'OCP\App::register' => '8.1.0', |
|
101 | + 'OCP\App::addNavigationEntry' => '8.1.0', |
|
102 | + 'OCP\App::getActiveNavigationEntry' => '8.2.0', |
|
103 | + 'OCP\App::setActiveNavigationEntry' => '8.1.0', |
|
104 | + |
|
105 | + 'OCP\AppFramework\Controller::params' => '7.0.0', |
|
106 | + 'OCP\AppFramework\Controller::getParams' => '7.0.0', |
|
107 | + 'OCP\AppFramework\Controller::method' => '7.0.0', |
|
108 | + 'OCP\AppFramework\Controller::getUploadedFile' => '7.0.0', |
|
109 | + 'OCP\AppFramework\Controller::env' => '7.0.0', |
|
110 | + 'OCP\AppFramework\Controller::cookie' => '7.0.0', |
|
111 | + 'OCP\AppFramework\Controller::render' => '7.0.0', |
|
112 | + |
|
113 | + 'OCP\AppFramework\IAppContainer::getCoreApi' => '8.0.0', |
|
114 | + 'OCP\AppFramework\IAppContainer::isLoggedIn' => '8.0.0', |
|
115 | + 'OCP\AppFramework\IAppContainer::isAdminUser' => '8.0.0', |
|
116 | + 'OCP\AppFramework\IAppContainer::log' => '8.0.0', |
|
117 | + |
|
118 | + 'OCP\BackgroundJob::registerJob' => '8.1.0', |
|
119 | + |
|
120 | + 'OCP\Files::tmpFile' => '8.1.0', |
|
121 | + 'OCP\Files::tmpFolder' => '8.1.0', |
|
122 | + |
|
123 | + 'OCP\IAppConfig::getValue' => '8.0.0', |
|
124 | + 'OCP\IAppConfig::deleteKey' => '8.0.0', |
|
125 | + 'OCP\IAppConfig::getKeys' => '8.0.0', |
|
126 | + 'OCP\IAppConfig::setValue' => '8.0.0', |
|
127 | + 'OCP\IAppConfig::deleteApp' => '8.0.0', |
|
128 | + |
|
129 | + 'OCP\IDBConnection::createQueryBuilder' => '8.2.0', |
|
130 | + 'OCP\IDBConnection::getExpressionBuilder' => '8.2.0', |
|
131 | + |
|
132 | + 'OCP\ISearch::search' => '8.0.0', |
|
133 | + |
|
134 | + 'OCP\IServerContainer::getCache' => '8.2.0', |
|
135 | + 'OCP\IServerContainer::getDb' => '8.1.0', |
|
136 | + 'OCP\IServerContainer::getHTTPHelper' => '8.1.0', |
|
137 | + |
|
138 | + 'OCP\User::getUser' => '8.0.0', |
|
139 | + 'OCP\User::getUsers' => '8.1.0', |
|
140 | + 'OCP\User::getDisplayName' => '8.1.0', |
|
141 | + 'OCP\User::getDisplayNames' => '8.1.0', |
|
142 | + 'OCP\User::userExists' => '8.1.0', |
|
143 | + 'OCP\User::logout' => '8.1.0', |
|
144 | + 'OCP\User::checkPassword' => '8.1.0', |
|
145 | + 'OCP\User::isLoggedIn' => '13.0.0', |
|
146 | + 'OCP\User::checkAdminUser' => '13.0.0', |
|
147 | + 'OCP\User::checkLoggedIn' => '13.0.0', |
|
148 | + |
|
149 | + 'OCP\Util::encryptedFiles' => '8.1.0', |
|
150 | + 'OCP\Util::formatDate' => '8.0.0', |
|
151 | + 'OCP\Util::generateRandomBytes' => '8.1.0', |
|
152 | + 'OCP\Util::getServerHost' => '8.1.0', |
|
153 | + 'OCP\Util::getServerProtocol' => '8.1.0', |
|
154 | + 'OCP\Util::getRequestUri' => '8.1.0', |
|
155 | + 'OCP\Util::getScriptName' => '8.1.0', |
|
156 | + 'OCP\Util::imagePath' => '8.1.0', |
|
157 | + 'OCP\Util::isValidFileName' => '8.1.0', |
|
158 | + 'OCP\Util::linkToRoute' => '8.1.0', |
|
159 | + 'OCP\Util::linkTo' => '8.1.0', |
|
160 | + 'OCP\Util::logException' => '8.2.0', |
|
161 | + 'OCP\Util::mb_str_replace' => '8.2.0', |
|
162 | + 'OCP\Util::mb_substr_replace' => '8.2.0', |
|
163 | + 'OCP\Util::sendMail' => '8.1.0', |
|
164 | + 'OCP\Util::writeLog' => '13.0.0', |
|
165 | + ]; |
|
166 | + } |
|
167 | 167 | } |
@@ -48,421 +48,421 @@ |
||
48 | 48 | * for local filestore, we only have to map the paths |
49 | 49 | */ |
50 | 50 | class Local extends \OC\Files\Storage\Common { |
51 | - protected $datadir; |
|
52 | - |
|
53 | - protected $dataDirLength; |
|
54 | - |
|
55 | - protected $allowSymlinks = false; |
|
56 | - |
|
57 | - protected $realDataDir; |
|
58 | - |
|
59 | - public function __construct($arguments) { |
|
60 | - if (!isset($arguments['datadir']) || !is_string($arguments['datadir'])) { |
|
61 | - throw new \InvalidArgumentException('No data directory set for local storage'); |
|
62 | - } |
|
63 | - $this->datadir = $arguments['datadir']; |
|
64 | - // some crazy code uses a local storage on root... |
|
65 | - if ($this->datadir === '/') { |
|
66 | - $this->realDataDir = $this->datadir; |
|
67 | - } else { |
|
68 | - $realPath = realpath($this->datadir); |
|
69 | - if (!$realPath) { |
|
70 | - throw new NotFoundException('Data directory not found: ' . $this->datadir); |
|
71 | - } |
|
72 | - $this->realDataDir = rtrim($realPath, '/') . '/'; |
|
73 | - } |
|
74 | - if (substr($this->datadir, -1) !== '/') { |
|
75 | - $this->datadir .= '/'; |
|
76 | - } |
|
77 | - $this->dataDirLength = strlen($this->realDataDir); |
|
78 | - } |
|
79 | - |
|
80 | - public function __destruct() { |
|
81 | - } |
|
82 | - |
|
83 | - public function getId() { |
|
84 | - return 'local::' . $this->datadir; |
|
85 | - } |
|
86 | - |
|
87 | - public function mkdir($path) { |
|
88 | - return @mkdir($this->getSourcePath($path), 0777, true); |
|
89 | - } |
|
90 | - |
|
91 | - public function rmdir($path) { |
|
92 | - if (!$this->isDeletable($path)) { |
|
93 | - return false; |
|
94 | - } |
|
95 | - try { |
|
96 | - $it = new \RecursiveIteratorIterator( |
|
97 | - new \RecursiveDirectoryIterator($this->getSourcePath($path)), |
|
98 | - \RecursiveIteratorIterator::CHILD_FIRST |
|
99 | - ); |
|
100 | - /** |
|
101 | - * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach |
|
102 | - * This bug is fixed in PHP 5.5.9 or before |
|
103 | - * See #8376 |
|
104 | - */ |
|
105 | - $it->rewind(); |
|
106 | - while ($it->valid()) { |
|
107 | - /** |
|
108 | - * @var \SplFileInfo $file |
|
109 | - */ |
|
110 | - $file = $it->current(); |
|
111 | - if (in_array($file->getBasename(), array('.', '..'))) { |
|
112 | - $it->next(); |
|
113 | - continue; |
|
114 | - } elseif ($file->isDir()) { |
|
115 | - rmdir($file->getPathname()); |
|
116 | - } elseif ($file->isFile() || $file->isLink()) { |
|
117 | - unlink($file->getPathname()); |
|
118 | - } |
|
119 | - $it->next(); |
|
120 | - } |
|
121 | - return rmdir($this->getSourcePath($path)); |
|
122 | - } catch (\UnexpectedValueException $e) { |
|
123 | - return false; |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - public function opendir($path) { |
|
128 | - return opendir($this->getSourcePath($path)); |
|
129 | - } |
|
130 | - |
|
131 | - public function is_dir($path) { |
|
132 | - if (substr($path, -1) == '/') { |
|
133 | - $path = substr($path, 0, -1); |
|
134 | - } |
|
135 | - return is_dir($this->getSourcePath($path)); |
|
136 | - } |
|
137 | - |
|
138 | - public function is_file($path) { |
|
139 | - return is_file($this->getSourcePath($path)); |
|
140 | - } |
|
141 | - |
|
142 | - public function stat($path) { |
|
143 | - clearstatcache(); |
|
144 | - $fullPath = $this->getSourcePath($path); |
|
145 | - $statResult = stat($fullPath); |
|
146 | - if (PHP_INT_SIZE === 4 && !$this->is_dir($path)) { |
|
147 | - $filesize = $this->filesize($path); |
|
148 | - $statResult['size'] = $filesize; |
|
149 | - $statResult[7] = $filesize; |
|
150 | - } |
|
151 | - return $statResult; |
|
152 | - } |
|
153 | - |
|
154 | - public function filetype($path) { |
|
155 | - $filetype = filetype($this->getSourcePath($path)); |
|
156 | - if ($filetype == 'link') { |
|
157 | - $filetype = filetype(realpath($this->getSourcePath($path))); |
|
158 | - } |
|
159 | - return $filetype; |
|
160 | - } |
|
161 | - |
|
162 | - public function filesize($path) { |
|
163 | - if ($this->is_dir($path)) { |
|
164 | - return 0; |
|
165 | - } |
|
166 | - $fullPath = $this->getSourcePath($path); |
|
167 | - if (PHP_INT_SIZE === 4) { |
|
168 | - $helper = new \OC\LargeFileHelper; |
|
169 | - return $helper->getFileSize($fullPath); |
|
170 | - } |
|
171 | - return filesize($fullPath); |
|
172 | - } |
|
173 | - |
|
174 | - public function isReadable($path) { |
|
175 | - return is_readable($this->getSourcePath($path)); |
|
176 | - } |
|
177 | - |
|
178 | - public function isUpdatable($path) { |
|
179 | - return is_writable($this->getSourcePath($path)); |
|
180 | - } |
|
181 | - |
|
182 | - public function file_exists($path) { |
|
183 | - return file_exists($this->getSourcePath($path)); |
|
184 | - } |
|
185 | - |
|
186 | - public function filemtime($path) { |
|
187 | - $fullPath = $this->getSourcePath($path); |
|
188 | - clearstatcache(true, $fullPath); |
|
189 | - if (!$this->file_exists($path)) { |
|
190 | - return false; |
|
191 | - } |
|
192 | - if (PHP_INT_SIZE === 4) { |
|
193 | - $helper = new \OC\LargeFileHelper(); |
|
194 | - return $helper->getFileMtime($fullPath); |
|
195 | - } |
|
196 | - return filemtime($fullPath); |
|
197 | - } |
|
198 | - |
|
199 | - public function touch($path, $mtime = null) { |
|
200 | - // sets the modification time of the file to the given value. |
|
201 | - // If mtime is nil the current time is set. |
|
202 | - // note that the access time of the file always changes to the current time. |
|
203 | - if ($this->file_exists($path) and !$this->isUpdatable($path)) { |
|
204 | - return false; |
|
205 | - } |
|
206 | - if (!is_null($mtime)) { |
|
207 | - $result = touch($this->getSourcePath($path), $mtime); |
|
208 | - } else { |
|
209 | - $result = touch($this->getSourcePath($path)); |
|
210 | - } |
|
211 | - if ($result) { |
|
212 | - clearstatcache(true, $this->getSourcePath($path)); |
|
213 | - } |
|
214 | - |
|
215 | - return $result; |
|
216 | - } |
|
217 | - |
|
218 | - public function file_get_contents($path) { |
|
219 | - return file_get_contents($this->getSourcePath($path)); |
|
220 | - } |
|
221 | - |
|
222 | - public function file_put_contents($path, $data) { |
|
223 | - return file_put_contents($this->getSourcePath($path), $data); |
|
224 | - } |
|
225 | - |
|
226 | - public function unlink($path) { |
|
227 | - if ($this->is_dir($path)) { |
|
228 | - return $this->rmdir($path); |
|
229 | - } else if ($this->is_file($path)) { |
|
230 | - return unlink($this->getSourcePath($path)); |
|
231 | - } else { |
|
232 | - return false; |
|
233 | - } |
|
234 | - |
|
235 | - } |
|
236 | - |
|
237 | - public function rename($path1, $path2) { |
|
238 | - $srcParent = dirname($path1); |
|
239 | - $dstParent = dirname($path2); |
|
240 | - |
|
241 | - if (!$this->isUpdatable($srcParent)) { |
|
242 | - \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, \OCP\Util::ERROR); |
|
243 | - return false; |
|
244 | - } |
|
245 | - |
|
246 | - if (!$this->isUpdatable($dstParent)) { |
|
247 | - \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, \OCP\Util::ERROR); |
|
248 | - return false; |
|
249 | - } |
|
250 | - |
|
251 | - if (!$this->file_exists($path1)) { |
|
252 | - \OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, \OCP\Util::ERROR); |
|
253 | - return false; |
|
254 | - } |
|
255 | - |
|
256 | - if ($this->is_dir($path2)) { |
|
257 | - $this->rmdir($path2); |
|
258 | - } else if ($this->is_file($path2)) { |
|
259 | - $this->unlink($path2); |
|
260 | - } |
|
261 | - |
|
262 | - if ($this->is_dir($path1)) { |
|
263 | - // we can't move folders across devices, use copy instead |
|
264 | - $stat1 = stat(dirname($this->getSourcePath($path1))); |
|
265 | - $stat2 = stat(dirname($this->getSourcePath($path2))); |
|
266 | - if ($stat1['dev'] !== $stat2['dev']) { |
|
267 | - $result = $this->copy($path1, $path2); |
|
268 | - if ($result) { |
|
269 | - $result &= $this->rmdir($path1); |
|
270 | - } |
|
271 | - return $result; |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - return rename($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
276 | - } |
|
277 | - |
|
278 | - public function copy($path1, $path2) { |
|
279 | - if ($this->is_dir($path1)) { |
|
280 | - return parent::copy($path1, $path2); |
|
281 | - } else { |
|
282 | - return copy($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
283 | - } |
|
284 | - } |
|
285 | - |
|
286 | - public function fopen($path, $mode) { |
|
287 | - return fopen($this->getSourcePath($path), $mode); |
|
288 | - } |
|
289 | - |
|
290 | - public function hash($type, $path, $raw = false) { |
|
291 | - return hash_file($type, $this->getSourcePath($path), $raw); |
|
292 | - } |
|
293 | - |
|
294 | - public function free_space($path) { |
|
295 | - $sourcePath = $this->getSourcePath($path); |
|
296 | - // using !is_dir because $sourcePath might be a part file or |
|
297 | - // non-existing file, so we'd still want to use the parent dir |
|
298 | - // in such cases |
|
299 | - if (!is_dir($sourcePath)) { |
|
300 | - // disk_free_space doesn't work on files |
|
301 | - $sourcePath = dirname($sourcePath); |
|
302 | - } |
|
303 | - $space = @disk_free_space($sourcePath); |
|
304 | - if ($space === false || is_null($space)) { |
|
305 | - return \OCP\Files\FileInfo::SPACE_UNKNOWN; |
|
306 | - } |
|
307 | - return $space; |
|
308 | - } |
|
309 | - |
|
310 | - public function search($query) { |
|
311 | - return $this->searchInDir($query); |
|
312 | - } |
|
313 | - |
|
314 | - public function getLocalFile($path) { |
|
315 | - return $this->getSourcePath($path); |
|
316 | - } |
|
317 | - |
|
318 | - public function getLocalFolder($path) { |
|
319 | - return $this->getSourcePath($path); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * @param string $query |
|
324 | - * @param string $dir |
|
325 | - * @return array |
|
326 | - */ |
|
327 | - protected function searchInDir($query, $dir = '') { |
|
328 | - $files = array(); |
|
329 | - $physicalDir = $this->getSourcePath($dir); |
|
330 | - foreach (scandir($physicalDir) as $item) { |
|
331 | - if (\OC\Files\Filesystem::isIgnoredDir($item)) |
|
332 | - continue; |
|
333 | - $physicalItem = $physicalDir . '/' . $item; |
|
334 | - |
|
335 | - if (strstr(strtolower($item), strtolower($query)) !== false) { |
|
336 | - $files[] = $dir . '/' . $item; |
|
337 | - } |
|
338 | - if (is_dir($physicalItem)) { |
|
339 | - $files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item)); |
|
340 | - } |
|
341 | - } |
|
342 | - return $files; |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * check if a file or folder has been updated since $time |
|
347 | - * |
|
348 | - * @param string $path |
|
349 | - * @param int $time |
|
350 | - * @return bool |
|
351 | - */ |
|
352 | - public function hasUpdated($path, $time) { |
|
353 | - if ($this->file_exists($path)) { |
|
354 | - return $this->filemtime($path) > $time; |
|
355 | - } else { |
|
356 | - return true; |
|
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Get the source path (on disk) of a given path |
|
362 | - * |
|
363 | - * @param string $path |
|
364 | - * @return string |
|
365 | - * @throws ForbiddenException |
|
366 | - */ |
|
367 | - public function getSourcePath($path) { |
|
368 | - $fullPath = $this->datadir . $path; |
|
369 | - $currentPath = $path; |
|
370 | - if ($this->allowSymlinks || $currentPath === '') { |
|
371 | - return $fullPath; |
|
372 | - } |
|
373 | - $pathToResolve = $fullPath; |
|
374 | - $realPath = realpath($pathToResolve); |
|
375 | - while ($realPath === false) { // for non existing files check the parent directory |
|
376 | - $currentPath = dirname($currentPath); |
|
377 | - if ($realPath === '' || $realPath === '.') { |
|
378 | - return $fullPath; |
|
379 | - } |
|
380 | - $realPath = realpath($this->datadir . $currentPath); |
|
381 | - } |
|
382 | - if ($realPath) { |
|
383 | - $realPath = $realPath . '/'; |
|
384 | - } |
|
385 | - if (substr($realPath, 0, $this->dataDirLength) === $this->realDataDir) { |
|
386 | - return $fullPath; |
|
387 | - } |
|
388 | - |
|
389 | - \OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", \OCP\Util::ERROR); |
|
390 | - throw new ForbiddenException('Following symlinks is not allowed', false); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * {@inheritdoc} |
|
395 | - */ |
|
396 | - public function isLocal() { |
|
397 | - return true; |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * get the ETag for a file or folder |
|
402 | - * |
|
403 | - * @param string $path |
|
404 | - * @return string |
|
405 | - */ |
|
406 | - public function getETag($path) { |
|
407 | - if ($this->is_file($path)) { |
|
408 | - $stat = $this->stat($path); |
|
409 | - return md5( |
|
410 | - $stat['mtime'] . |
|
411 | - $stat['ino'] . |
|
412 | - $stat['dev'] . |
|
413 | - $stat['size'] |
|
414 | - ); |
|
415 | - } else { |
|
416 | - return parent::getETag($path); |
|
417 | - } |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * @param IStorage $sourceStorage |
|
422 | - * @param string $sourceInternalPath |
|
423 | - * @param string $targetInternalPath |
|
424 | - * @param bool $preserveMtime |
|
425 | - * @return bool |
|
426 | - */ |
|
427 | - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { |
|
428 | - if ($sourceStorage->instanceOfStorage(Local::class)) { |
|
429 | - if ($sourceStorage->instanceOfStorage(Jail::class)) { |
|
430 | - /** |
|
431 | - * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage |
|
432 | - */ |
|
433 | - $sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath); |
|
434 | - } |
|
435 | - /** |
|
436 | - * @var \OC\Files\Storage\Local $sourceStorage |
|
437 | - */ |
|
438 | - $rootStorage = new Local(['datadir' => '/']); |
|
439 | - return $rootStorage->copy($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath)); |
|
440 | - } else { |
|
441 | - return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
442 | - } |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * @param IStorage $sourceStorage |
|
447 | - * @param string $sourceInternalPath |
|
448 | - * @param string $targetInternalPath |
|
449 | - * @return bool |
|
450 | - */ |
|
451 | - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
452 | - if ($sourceStorage->instanceOfStorage(Local::class)) { |
|
453 | - if ($sourceStorage->instanceOfStorage(Jail::class)) { |
|
454 | - /** |
|
455 | - * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage |
|
456 | - */ |
|
457 | - $sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath); |
|
458 | - } |
|
459 | - /** |
|
460 | - * @var \OC\Files\Storage\Local $sourceStorage |
|
461 | - */ |
|
462 | - $rootStorage = new Local(['datadir' => '/']); |
|
463 | - return $rootStorage->rename($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath)); |
|
464 | - } else { |
|
465 | - return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
466 | - } |
|
467 | - } |
|
51 | + protected $datadir; |
|
52 | + |
|
53 | + protected $dataDirLength; |
|
54 | + |
|
55 | + protected $allowSymlinks = false; |
|
56 | + |
|
57 | + protected $realDataDir; |
|
58 | + |
|
59 | + public function __construct($arguments) { |
|
60 | + if (!isset($arguments['datadir']) || !is_string($arguments['datadir'])) { |
|
61 | + throw new \InvalidArgumentException('No data directory set for local storage'); |
|
62 | + } |
|
63 | + $this->datadir = $arguments['datadir']; |
|
64 | + // some crazy code uses a local storage on root... |
|
65 | + if ($this->datadir === '/') { |
|
66 | + $this->realDataDir = $this->datadir; |
|
67 | + } else { |
|
68 | + $realPath = realpath($this->datadir); |
|
69 | + if (!$realPath) { |
|
70 | + throw new NotFoundException('Data directory not found: ' . $this->datadir); |
|
71 | + } |
|
72 | + $this->realDataDir = rtrim($realPath, '/') . '/'; |
|
73 | + } |
|
74 | + if (substr($this->datadir, -1) !== '/') { |
|
75 | + $this->datadir .= '/'; |
|
76 | + } |
|
77 | + $this->dataDirLength = strlen($this->realDataDir); |
|
78 | + } |
|
79 | + |
|
80 | + public function __destruct() { |
|
81 | + } |
|
82 | + |
|
83 | + public function getId() { |
|
84 | + return 'local::' . $this->datadir; |
|
85 | + } |
|
86 | + |
|
87 | + public function mkdir($path) { |
|
88 | + return @mkdir($this->getSourcePath($path), 0777, true); |
|
89 | + } |
|
90 | + |
|
91 | + public function rmdir($path) { |
|
92 | + if (!$this->isDeletable($path)) { |
|
93 | + return false; |
|
94 | + } |
|
95 | + try { |
|
96 | + $it = new \RecursiveIteratorIterator( |
|
97 | + new \RecursiveDirectoryIterator($this->getSourcePath($path)), |
|
98 | + \RecursiveIteratorIterator::CHILD_FIRST |
|
99 | + ); |
|
100 | + /** |
|
101 | + * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach |
|
102 | + * This bug is fixed in PHP 5.5.9 or before |
|
103 | + * See #8376 |
|
104 | + */ |
|
105 | + $it->rewind(); |
|
106 | + while ($it->valid()) { |
|
107 | + /** |
|
108 | + * @var \SplFileInfo $file |
|
109 | + */ |
|
110 | + $file = $it->current(); |
|
111 | + if (in_array($file->getBasename(), array('.', '..'))) { |
|
112 | + $it->next(); |
|
113 | + continue; |
|
114 | + } elseif ($file->isDir()) { |
|
115 | + rmdir($file->getPathname()); |
|
116 | + } elseif ($file->isFile() || $file->isLink()) { |
|
117 | + unlink($file->getPathname()); |
|
118 | + } |
|
119 | + $it->next(); |
|
120 | + } |
|
121 | + return rmdir($this->getSourcePath($path)); |
|
122 | + } catch (\UnexpectedValueException $e) { |
|
123 | + return false; |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + public function opendir($path) { |
|
128 | + return opendir($this->getSourcePath($path)); |
|
129 | + } |
|
130 | + |
|
131 | + public function is_dir($path) { |
|
132 | + if (substr($path, -1) == '/') { |
|
133 | + $path = substr($path, 0, -1); |
|
134 | + } |
|
135 | + return is_dir($this->getSourcePath($path)); |
|
136 | + } |
|
137 | + |
|
138 | + public function is_file($path) { |
|
139 | + return is_file($this->getSourcePath($path)); |
|
140 | + } |
|
141 | + |
|
142 | + public function stat($path) { |
|
143 | + clearstatcache(); |
|
144 | + $fullPath = $this->getSourcePath($path); |
|
145 | + $statResult = stat($fullPath); |
|
146 | + if (PHP_INT_SIZE === 4 && !$this->is_dir($path)) { |
|
147 | + $filesize = $this->filesize($path); |
|
148 | + $statResult['size'] = $filesize; |
|
149 | + $statResult[7] = $filesize; |
|
150 | + } |
|
151 | + return $statResult; |
|
152 | + } |
|
153 | + |
|
154 | + public function filetype($path) { |
|
155 | + $filetype = filetype($this->getSourcePath($path)); |
|
156 | + if ($filetype == 'link') { |
|
157 | + $filetype = filetype(realpath($this->getSourcePath($path))); |
|
158 | + } |
|
159 | + return $filetype; |
|
160 | + } |
|
161 | + |
|
162 | + public function filesize($path) { |
|
163 | + if ($this->is_dir($path)) { |
|
164 | + return 0; |
|
165 | + } |
|
166 | + $fullPath = $this->getSourcePath($path); |
|
167 | + if (PHP_INT_SIZE === 4) { |
|
168 | + $helper = new \OC\LargeFileHelper; |
|
169 | + return $helper->getFileSize($fullPath); |
|
170 | + } |
|
171 | + return filesize($fullPath); |
|
172 | + } |
|
173 | + |
|
174 | + public function isReadable($path) { |
|
175 | + return is_readable($this->getSourcePath($path)); |
|
176 | + } |
|
177 | + |
|
178 | + public function isUpdatable($path) { |
|
179 | + return is_writable($this->getSourcePath($path)); |
|
180 | + } |
|
181 | + |
|
182 | + public function file_exists($path) { |
|
183 | + return file_exists($this->getSourcePath($path)); |
|
184 | + } |
|
185 | + |
|
186 | + public function filemtime($path) { |
|
187 | + $fullPath = $this->getSourcePath($path); |
|
188 | + clearstatcache(true, $fullPath); |
|
189 | + if (!$this->file_exists($path)) { |
|
190 | + return false; |
|
191 | + } |
|
192 | + if (PHP_INT_SIZE === 4) { |
|
193 | + $helper = new \OC\LargeFileHelper(); |
|
194 | + return $helper->getFileMtime($fullPath); |
|
195 | + } |
|
196 | + return filemtime($fullPath); |
|
197 | + } |
|
198 | + |
|
199 | + public function touch($path, $mtime = null) { |
|
200 | + // sets the modification time of the file to the given value. |
|
201 | + // If mtime is nil the current time is set. |
|
202 | + // note that the access time of the file always changes to the current time. |
|
203 | + if ($this->file_exists($path) and !$this->isUpdatable($path)) { |
|
204 | + return false; |
|
205 | + } |
|
206 | + if (!is_null($mtime)) { |
|
207 | + $result = touch($this->getSourcePath($path), $mtime); |
|
208 | + } else { |
|
209 | + $result = touch($this->getSourcePath($path)); |
|
210 | + } |
|
211 | + if ($result) { |
|
212 | + clearstatcache(true, $this->getSourcePath($path)); |
|
213 | + } |
|
214 | + |
|
215 | + return $result; |
|
216 | + } |
|
217 | + |
|
218 | + public function file_get_contents($path) { |
|
219 | + return file_get_contents($this->getSourcePath($path)); |
|
220 | + } |
|
221 | + |
|
222 | + public function file_put_contents($path, $data) { |
|
223 | + return file_put_contents($this->getSourcePath($path), $data); |
|
224 | + } |
|
225 | + |
|
226 | + public function unlink($path) { |
|
227 | + if ($this->is_dir($path)) { |
|
228 | + return $this->rmdir($path); |
|
229 | + } else if ($this->is_file($path)) { |
|
230 | + return unlink($this->getSourcePath($path)); |
|
231 | + } else { |
|
232 | + return false; |
|
233 | + } |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + public function rename($path1, $path2) { |
|
238 | + $srcParent = dirname($path1); |
|
239 | + $dstParent = dirname($path2); |
|
240 | + |
|
241 | + if (!$this->isUpdatable($srcParent)) { |
|
242 | + \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, \OCP\Util::ERROR); |
|
243 | + return false; |
|
244 | + } |
|
245 | + |
|
246 | + if (!$this->isUpdatable($dstParent)) { |
|
247 | + \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, \OCP\Util::ERROR); |
|
248 | + return false; |
|
249 | + } |
|
250 | + |
|
251 | + if (!$this->file_exists($path1)) { |
|
252 | + \OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, \OCP\Util::ERROR); |
|
253 | + return false; |
|
254 | + } |
|
255 | + |
|
256 | + if ($this->is_dir($path2)) { |
|
257 | + $this->rmdir($path2); |
|
258 | + } else if ($this->is_file($path2)) { |
|
259 | + $this->unlink($path2); |
|
260 | + } |
|
261 | + |
|
262 | + if ($this->is_dir($path1)) { |
|
263 | + // we can't move folders across devices, use copy instead |
|
264 | + $stat1 = stat(dirname($this->getSourcePath($path1))); |
|
265 | + $stat2 = stat(dirname($this->getSourcePath($path2))); |
|
266 | + if ($stat1['dev'] !== $stat2['dev']) { |
|
267 | + $result = $this->copy($path1, $path2); |
|
268 | + if ($result) { |
|
269 | + $result &= $this->rmdir($path1); |
|
270 | + } |
|
271 | + return $result; |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + return rename($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
276 | + } |
|
277 | + |
|
278 | + public function copy($path1, $path2) { |
|
279 | + if ($this->is_dir($path1)) { |
|
280 | + return parent::copy($path1, $path2); |
|
281 | + } else { |
|
282 | + return copy($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
283 | + } |
|
284 | + } |
|
285 | + |
|
286 | + public function fopen($path, $mode) { |
|
287 | + return fopen($this->getSourcePath($path), $mode); |
|
288 | + } |
|
289 | + |
|
290 | + public function hash($type, $path, $raw = false) { |
|
291 | + return hash_file($type, $this->getSourcePath($path), $raw); |
|
292 | + } |
|
293 | + |
|
294 | + public function free_space($path) { |
|
295 | + $sourcePath = $this->getSourcePath($path); |
|
296 | + // using !is_dir because $sourcePath might be a part file or |
|
297 | + // non-existing file, so we'd still want to use the parent dir |
|
298 | + // in such cases |
|
299 | + if (!is_dir($sourcePath)) { |
|
300 | + // disk_free_space doesn't work on files |
|
301 | + $sourcePath = dirname($sourcePath); |
|
302 | + } |
|
303 | + $space = @disk_free_space($sourcePath); |
|
304 | + if ($space === false || is_null($space)) { |
|
305 | + return \OCP\Files\FileInfo::SPACE_UNKNOWN; |
|
306 | + } |
|
307 | + return $space; |
|
308 | + } |
|
309 | + |
|
310 | + public function search($query) { |
|
311 | + return $this->searchInDir($query); |
|
312 | + } |
|
313 | + |
|
314 | + public function getLocalFile($path) { |
|
315 | + return $this->getSourcePath($path); |
|
316 | + } |
|
317 | + |
|
318 | + public function getLocalFolder($path) { |
|
319 | + return $this->getSourcePath($path); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * @param string $query |
|
324 | + * @param string $dir |
|
325 | + * @return array |
|
326 | + */ |
|
327 | + protected function searchInDir($query, $dir = '') { |
|
328 | + $files = array(); |
|
329 | + $physicalDir = $this->getSourcePath($dir); |
|
330 | + foreach (scandir($physicalDir) as $item) { |
|
331 | + if (\OC\Files\Filesystem::isIgnoredDir($item)) |
|
332 | + continue; |
|
333 | + $physicalItem = $physicalDir . '/' . $item; |
|
334 | + |
|
335 | + if (strstr(strtolower($item), strtolower($query)) !== false) { |
|
336 | + $files[] = $dir . '/' . $item; |
|
337 | + } |
|
338 | + if (is_dir($physicalItem)) { |
|
339 | + $files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item)); |
|
340 | + } |
|
341 | + } |
|
342 | + return $files; |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * check if a file or folder has been updated since $time |
|
347 | + * |
|
348 | + * @param string $path |
|
349 | + * @param int $time |
|
350 | + * @return bool |
|
351 | + */ |
|
352 | + public function hasUpdated($path, $time) { |
|
353 | + if ($this->file_exists($path)) { |
|
354 | + return $this->filemtime($path) > $time; |
|
355 | + } else { |
|
356 | + return true; |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Get the source path (on disk) of a given path |
|
362 | + * |
|
363 | + * @param string $path |
|
364 | + * @return string |
|
365 | + * @throws ForbiddenException |
|
366 | + */ |
|
367 | + public function getSourcePath($path) { |
|
368 | + $fullPath = $this->datadir . $path; |
|
369 | + $currentPath = $path; |
|
370 | + if ($this->allowSymlinks || $currentPath === '') { |
|
371 | + return $fullPath; |
|
372 | + } |
|
373 | + $pathToResolve = $fullPath; |
|
374 | + $realPath = realpath($pathToResolve); |
|
375 | + while ($realPath === false) { // for non existing files check the parent directory |
|
376 | + $currentPath = dirname($currentPath); |
|
377 | + if ($realPath === '' || $realPath === '.') { |
|
378 | + return $fullPath; |
|
379 | + } |
|
380 | + $realPath = realpath($this->datadir . $currentPath); |
|
381 | + } |
|
382 | + if ($realPath) { |
|
383 | + $realPath = $realPath . '/'; |
|
384 | + } |
|
385 | + if (substr($realPath, 0, $this->dataDirLength) === $this->realDataDir) { |
|
386 | + return $fullPath; |
|
387 | + } |
|
388 | + |
|
389 | + \OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", \OCP\Util::ERROR); |
|
390 | + throw new ForbiddenException('Following symlinks is not allowed', false); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * {@inheritdoc} |
|
395 | + */ |
|
396 | + public function isLocal() { |
|
397 | + return true; |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * get the ETag for a file or folder |
|
402 | + * |
|
403 | + * @param string $path |
|
404 | + * @return string |
|
405 | + */ |
|
406 | + public function getETag($path) { |
|
407 | + if ($this->is_file($path)) { |
|
408 | + $stat = $this->stat($path); |
|
409 | + return md5( |
|
410 | + $stat['mtime'] . |
|
411 | + $stat['ino'] . |
|
412 | + $stat['dev'] . |
|
413 | + $stat['size'] |
|
414 | + ); |
|
415 | + } else { |
|
416 | + return parent::getETag($path); |
|
417 | + } |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * @param IStorage $sourceStorage |
|
422 | + * @param string $sourceInternalPath |
|
423 | + * @param string $targetInternalPath |
|
424 | + * @param bool $preserveMtime |
|
425 | + * @return bool |
|
426 | + */ |
|
427 | + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { |
|
428 | + if ($sourceStorage->instanceOfStorage(Local::class)) { |
|
429 | + if ($sourceStorage->instanceOfStorage(Jail::class)) { |
|
430 | + /** |
|
431 | + * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage |
|
432 | + */ |
|
433 | + $sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath); |
|
434 | + } |
|
435 | + /** |
|
436 | + * @var \OC\Files\Storage\Local $sourceStorage |
|
437 | + */ |
|
438 | + $rootStorage = new Local(['datadir' => '/']); |
|
439 | + return $rootStorage->copy($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath)); |
|
440 | + } else { |
|
441 | + return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
442 | + } |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * @param IStorage $sourceStorage |
|
447 | + * @param string $sourceInternalPath |
|
448 | + * @param string $targetInternalPath |
|
449 | + * @return bool |
|
450 | + */ |
|
451 | + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
452 | + if ($sourceStorage->instanceOfStorage(Local::class)) { |
|
453 | + if ($sourceStorage->instanceOfStorage(Jail::class)) { |
|
454 | + /** |
|
455 | + * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage |
|
456 | + */ |
|
457 | + $sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath); |
|
458 | + } |
|
459 | + /** |
|
460 | + * @var \OC\Files\Storage\Local $sourceStorage |
|
461 | + */ |
|
462 | + $rootStorage = new Local(['datadir' => '/']); |
|
463 | + return $rootStorage->rename($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath)); |
|
464 | + } else { |
|
465 | + return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
466 | + } |
|
467 | + } |
|
468 | 468 | } |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | } else { |
68 | 68 | $realPath = realpath($this->datadir); |
69 | 69 | if (!$realPath) { |
70 | - throw new NotFoundException('Data directory not found: ' . $this->datadir); |
|
70 | + throw new NotFoundException('Data directory not found: '.$this->datadir); |
|
71 | 71 | } |
72 | - $this->realDataDir = rtrim($realPath, '/') . '/'; |
|
72 | + $this->realDataDir = rtrim($realPath, '/').'/'; |
|
73 | 73 | } |
74 | 74 | if (substr($this->datadir, -1) !== '/') { |
75 | 75 | $this->datadir .= '/'; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | public function getId() { |
84 | - return 'local::' . $this->datadir; |
|
84 | + return 'local::'.$this->datadir; |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | public function mkdir($path) { |
@@ -239,17 +239,17 @@ discard block |
||
239 | 239 | $dstParent = dirname($path2); |
240 | 240 | |
241 | 241 | if (!$this->isUpdatable($srcParent)) { |
242 | - \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, \OCP\Util::ERROR); |
|
242 | + \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : '.$srcParent, \OCP\Util::ERROR); |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | |
246 | 246 | if (!$this->isUpdatable($dstParent)) { |
247 | - \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, \OCP\Util::ERROR); |
|
247 | + \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : '.$dstParent, \OCP\Util::ERROR); |
|
248 | 248 | return false; |
249 | 249 | } |
250 | 250 | |
251 | 251 | if (!$this->file_exists($path1)) { |
252 | - \OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, \OCP\Util::ERROR); |
|
252 | + \OCP\Util::writeLog('core', 'unable to rename, file does not exists : '.$path1, \OCP\Util::ERROR); |
|
253 | 253 | return false; |
254 | 254 | } |
255 | 255 | |
@@ -330,13 +330,13 @@ discard block |
||
330 | 330 | foreach (scandir($physicalDir) as $item) { |
331 | 331 | if (\OC\Files\Filesystem::isIgnoredDir($item)) |
332 | 332 | continue; |
333 | - $physicalItem = $physicalDir . '/' . $item; |
|
333 | + $physicalItem = $physicalDir.'/'.$item; |
|
334 | 334 | |
335 | 335 | if (strstr(strtolower($item), strtolower($query)) !== false) { |
336 | - $files[] = $dir . '/' . $item; |
|
336 | + $files[] = $dir.'/'.$item; |
|
337 | 337 | } |
338 | 338 | if (is_dir($physicalItem)) { |
339 | - $files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item)); |
|
339 | + $files = array_merge($files, $this->searchInDir($query, $dir.'/'.$item)); |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | return $files; |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * @throws ForbiddenException |
366 | 366 | */ |
367 | 367 | public function getSourcePath($path) { |
368 | - $fullPath = $this->datadir . $path; |
|
368 | + $fullPath = $this->datadir.$path; |
|
369 | 369 | $currentPath = $path; |
370 | 370 | if ($this->allowSymlinks || $currentPath === '') { |
371 | 371 | return $fullPath; |
@@ -377,10 +377,10 @@ discard block |
||
377 | 377 | if ($realPath === '' || $realPath === '.') { |
378 | 378 | return $fullPath; |
379 | 379 | } |
380 | - $realPath = realpath($this->datadir . $currentPath); |
|
380 | + $realPath = realpath($this->datadir.$currentPath); |
|
381 | 381 | } |
382 | 382 | if ($realPath) { |
383 | - $realPath = $realPath . '/'; |
|
383 | + $realPath = $realPath.'/'; |
|
384 | 384 | } |
385 | 385 | if (substr($realPath, 0, $this->dataDirLength) === $this->realDataDir) { |
386 | 386 | return $fullPath; |
@@ -407,9 +407,9 @@ discard block |
||
407 | 407 | if ($this->is_file($path)) { |
408 | 408 | $stat = $this->stat($path); |
409 | 409 | return md5( |
410 | - $stat['mtime'] . |
|
411 | - $stat['ino'] . |
|
412 | - $stat['dev'] . |
|
410 | + $stat['mtime']. |
|
411 | + $stat['ino']. |
|
412 | + $stat['dev']. |
|
413 | 413 | $stat['size'] |
414 | 414 | ); |
415 | 415 | } else { |