@@ -50,7 +50,7 @@ |
||
50 | 50 | public function __construct($arguments) { |
51 | 51 | $this->user = $arguments['user']; |
52 | 52 | $datadir = $this->user->getHome(); |
53 | - $this->id = 'home::' . $this->user->getUID(); |
|
53 | + $this->id = 'home::'.$this->user->getUID(); |
|
54 | 54 | |
55 | 55 | parent::__construct(['datadir' => $datadir]); |
56 | 56 | } |
@@ -27,7 +27,6 @@ |
||
27 | 27 | namespace OC\Files\Storage; |
28 | 28 | |
29 | 29 | use OC\Files\Cache\HomePropagator; |
30 | -use OCP\Files\NotFoundException; |
|
31 | 30 | |
32 | 31 | /** |
33 | 32 | * Specialized version of Local storage for home directory usage |
@@ -33,80 +33,80 @@ |
||
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 | - parent::__construct(['datadir' => $datadir]); |
|
58 | - } |
|
57 | + parent::__construct(['datadir' => $datadir]); |
|
58 | + } |
|
59 | 59 | |
60 | - public function getId() { |
|
61 | - return $this->id; |
|
62 | - } |
|
60 | + public function getId() { |
|
61 | + return $this->id; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return \OC\Files\Cache\HomeCache |
|
66 | - */ |
|
67 | - public function getCache($path = '', $storage = null) { |
|
68 | - if (!$storage) { |
|
69 | - $storage = $this; |
|
70 | - } |
|
71 | - if (!isset($this->cache)) { |
|
72 | - $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | - } |
|
74 | - return $this->cache; |
|
75 | - } |
|
64 | + /** |
|
65 | + * @return \OC\Files\Cache\HomeCache |
|
66 | + */ |
|
67 | + public function getCache($path = '', $storage = null) { |
|
68 | + if (!$storage) { |
|
69 | + $storage = $this; |
|
70 | + } |
|
71 | + if (!isset($this->cache)) { |
|
72 | + $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | + } |
|
74 | + return $this->cache; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * get a propagator instance for the cache |
|
79 | - * |
|
80 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | - * @return \OC\Files\Cache\Propagator |
|
82 | - */ |
|
83 | - public function getPropagator($storage = null) { |
|
84 | - if (!$storage) { |
|
85 | - $storage = $this; |
|
86 | - } |
|
87 | - if (!isset($this->propagator)) { |
|
88 | - $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | - } |
|
90 | - return $this->propagator; |
|
91 | - } |
|
77 | + /** |
|
78 | + * get a propagator instance for the cache |
|
79 | + * |
|
80 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | + * @return \OC\Files\Cache\Propagator |
|
82 | + */ |
|
83 | + public function getPropagator($storage = null) { |
|
84 | + if (!$storage) { |
|
85 | + $storage = $this; |
|
86 | + } |
|
87 | + if (!isset($this->propagator)) { |
|
88 | + $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | + } |
|
90 | + return $this->propagator; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Returns the owner of this home storage |
|
96 | - * |
|
97 | - * @return \OC\User\User owner of this home storage |
|
98 | - */ |
|
99 | - public function getUser() { |
|
100 | - return $this->user; |
|
101 | - } |
|
94 | + /** |
|
95 | + * Returns the owner of this home storage |
|
96 | + * |
|
97 | + * @return \OC\User\User owner of this home storage |
|
98 | + */ |
|
99 | + public function getUser() { |
|
100 | + return $this->user; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * get the owner of a path |
|
105 | - * |
|
106 | - * @param string $path The path to get the owner |
|
107 | - * @return string uid or false |
|
108 | - */ |
|
109 | - public function getOwner($path) { |
|
110 | - return $this->user->getUID(); |
|
111 | - } |
|
103 | + /** |
|
104 | + * get the owner of a path |
|
105 | + * |
|
106 | + * @param string $path The path to get the owner |
|
107 | + * @return string uid or false |
|
108 | + */ |
|
109 | + public function getOwner($path) { |
|
110 | + return $this->user->getUID(); |
|
111 | + } |
|
112 | 112 | } |
@@ -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 | } |
@@ -41,7 +41,6 @@ |
||
41 | 41 | |
42 | 42 | use OC\Files\Storage\Wrapper\Jail; |
43 | 43 | use OCP\Files\ForbiddenException; |
44 | -use OCP\Files\NotFoundException; |
|
45 | 44 | use OCP\Files\Storage\IStorage; |
46 | 45 | |
47 | 46 | /** |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->realDataDir = $this->datadir; |
67 | 67 | } else { |
68 | 68 | $realPath = realpath($this->datadir) ?: $this->datadir; |
69 | - $this->realDataDir = rtrim($realPath, '/') . '/'; |
|
69 | + $this->realDataDir = rtrim($realPath, '/').'/'; |
|
70 | 70 | } |
71 | 71 | if (substr($this->datadir, -1) !== '/') { |
72 | 72 | $this->datadir .= '/'; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | } |
79 | 79 | |
80 | 80 | public function getId() { |
81 | - return 'local::' . $this->datadir; |
|
81 | + return 'local::'.$this->datadir; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | public function mkdir($path) { |
@@ -236,17 +236,17 @@ discard block |
||
236 | 236 | $dstParent = dirname($path2); |
237 | 237 | |
238 | 238 | if (!$this->isUpdatable($srcParent)) { |
239 | - \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, \OCP\Util::ERROR); |
|
239 | + \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : '.$srcParent, \OCP\Util::ERROR); |
|
240 | 240 | return false; |
241 | 241 | } |
242 | 242 | |
243 | 243 | if (!$this->isUpdatable($dstParent)) { |
244 | - \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, \OCP\Util::ERROR); |
|
244 | + \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : '.$dstParent, \OCP\Util::ERROR); |
|
245 | 245 | return false; |
246 | 246 | } |
247 | 247 | |
248 | 248 | if (!$this->file_exists($path1)) { |
249 | - \OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, \OCP\Util::ERROR); |
|
249 | + \OCP\Util::writeLog('core', 'unable to rename, file does not exists : '.$path1, \OCP\Util::ERROR); |
|
250 | 250 | return false; |
251 | 251 | } |
252 | 252 | |
@@ -327,13 +327,13 @@ discard block |
||
327 | 327 | foreach (scandir($physicalDir) as $item) { |
328 | 328 | if (\OC\Files\Filesystem::isIgnoredDir($item)) |
329 | 329 | continue; |
330 | - $physicalItem = $physicalDir . '/' . $item; |
|
330 | + $physicalItem = $physicalDir.'/'.$item; |
|
331 | 331 | |
332 | 332 | if (strstr(strtolower($item), strtolower($query)) !== false) { |
333 | - $files[] = $dir . '/' . $item; |
|
333 | + $files[] = $dir.'/'.$item; |
|
334 | 334 | } |
335 | 335 | if (is_dir($physicalItem)) { |
336 | - $files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item)); |
|
336 | + $files = array_merge($files, $this->searchInDir($query, $dir.'/'.$item)); |
|
337 | 337 | } |
338 | 338 | } |
339 | 339 | return $files; |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * @throws ForbiddenException |
363 | 363 | */ |
364 | 364 | public function getSourcePath($path) { |
365 | - $fullPath = $this->datadir . $path; |
|
365 | + $fullPath = $this->datadir.$path; |
|
366 | 366 | $currentPath = $path; |
367 | 367 | if ($this->allowSymlinks || $currentPath === '') { |
368 | 368 | return $fullPath; |
@@ -374,10 +374,10 @@ discard block |
||
374 | 374 | if ($currentPath === '' || $currentPath === '.') { |
375 | 375 | return $fullPath; |
376 | 376 | } |
377 | - $realPath = realpath($this->datadir . $currentPath); |
|
377 | + $realPath = realpath($this->datadir.$currentPath); |
|
378 | 378 | } |
379 | 379 | if ($realPath) { |
380 | - $realPath = $realPath . '/'; |
|
380 | + $realPath = $realPath.'/'; |
|
381 | 381 | } |
382 | 382 | if (substr($realPath, 0, $this->dataDirLength) === $this->realDataDir) { |
383 | 383 | return $fullPath; |
@@ -404,9 +404,9 @@ discard block |
||
404 | 404 | if ($this->is_file($path)) { |
405 | 405 | $stat = $this->stat($path); |
406 | 406 | return md5( |
407 | - $stat['mtime'] . |
|
408 | - $stat['ino'] . |
|
409 | - $stat['dev'] . |
|
407 | + $stat['mtime']. |
|
408 | + $stat['ino']. |
|
409 | + $stat['dev']. |
|
410 | 410 | $stat['size'] |
411 | 411 | ); |
412 | 412 | } else { |
@@ -48,418 +48,418 @@ |
||
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 = str_replace('//', '/', $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) ?: $this->datadir; |
|
69 | - $this->realDataDir = rtrim($realPath, '/') . '/'; |
|
70 | - } |
|
71 | - if (substr($this->datadir, -1) !== '/') { |
|
72 | - $this->datadir .= '/'; |
|
73 | - } |
|
74 | - $this->dataDirLength = strlen($this->realDataDir); |
|
75 | - } |
|
76 | - |
|
77 | - public function __destruct() { |
|
78 | - } |
|
79 | - |
|
80 | - public function getId() { |
|
81 | - return 'local::' . $this->datadir; |
|
82 | - } |
|
83 | - |
|
84 | - public function mkdir($path) { |
|
85 | - return @mkdir($this->getSourcePath($path), 0777, true); |
|
86 | - } |
|
87 | - |
|
88 | - public function rmdir($path) { |
|
89 | - if (!$this->isDeletable($path)) { |
|
90 | - return false; |
|
91 | - } |
|
92 | - try { |
|
93 | - $it = new \RecursiveIteratorIterator( |
|
94 | - new \RecursiveDirectoryIterator($this->getSourcePath($path)), |
|
95 | - \RecursiveIteratorIterator::CHILD_FIRST |
|
96 | - ); |
|
97 | - /** |
|
98 | - * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach |
|
99 | - * This bug is fixed in PHP 5.5.9 or before |
|
100 | - * See #8376 |
|
101 | - */ |
|
102 | - $it->rewind(); |
|
103 | - while ($it->valid()) { |
|
104 | - /** |
|
105 | - * @var \SplFileInfo $file |
|
106 | - */ |
|
107 | - $file = $it->current(); |
|
108 | - if (in_array($file->getBasename(), array('.', '..'))) { |
|
109 | - $it->next(); |
|
110 | - continue; |
|
111 | - } elseif ($file->isDir()) { |
|
112 | - rmdir($file->getPathname()); |
|
113 | - } elseif ($file->isFile() || $file->isLink()) { |
|
114 | - unlink($file->getPathname()); |
|
115 | - } |
|
116 | - $it->next(); |
|
117 | - } |
|
118 | - return rmdir($this->getSourcePath($path)); |
|
119 | - } catch (\UnexpectedValueException $e) { |
|
120 | - return false; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - public function opendir($path) { |
|
125 | - return opendir($this->getSourcePath($path)); |
|
126 | - } |
|
127 | - |
|
128 | - public function is_dir($path) { |
|
129 | - if (substr($path, -1) == '/') { |
|
130 | - $path = substr($path, 0, -1); |
|
131 | - } |
|
132 | - return is_dir($this->getSourcePath($path)); |
|
133 | - } |
|
134 | - |
|
135 | - public function is_file($path) { |
|
136 | - return is_file($this->getSourcePath($path)); |
|
137 | - } |
|
138 | - |
|
139 | - public function stat($path) { |
|
140 | - clearstatcache(); |
|
141 | - $fullPath = $this->getSourcePath($path); |
|
142 | - $statResult = stat($fullPath); |
|
143 | - if (PHP_INT_SIZE === 4 && !$this->is_dir($path)) { |
|
144 | - $filesize = $this->filesize($path); |
|
145 | - $statResult['size'] = $filesize; |
|
146 | - $statResult[7] = $filesize; |
|
147 | - } |
|
148 | - return $statResult; |
|
149 | - } |
|
150 | - |
|
151 | - public function filetype($path) { |
|
152 | - $filetype = filetype($this->getSourcePath($path)); |
|
153 | - if ($filetype == 'link') { |
|
154 | - $filetype = filetype(realpath($this->getSourcePath($path))); |
|
155 | - } |
|
156 | - return $filetype; |
|
157 | - } |
|
158 | - |
|
159 | - public function filesize($path) { |
|
160 | - if ($this->is_dir($path)) { |
|
161 | - return 0; |
|
162 | - } |
|
163 | - $fullPath = $this->getSourcePath($path); |
|
164 | - if (PHP_INT_SIZE === 4) { |
|
165 | - $helper = new \OC\LargeFileHelper; |
|
166 | - return $helper->getFileSize($fullPath); |
|
167 | - } |
|
168 | - return filesize($fullPath); |
|
169 | - } |
|
170 | - |
|
171 | - public function isReadable($path) { |
|
172 | - return is_readable($this->getSourcePath($path)); |
|
173 | - } |
|
174 | - |
|
175 | - public function isUpdatable($path) { |
|
176 | - return is_writable($this->getSourcePath($path)); |
|
177 | - } |
|
178 | - |
|
179 | - public function file_exists($path) { |
|
180 | - return file_exists($this->getSourcePath($path)); |
|
181 | - } |
|
182 | - |
|
183 | - public function filemtime($path) { |
|
184 | - $fullPath = $this->getSourcePath($path); |
|
185 | - clearstatcache(true, $fullPath); |
|
186 | - if (!$this->file_exists($path)) { |
|
187 | - return false; |
|
188 | - } |
|
189 | - if (PHP_INT_SIZE === 4) { |
|
190 | - $helper = new \OC\LargeFileHelper(); |
|
191 | - return $helper->getFileMtime($fullPath); |
|
192 | - } |
|
193 | - return filemtime($fullPath); |
|
194 | - } |
|
195 | - |
|
196 | - public function touch($path, $mtime = null) { |
|
197 | - // sets the modification time of the file to the given value. |
|
198 | - // If mtime is nil the current time is set. |
|
199 | - // note that the access time of the file always changes to the current time. |
|
200 | - if ($this->file_exists($path) and !$this->isUpdatable($path)) { |
|
201 | - return false; |
|
202 | - } |
|
203 | - if (!is_null($mtime)) { |
|
204 | - $result = touch($this->getSourcePath($path), $mtime); |
|
205 | - } else { |
|
206 | - $result = touch($this->getSourcePath($path)); |
|
207 | - } |
|
208 | - if ($result) { |
|
209 | - clearstatcache(true, $this->getSourcePath($path)); |
|
210 | - } |
|
211 | - |
|
212 | - return $result; |
|
213 | - } |
|
214 | - |
|
215 | - public function file_get_contents($path) { |
|
216 | - return file_get_contents($this->getSourcePath($path)); |
|
217 | - } |
|
218 | - |
|
219 | - public function file_put_contents($path, $data) { |
|
220 | - return file_put_contents($this->getSourcePath($path), $data); |
|
221 | - } |
|
222 | - |
|
223 | - public function unlink($path) { |
|
224 | - if ($this->is_dir($path)) { |
|
225 | - return $this->rmdir($path); |
|
226 | - } else if ($this->is_file($path)) { |
|
227 | - return unlink($this->getSourcePath($path)); |
|
228 | - } else { |
|
229 | - return false; |
|
230 | - } |
|
231 | - |
|
232 | - } |
|
233 | - |
|
234 | - public function rename($path1, $path2) { |
|
235 | - $srcParent = dirname($path1); |
|
236 | - $dstParent = dirname($path2); |
|
237 | - |
|
238 | - if (!$this->isUpdatable($srcParent)) { |
|
239 | - \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, \OCP\Util::ERROR); |
|
240 | - return false; |
|
241 | - } |
|
242 | - |
|
243 | - if (!$this->isUpdatable($dstParent)) { |
|
244 | - \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, \OCP\Util::ERROR); |
|
245 | - return false; |
|
246 | - } |
|
247 | - |
|
248 | - if (!$this->file_exists($path1)) { |
|
249 | - \OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, \OCP\Util::ERROR); |
|
250 | - return false; |
|
251 | - } |
|
252 | - |
|
253 | - if ($this->is_dir($path2)) { |
|
254 | - $this->rmdir($path2); |
|
255 | - } else if ($this->is_file($path2)) { |
|
256 | - $this->unlink($path2); |
|
257 | - } |
|
258 | - |
|
259 | - if ($this->is_dir($path1)) { |
|
260 | - // we can't move folders across devices, use copy instead |
|
261 | - $stat1 = stat(dirname($this->getSourcePath($path1))); |
|
262 | - $stat2 = stat(dirname($this->getSourcePath($path2))); |
|
263 | - if ($stat1['dev'] !== $stat2['dev']) { |
|
264 | - $result = $this->copy($path1, $path2); |
|
265 | - if ($result) { |
|
266 | - $result &= $this->rmdir($path1); |
|
267 | - } |
|
268 | - return $result; |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - return rename($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
273 | - } |
|
274 | - |
|
275 | - public function copy($path1, $path2) { |
|
276 | - if ($this->is_dir($path1)) { |
|
277 | - return parent::copy($path1, $path2); |
|
278 | - } else { |
|
279 | - return copy($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - public function fopen($path, $mode) { |
|
284 | - return fopen($this->getSourcePath($path), $mode); |
|
285 | - } |
|
286 | - |
|
287 | - public function hash($type, $path, $raw = false) { |
|
288 | - return hash_file($type, $this->getSourcePath($path), $raw); |
|
289 | - } |
|
290 | - |
|
291 | - public function free_space($path) { |
|
292 | - $sourcePath = $this->getSourcePath($path); |
|
293 | - // using !is_dir because $sourcePath might be a part file or |
|
294 | - // non-existing file, so we'd still want to use the parent dir |
|
295 | - // in such cases |
|
296 | - if (!is_dir($sourcePath)) { |
|
297 | - // disk_free_space doesn't work on files |
|
298 | - $sourcePath = dirname($sourcePath); |
|
299 | - } |
|
300 | - $space = @disk_free_space($sourcePath); |
|
301 | - if ($space === false || is_null($space)) { |
|
302 | - return \OCP\Files\FileInfo::SPACE_UNKNOWN; |
|
303 | - } |
|
304 | - return $space; |
|
305 | - } |
|
306 | - |
|
307 | - public function search($query) { |
|
308 | - return $this->searchInDir($query); |
|
309 | - } |
|
310 | - |
|
311 | - public function getLocalFile($path) { |
|
312 | - return $this->getSourcePath($path); |
|
313 | - } |
|
314 | - |
|
315 | - public function getLocalFolder($path) { |
|
316 | - return $this->getSourcePath($path); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * @param string $query |
|
321 | - * @param string $dir |
|
322 | - * @return array |
|
323 | - */ |
|
324 | - protected function searchInDir($query, $dir = '') { |
|
325 | - $files = array(); |
|
326 | - $physicalDir = $this->getSourcePath($dir); |
|
327 | - foreach (scandir($physicalDir) as $item) { |
|
328 | - if (\OC\Files\Filesystem::isIgnoredDir($item)) |
|
329 | - continue; |
|
330 | - $physicalItem = $physicalDir . '/' . $item; |
|
331 | - |
|
332 | - if (strstr(strtolower($item), strtolower($query)) !== false) { |
|
333 | - $files[] = $dir . '/' . $item; |
|
334 | - } |
|
335 | - if (is_dir($physicalItem)) { |
|
336 | - $files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item)); |
|
337 | - } |
|
338 | - } |
|
339 | - return $files; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * check if a file or folder has been updated since $time |
|
344 | - * |
|
345 | - * @param string $path |
|
346 | - * @param int $time |
|
347 | - * @return bool |
|
348 | - */ |
|
349 | - public function hasUpdated($path, $time) { |
|
350 | - if ($this->file_exists($path)) { |
|
351 | - return $this->filemtime($path) > $time; |
|
352 | - } else { |
|
353 | - return true; |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Get the source path (on disk) of a given path |
|
359 | - * |
|
360 | - * @param string $path |
|
361 | - * @return string |
|
362 | - * @throws ForbiddenException |
|
363 | - */ |
|
364 | - public function getSourcePath($path) { |
|
365 | - $fullPath = $this->datadir . $path; |
|
366 | - $currentPath = $path; |
|
367 | - if ($this->allowSymlinks || $currentPath === '') { |
|
368 | - return $fullPath; |
|
369 | - } |
|
370 | - $pathToResolve = $fullPath; |
|
371 | - $realPath = realpath($pathToResolve); |
|
372 | - while ($realPath === false) { // for non existing files check the parent directory |
|
373 | - $currentPath = dirname($currentPath); |
|
374 | - if ($currentPath === '' || $currentPath === '.') { |
|
375 | - return $fullPath; |
|
376 | - } |
|
377 | - $realPath = realpath($this->datadir . $currentPath); |
|
378 | - } |
|
379 | - if ($realPath) { |
|
380 | - $realPath = $realPath . '/'; |
|
381 | - } |
|
382 | - if (substr($realPath, 0, $this->dataDirLength) === $this->realDataDir) { |
|
383 | - return $fullPath; |
|
384 | - } |
|
385 | - |
|
386 | - \OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", \OCP\Util::ERROR); |
|
387 | - throw new ForbiddenException('Following symlinks is not allowed', false); |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * {@inheritdoc} |
|
392 | - */ |
|
393 | - public function isLocal() { |
|
394 | - return true; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * get the ETag for a file or folder |
|
399 | - * |
|
400 | - * @param string $path |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - public function getETag($path) { |
|
404 | - if ($this->is_file($path)) { |
|
405 | - $stat = $this->stat($path); |
|
406 | - return md5( |
|
407 | - $stat['mtime'] . |
|
408 | - $stat['ino'] . |
|
409 | - $stat['dev'] . |
|
410 | - $stat['size'] |
|
411 | - ); |
|
412 | - } else { |
|
413 | - return parent::getETag($path); |
|
414 | - } |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * @param IStorage $sourceStorage |
|
419 | - * @param string $sourceInternalPath |
|
420 | - * @param string $targetInternalPath |
|
421 | - * @param bool $preserveMtime |
|
422 | - * @return bool |
|
423 | - */ |
|
424 | - public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { |
|
425 | - if ($sourceStorage->instanceOfStorage(Local::class)) { |
|
426 | - if ($sourceStorage->instanceOfStorage(Jail::class)) { |
|
427 | - /** |
|
428 | - * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage |
|
429 | - */ |
|
430 | - $sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath); |
|
431 | - } |
|
432 | - /** |
|
433 | - * @var \OC\Files\Storage\Local $sourceStorage |
|
434 | - */ |
|
435 | - $rootStorage = new Local(['datadir' => '/']); |
|
436 | - return $rootStorage->copy($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath)); |
|
437 | - } else { |
|
438 | - return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
439 | - } |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * @param IStorage $sourceStorage |
|
444 | - * @param string $sourceInternalPath |
|
445 | - * @param string $targetInternalPath |
|
446 | - * @return bool |
|
447 | - */ |
|
448 | - public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
449 | - if ($sourceStorage->instanceOfStorage(Local::class)) { |
|
450 | - if ($sourceStorage->instanceOfStorage(Jail::class)) { |
|
451 | - /** |
|
452 | - * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage |
|
453 | - */ |
|
454 | - $sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath); |
|
455 | - } |
|
456 | - /** |
|
457 | - * @var \OC\Files\Storage\Local $sourceStorage |
|
458 | - */ |
|
459 | - $rootStorage = new Local(['datadir' => '/']); |
|
460 | - return $rootStorage->rename($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath)); |
|
461 | - } else { |
|
462 | - return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
463 | - } |
|
464 | - } |
|
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 = str_replace('//', '/', $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) ?: $this->datadir; |
|
69 | + $this->realDataDir = rtrim($realPath, '/') . '/'; |
|
70 | + } |
|
71 | + if (substr($this->datadir, -1) !== '/') { |
|
72 | + $this->datadir .= '/'; |
|
73 | + } |
|
74 | + $this->dataDirLength = strlen($this->realDataDir); |
|
75 | + } |
|
76 | + |
|
77 | + public function __destruct() { |
|
78 | + } |
|
79 | + |
|
80 | + public function getId() { |
|
81 | + return 'local::' . $this->datadir; |
|
82 | + } |
|
83 | + |
|
84 | + public function mkdir($path) { |
|
85 | + return @mkdir($this->getSourcePath($path), 0777, true); |
|
86 | + } |
|
87 | + |
|
88 | + public function rmdir($path) { |
|
89 | + if (!$this->isDeletable($path)) { |
|
90 | + return false; |
|
91 | + } |
|
92 | + try { |
|
93 | + $it = new \RecursiveIteratorIterator( |
|
94 | + new \RecursiveDirectoryIterator($this->getSourcePath($path)), |
|
95 | + \RecursiveIteratorIterator::CHILD_FIRST |
|
96 | + ); |
|
97 | + /** |
|
98 | + * RecursiveDirectoryIterator on an NFS path isn't iterable with foreach |
|
99 | + * This bug is fixed in PHP 5.5.9 or before |
|
100 | + * See #8376 |
|
101 | + */ |
|
102 | + $it->rewind(); |
|
103 | + while ($it->valid()) { |
|
104 | + /** |
|
105 | + * @var \SplFileInfo $file |
|
106 | + */ |
|
107 | + $file = $it->current(); |
|
108 | + if (in_array($file->getBasename(), array('.', '..'))) { |
|
109 | + $it->next(); |
|
110 | + continue; |
|
111 | + } elseif ($file->isDir()) { |
|
112 | + rmdir($file->getPathname()); |
|
113 | + } elseif ($file->isFile() || $file->isLink()) { |
|
114 | + unlink($file->getPathname()); |
|
115 | + } |
|
116 | + $it->next(); |
|
117 | + } |
|
118 | + return rmdir($this->getSourcePath($path)); |
|
119 | + } catch (\UnexpectedValueException $e) { |
|
120 | + return false; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + public function opendir($path) { |
|
125 | + return opendir($this->getSourcePath($path)); |
|
126 | + } |
|
127 | + |
|
128 | + public function is_dir($path) { |
|
129 | + if (substr($path, -1) == '/') { |
|
130 | + $path = substr($path, 0, -1); |
|
131 | + } |
|
132 | + return is_dir($this->getSourcePath($path)); |
|
133 | + } |
|
134 | + |
|
135 | + public function is_file($path) { |
|
136 | + return is_file($this->getSourcePath($path)); |
|
137 | + } |
|
138 | + |
|
139 | + public function stat($path) { |
|
140 | + clearstatcache(); |
|
141 | + $fullPath = $this->getSourcePath($path); |
|
142 | + $statResult = stat($fullPath); |
|
143 | + if (PHP_INT_SIZE === 4 && !$this->is_dir($path)) { |
|
144 | + $filesize = $this->filesize($path); |
|
145 | + $statResult['size'] = $filesize; |
|
146 | + $statResult[7] = $filesize; |
|
147 | + } |
|
148 | + return $statResult; |
|
149 | + } |
|
150 | + |
|
151 | + public function filetype($path) { |
|
152 | + $filetype = filetype($this->getSourcePath($path)); |
|
153 | + if ($filetype == 'link') { |
|
154 | + $filetype = filetype(realpath($this->getSourcePath($path))); |
|
155 | + } |
|
156 | + return $filetype; |
|
157 | + } |
|
158 | + |
|
159 | + public function filesize($path) { |
|
160 | + if ($this->is_dir($path)) { |
|
161 | + return 0; |
|
162 | + } |
|
163 | + $fullPath = $this->getSourcePath($path); |
|
164 | + if (PHP_INT_SIZE === 4) { |
|
165 | + $helper = new \OC\LargeFileHelper; |
|
166 | + return $helper->getFileSize($fullPath); |
|
167 | + } |
|
168 | + return filesize($fullPath); |
|
169 | + } |
|
170 | + |
|
171 | + public function isReadable($path) { |
|
172 | + return is_readable($this->getSourcePath($path)); |
|
173 | + } |
|
174 | + |
|
175 | + public function isUpdatable($path) { |
|
176 | + return is_writable($this->getSourcePath($path)); |
|
177 | + } |
|
178 | + |
|
179 | + public function file_exists($path) { |
|
180 | + return file_exists($this->getSourcePath($path)); |
|
181 | + } |
|
182 | + |
|
183 | + public function filemtime($path) { |
|
184 | + $fullPath = $this->getSourcePath($path); |
|
185 | + clearstatcache(true, $fullPath); |
|
186 | + if (!$this->file_exists($path)) { |
|
187 | + return false; |
|
188 | + } |
|
189 | + if (PHP_INT_SIZE === 4) { |
|
190 | + $helper = new \OC\LargeFileHelper(); |
|
191 | + return $helper->getFileMtime($fullPath); |
|
192 | + } |
|
193 | + return filemtime($fullPath); |
|
194 | + } |
|
195 | + |
|
196 | + public function touch($path, $mtime = null) { |
|
197 | + // sets the modification time of the file to the given value. |
|
198 | + // If mtime is nil the current time is set. |
|
199 | + // note that the access time of the file always changes to the current time. |
|
200 | + if ($this->file_exists($path) and !$this->isUpdatable($path)) { |
|
201 | + return false; |
|
202 | + } |
|
203 | + if (!is_null($mtime)) { |
|
204 | + $result = touch($this->getSourcePath($path), $mtime); |
|
205 | + } else { |
|
206 | + $result = touch($this->getSourcePath($path)); |
|
207 | + } |
|
208 | + if ($result) { |
|
209 | + clearstatcache(true, $this->getSourcePath($path)); |
|
210 | + } |
|
211 | + |
|
212 | + return $result; |
|
213 | + } |
|
214 | + |
|
215 | + public function file_get_contents($path) { |
|
216 | + return file_get_contents($this->getSourcePath($path)); |
|
217 | + } |
|
218 | + |
|
219 | + public function file_put_contents($path, $data) { |
|
220 | + return file_put_contents($this->getSourcePath($path), $data); |
|
221 | + } |
|
222 | + |
|
223 | + public function unlink($path) { |
|
224 | + if ($this->is_dir($path)) { |
|
225 | + return $this->rmdir($path); |
|
226 | + } else if ($this->is_file($path)) { |
|
227 | + return unlink($this->getSourcePath($path)); |
|
228 | + } else { |
|
229 | + return false; |
|
230 | + } |
|
231 | + |
|
232 | + } |
|
233 | + |
|
234 | + public function rename($path1, $path2) { |
|
235 | + $srcParent = dirname($path1); |
|
236 | + $dstParent = dirname($path2); |
|
237 | + |
|
238 | + if (!$this->isUpdatable($srcParent)) { |
|
239 | + \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, \OCP\Util::ERROR); |
|
240 | + return false; |
|
241 | + } |
|
242 | + |
|
243 | + if (!$this->isUpdatable($dstParent)) { |
|
244 | + \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, \OCP\Util::ERROR); |
|
245 | + return false; |
|
246 | + } |
|
247 | + |
|
248 | + if (!$this->file_exists($path1)) { |
|
249 | + \OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, \OCP\Util::ERROR); |
|
250 | + return false; |
|
251 | + } |
|
252 | + |
|
253 | + if ($this->is_dir($path2)) { |
|
254 | + $this->rmdir($path2); |
|
255 | + } else if ($this->is_file($path2)) { |
|
256 | + $this->unlink($path2); |
|
257 | + } |
|
258 | + |
|
259 | + if ($this->is_dir($path1)) { |
|
260 | + // we can't move folders across devices, use copy instead |
|
261 | + $stat1 = stat(dirname($this->getSourcePath($path1))); |
|
262 | + $stat2 = stat(dirname($this->getSourcePath($path2))); |
|
263 | + if ($stat1['dev'] !== $stat2['dev']) { |
|
264 | + $result = $this->copy($path1, $path2); |
|
265 | + if ($result) { |
|
266 | + $result &= $this->rmdir($path1); |
|
267 | + } |
|
268 | + return $result; |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + return rename($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
273 | + } |
|
274 | + |
|
275 | + public function copy($path1, $path2) { |
|
276 | + if ($this->is_dir($path1)) { |
|
277 | + return parent::copy($path1, $path2); |
|
278 | + } else { |
|
279 | + return copy($this->getSourcePath($path1), $this->getSourcePath($path2)); |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + public function fopen($path, $mode) { |
|
284 | + return fopen($this->getSourcePath($path), $mode); |
|
285 | + } |
|
286 | + |
|
287 | + public function hash($type, $path, $raw = false) { |
|
288 | + return hash_file($type, $this->getSourcePath($path), $raw); |
|
289 | + } |
|
290 | + |
|
291 | + public function free_space($path) { |
|
292 | + $sourcePath = $this->getSourcePath($path); |
|
293 | + // using !is_dir because $sourcePath might be a part file or |
|
294 | + // non-existing file, so we'd still want to use the parent dir |
|
295 | + // in such cases |
|
296 | + if (!is_dir($sourcePath)) { |
|
297 | + // disk_free_space doesn't work on files |
|
298 | + $sourcePath = dirname($sourcePath); |
|
299 | + } |
|
300 | + $space = @disk_free_space($sourcePath); |
|
301 | + if ($space === false || is_null($space)) { |
|
302 | + return \OCP\Files\FileInfo::SPACE_UNKNOWN; |
|
303 | + } |
|
304 | + return $space; |
|
305 | + } |
|
306 | + |
|
307 | + public function search($query) { |
|
308 | + return $this->searchInDir($query); |
|
309 | + } |
|
310 | + |
|
311 | + public function getLocalFile($path) { |
|
312 | + return $this->getSourcePath($path); |
|
313 | + } |
|
314 | + |
|
315 | + public function getLocalFolder($path) { |
|
316 | + return $this->getSourcePath($path); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * @param string $query |
|
321 | + * @param string $dir |
|
322 | + * @return array |
|
323 | + */ |
|
324 | + protected function searchInDir($query, $dir = '') { |
|
325 | + $files = array(); |
|
326 | + $physicalDir = $this->getSourcePath($dir); |
|
327 | + foreach (scandir($physicalDir) as $item) { |
|
328 | + if (\OC\Files\Filesystem::isIgnoredDir($item)) |
|
329 | + continue; |
|
330 | + $physicalItem = $physicalDir . '/' . $item; |
|
331 | + |
|
332 | + if (strstr(strtolower($item), strtolower($query)) !== false) { |
|
333 | + $files[] = $dir . '/' . $item; |
|
334 | + } |
|
335 | + if (is_dir($physicalItem)) { |
|
336 | + $files = array_merge($files, $this->searchInDir($query, $dir . '/' . $item)); |
|
337 | + } |
|
338 | + } |
|
339 | + return $files; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * check if a file or folder has been updated since $time |
|
344 | + * |
|
345 | + * @param string $path |
|
346 | + * @param int $time |
|
347 | + * @return bool |
|
348 | + */ |
|
349 | + public function hasUpdated($path, $time) { |
|
350 | + if ($this->file_exists($path)) { |
|
351 | + return $this->filemtime($path) > $time; |
|
352 | + } else { |
|
353 | + return true; |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Get the source path (on disk) of a given path |
|
359 | + * |
|
360 | + * @param string $path |
|
361 | + * @return string |
|
362 | + * @throws ForbiddenException |
|
363 | + */ |
|
364 | + public function getSourcePath($path) { |
|
365 | + $fullPath = $this->datadir . $path; |
|
366 | + $currentPath = $path; |
|
367 | + if ($this->allowSymlinks || $currentPath === '') { |
|
368 | + return $fullPath; |
|
369 | + } |
|
370 | + $pathToResolve = $fullPath; |
|
371 | + $realPath = realpath($pathToResolve); |
|
372 | + while ($realPath === false) { // for non existing files check the parent directory |
|
373 | + $currentPath = dirname($currentPath); |
|
374 | + if ($currentPath === '' || $currentPath === '.') { |
|
375 | + return $fullPath; |
|
376 | + } |
|
377 | + $realPath = realpath($this->datadir . $currentPath); |
|
378 | + } |
|
379 | + if ($realPath) { |
|
380 | + $realPath = $realPath . '/'; |
|
381 | + } |
|
382 | + if (substr($realPath, 0, $this->dataDirLength) === $this->realDataDir) { |
|
383 | + return $fullPath; |
|
384 | + } |
|
385 | + |
|
386 | + \OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", \OCP\Util::ERROR); |
|
387 | + throw new ForbiddenException('Following symlinks is not allowed', false); |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * {@inheritdoc} |
|
392 | + */ |
|
393 | + public function isLocal() { |
|
394 | + return true; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * get the ETag for a file or folder |
|
399 | + * |
|
400 | + * @param string $path |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + public function getETag($path) { |
|
404 | + if ($this->is_file($path)) { |
|
405 | + $stat = $this->stat($path); |
|
406 | + return md5( |
|
407 | + $stat['mtime'] . |
|
408 | + $stat['ino'] . |
|
409 | + $stat['dev'] . |
|
410 | + $stat['size'] |
|
411 | + ); |
|
412 | + } else { |
|
413 | + return parent::getETag($path); |
|
414 | + } |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * @param IStorage $sourceStorage |
|
419 | + * @param string $sourceInternalPath |
|
420 | + * @param string $targetInternalPath |
|
421 | + * @param bool $preserveMtime |
|
422 | + * @return bool |
|
423 | + */ |
|
424 | + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { |
|
425 | + if ($sourceStorage->instanceOfStorage(Local::class)) { |
|
426 | + if ($sourceStorage->instanceOfStorage(Jail::class)) { |
|
427 | + /** |
|
428 | + * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage |
|
429 | + */ |
|
430 | + $sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath); |
|
431 | + } |
|
432 | + /** |
|
433 | + * @var \OC\Files\Storage\Local $sourceStorage |
|
434 | + */ |
|
435 | + $rootStorage = new Local(['datadir' => '/']); |
|
436 | + return $rootStorage->copy($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath)); |
|
437 | + } else { |
|
438 | + return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
439 | + } |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * @param IStorage $sourceStorage |
|
444 | + * @param string $sourceInternalPath |
|
445 | + * @param string $targetInternalPath |
|
446 | + * @return bool |
|
447 | + */ |
|
448 | + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { |
|
449 | + if ($sourceStorage->instanceOfStorage(Local::class)) { |
|
450 | + if ($sourceStorage->instanceOfStorage(Jail::class)) { |
|
451 | + /** |
|
452 | + * @var \OC\Files\Storage\Wrapper\Jail $sourceStorage |
|
453 | + */ |
|
454 | + $sourceInternalPath = $sourceStorage->getUnjailedPath($sourceInternalPath); |
|
455 | + } |
|
456 | + /** |
|
457 | + * @var \OC\Files\Storage\Local $sourceStorage |
|
458 | + */ |
|
459 | + $rootStorage = new Local(['datadir' => '/']); |
|
460 | + return $rootStorage->rename($sourceStorage->getSourcePath($sourceInternalPath), $this->getSourcePath($targetInternalPath)); |
|
461 | + } else { |
|
462 | + return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); |
|
463 | + } |
|
464 | + } |
|
465 | 465 | } |