Completed
Push — master ( b2c886...09d7dd )
by
unknown
25:59
created
lib/private/legacy/OC_User.php 2 patches
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -40,320 +40,320 @@
 block discarded – undo
40 40
  *   logout()
41 41
  */
42 42
 class OC_User {
43
-	private static $_setupedBackends = [];
44
-
45
-	// bool, stores if a user want to access a resource anonymously, e.g if they open a public link
46
-	private static $incognitoMode = false;
47
-
48
-	/**
49
-	 * Adds the backend to the list of used backends
50
-	 *
51
-	 * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
52
-	 * @return bool
53
-	 * @deprecated 32.0.0 Use IUserManager::registerBackend instead
54
-	 *
55
-	 * Set the User Authentication Module
56
-	 */
57
-	public static function useBackend($backend = 'database') {
58
-		if ($backend instanceof \OCP\UserInterface) {
59
-			Server::get(IUserManager::class)->registerBackend($backend);
60
-		} else {
61
-			// You'll never know what happens
62
-			if ($backend === null || !is_string($backend)) {
63
-				$backend = 'database';
64
-			}
65
-
66
-			// Load backend
67
-			switch ($backend) {
68
-				case 'database':
69
-				case 'mysql':
70
-				case 'sqlite':
71
-					Server::get(LoggerInterface::class)->debug('Adding user backend ' . $backend . '.', ['app' => 'core']);
72
-					Server::get(IUserManager::class)->registerBackend(new \OC\User\Database());
73
-					break;
74
-				case 'dummy':
75
-					Server::get(IUserManager::class)->registerBackend(new \Test\Util\User\Dummy());
76
-					break;
77
-				default:
78
-					Server::get(LoggerInterface::class)->debug('Adding default user backend ' . $backend . '.', ['app' => 'core']);
79
-					$className = 'OC_USER_' . strtoupper($backend);
80
-					Server::get(IUserManager::class)->registerBackend(new $className());
81
-					break;
82
-			}
83
-		}
84
-		return true;
85
-	}
86
-
87
-	/**
88
-	 * remove all used backends
89
-	 * @deprecated 32.0.0 Use IUserManager::clearBackends instead
90
-	 */
91
-	public static function clearBackends() {
92
-		Server::get(IUserManager::class)->clearBackends();
93
-	}
94
-
95
-	/**
96
-	 * setup the configured backends in config.php
97
-	 * @suppress PhanDeprecatedFunction
98
-	 */
99
-	public static function setupBackends() {
100
-		OC_App::loadApps(['prelogin']);
101
-		$backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
102
-		if (isset($backends['default']) && !$backends['default']) {
103
-			// clear default backends
104
-			self::clearBackends();
105
-		}
106
-		foreach ($backends as $i => $config) {
107
-			if (!is_array($config)) {
108
-				continue;
109
-			}
110
-			$class = $config['class'];
111
-			$arguments = $config['arguments'];
112
-			if (class_exists($class)) {
113
-				if (!in_array($i, self::$_setupedBackends)) {
114
-					// make a reflection object
115
-					$reflectionObj = new ReflectionClass($class);
116
-
117
-					// use Reflection to create a new instance, using the $args
118
-					$backend = $reflectionObj->newInstanceArgs($arguments);
119
-					self::useBackend($backend);
120
-					self::$_setupedBackends[] = $i;
121
-				} else {
122
-					Server::get(LoggerInterface::class)->debug('User backend ' . $class . ' already initialized.', ['app' => 'core']);
123
-				}
124
-			} else {
125
-				Server::get(LoggerInterface::class)->error('User backend ' . $class . ' not found.', ['app' => 'core']);
126
-			}
127
-		}
128
-	}
129
-
130
-	/**
131
-	 * Try to login a user, assuming authentication
132
-	 * has already happened (e.g. via Single Sign On).
133
-	 *
134
-	 * Log in a user and regenerate a new session.
135
-	 *
136
-	 * @param \OCP\Authentication\IApacheBackend $backend
137
-	 * @return bool
138
-	 */
139
-	public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
140
-		$uid = $backend->getCurrentUserId();
141
-		$run = true;
142
-		OC_Hook::emit('OC_User', 'pre_login', ['run' => &$run, 'uid' => $uid, 'backend' => $backend]);
143
-
144
-		if ($uid) {
145
-			if (self::getUser() !== $uid) {
146
-				self::setUserId($uid);
147
-				$userSession = \OC::$server->getUserSession();
148
-
149
-				/** @var IEventDispatcher $dispatcher */
150
-				$dispatcher = \OC::$server->get(IEventDispatcher::class);
151
-
152
-				if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
153
-					$message = \OC::$server->getL10N('lib')->t('Account disabled');
154
-					throw new DisabledUserException($message);
155
-				}
156
-				$userSession->setLoginName($uid);
157
-				$request = OC::$server->getRequest();
158
-				$password = null;
159
-				if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
160
-					$password = $backend->getCurrentUserSecret();
161
-				}
162
-
163
-				/** @var IEventDispatcher $dispatcher */
164
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password, $backend));
165
-
166
-				$userSession->createSessionToken($request, $uid, $uid, $password);
167
-				$userSession->createRememberMeToken($userSession->getUser());
168
-
169
-				if (empty($password)) {
170
-					$tokenProvider = \OC::$server->get(IProvider::class);
171
-					try {
172
-						$token = $tokenProvider->getToken($userSession->getSession()->getId());
173
-						$token->setScope([
174
-							IToken::SCOPE_SKIP_PASSWORD_VALIDATION => true,
175
-							IToken::SCOPE_FILESYSTEM => true,
176
-						]);
177
-						$tokenProvider->updateToken($token);
178
-					} catch (InvalidTokenException|WipeTokenException|SessionNotAvailableException) {
179
-						// swallow the exceptions as we do not deal with them here
180
-						// simply skip updating the token when is it missing
181
-					}
182
-				}
183
-
184
-				// setup the filesystem
185
-				OC_Util::setupFS($uid);
186
-				// first call the post_login hooks, the login-process needs to be
187
-				// completed before we can safely create the users folder.
188
-				// For example encryption needs to initialize the users keys first
189
-				// before we can create the user folder with the skeleton files
190
-				OC_Hook::emit(
191
-					'OC_User',
192
-					'post_login',
193
-					[
194
-						'uid' => $uid,
195
-						'password' => $password,
196
-						'isTokenLogin' => false,
197
-					]
198
-				);
199
-				$dispatcher->dispatchTyped(new UserLoggedInEvent(
200
-					\OC::$server->get(IUserManager::class)->get($uid),
201
-					$uid,
202
-					null,
203
-					false)
204
-				);
205
-
206
-				//trigger creation of user home and /files folder
207
-				\OC::$server->getUserFolder($uid);
208
-			}
209
-			return true;
210
-		}
211
-		return false;
212
-	}
213
-
214
-	/**
215
-	 * Verify with Apache whether user is authenticated.
216
-	 *
217
-	 * @return boolean|null
218
-	 *                      true: authenticated
219
-	 *                      false: not authenticated
220
-	 *                      null: not handled / no backend available
221
-	 */
222
-	public static function handleApacheAuth() {
223
-		$backend = self::findFirstActiveUsedBackend();
224
-		if ($backend) {
225
-			OC_App::loadApps();
226
-
227
-			//setup extra user backends
228
-			self::setupBackends();
229
-			\OC::$server->getUserSession()->unsetMagicInCookie();
230
-
231
-			return self::loginWithApache($backend);
232
-		}
233
-
234
-		return null;
235
-	}
236
-
237
-
238
-	/**
239
-	 * Sets user id for session and triggers emit
240
-	 *
241
-	 * @param string $uid
242
-	 */
243
-	public static function setUserId($uid) {
244
-		$userSession = \OC::$server->getUserSession();
245
-		$userManager = Server::get(IUserManager::class);
246
-		if ($user = $userManager->get($uid)) {
247
-			$userSession->setUser($user);
248
-		} else {
249
-			\OC::$server->getSession()->set('user_id', $uid);
250
-		}
251
-	}
252
-
253
-	/**
254
-	 * set incognito mode, e.g. if a user wants to open a public link
255
-	 *
256
-	 * @param bool $status
257
-	 */
258
-	public static function setIncognitoMode($status) {
259
-		self::$incognitoMode = $status;
260
-	}
261
-
262
-	/**
263
-	 * get incognito mode status
264
-	 *
265
-	 * @return bool
266
-	 */
267
-	public static function isIncognitoMode() {
268
-		return self::$incognitoMode;
269
-	}
270
-
271
-	/**
272
-	 * Returns the current logout URL valid for the currently logged-in user
273
-	 *
274
-	 * @param \OCP\IURLGenerator $urlGenerator
275
-	 * @return string
276
-	 */
277
-	public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
278
-		$backend = self::findFirstActiveUsedBackend();
279
-		if ($backend) {
280
-			return $backend->getLogoutUrl();
281
-		}
282
-
283
-		$user = \OC::$server->getUserSession()->getUser();
284
-		if ($user instanceof IUser) {
285
-			$backend = $user->getBackend();
286
-			if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
287
-				return $backend->getLogoutUrl();
288
-			}
289
-		}
290
-
291
-		$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
292
-		$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
293
-
294
-		return $logoutUrl;
295
-	}
296
-
297
-	/**
298
-	 * Check if the user is an admin user
299
-	 *
300
-	 * @param string $uid uid of the admin
301
-	 * @return bool
302
-	 */
303
-	public static function isAdminUser($uid) {
304
-		$user = Server::get(IUserManager::class)->get($uid);
305
-		$isAdmin = $user && Server::get(IGroupManager::class)->isAdmin($user->getUID());
306
-		return $isAdmin && self::$incognitoMode === false;
307
-	}
308
-
309
-
310
-	/**
311
-	 * get the user id of the user currently logged in.
312
-	 *
313
-	 * @return string|false uid or false
314
-	 */
315
-	public static function getUser() {
316
-		$uid = Server::get(ISession::class)?->get('user_id');
317
-		if (!is_null($uid) && self::$incognitoMode === false) {
318
-			return $uid;
319
-		} else {
320
-			return false;
321
-		}
322
-	}
323
-
324
-	/**
325
-	 * Set password
326
-	 *
327
-	 * @param string $uid The username
328
-	 * @param string $password The new password
329
-	 * @param string $recoveryPassword for the encryption app to reset encryption keys
330
-	 * @return bool
331
-	 *
332
-	 * Change the password of a user
333
-	 */
334
-	public static function setPassword($uid, $password, $recoveryPassword = null) {
335
-		$user = Server::get(IUserManager::class)->get($uid);
336
-		if ($user) {
337
-			return $user->setPassword($password, $recoveryPassword);
338
-		} else {
339
-			return false;
340
-		}
341
-	}
342
-
343
-	/**
344
-	 * Returns the first active backend from self::$_usedBackends.
345
-	 *
346
-	 * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
347
-	 */
348
-	private static function findFirstActiveUsedBackend() {
349
-		foreach (Server::get(IUserManager::class)->getBackends() as $backend) {
350
-			if ($backend instanceof OCP\Authentication\IApacheBackend) {
351
-				if ($backend->isSessionActive()) {
352
-					return $backend;
353
-				}
354
-			}
355
-		}
356
-
357
-		return null;
358
-	}
43
+    private static $_setupedBackends = [];
44
+
45
+    // bool, stores if a user want to access a resource anonymously, e.g if they open a public link
46
+    private static $incognitoMode = false;
47
+
48
+    /**
49
+     * Adds the backend to the list of used backends
50
+     *
51
+     * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
52
+     * @return bool
53
+     * @deprecated 32.0.0 Use IUserManager::registerBackend instead
54
+     *
55
+     * Set the User Authentication Module
56
+     */
57
+    public static function useBackend($backend = 'database') {
58
+        if ($backend instanceof \OCP\UserInterface) {
59
+            Server::get(IUserManager::class)->registerBackend($backend);
60
+        } else {
61
+            // You'll never know what happens
62
+            if ($backend === null || !is_string($backend)) {
63
+                $backend = 'database';
64
+            }
65
+
66
+            // Load backend
67
+            switch ($backend) {
68
+                case 'database':
69
+                case 'mysql':
70
+                case 'sqlite':
71
+                    Server::get(LoggerInterface::class)->debug('Adding user backend ' . $backend . '.', ['app' => 'core']);
72
+                    Server::get(IUserManager::class)->registerBackend(new \OC\User\Database());
73
+                    break;
74
+                case 'dummy':
75
+                    Server::get(IUserManager::class)->registerBackend(new \Test\Util\User\Dummy());
76
+                    break;
77
+                default:
78
+                    Server::get(LoggerInterface::class)->debug('Adding default user backend ' . $backend . '.', ['app' => 'core']);
79
+                    $className = 'OC_USER_' . strtoupper($backend);
80
+                    Server::get(IUserManager::class)->registerBackend(new $className());
81
+                    break;
82
+            }
83
+        }
84
+        return true;
85
+    }
86
+
87
+    /**
88
+     * remove all used backends
89
+     * @deprecated 32.0.0 Use IUserManager::clearBackends instead
90
+     */
91
+    public static function clearBackends() {
92
+        Server::get(IUserManager::class)->clearBackends();
93
+    }
94
+
95
+    /**
96
+     * setup the configured backends in config.php
97
+     * @suppress PhanDeprecatedFunction
98
+     */
99
+    public static function setupBackends() {
100
+        OC_App::loadApps(['prelogin']);
101
+        $backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
102
+        if (isset($backends['default']) && !$backends['default']) {
103
+            // clear default backends
104
+            self::clearBackends();
105
+        }
106
+        foreach ($backends as $i => $config) {
107
+            if (!is_array($config)) {
108
+                continue;
109
+            }
110
+            $class = $config['class'];
111
+            $arguments = $config['arguments'];
112
+            if (class_exists($class)) {
113
+                if (!in_array($i, self::$_setupedBackends)) {
114
+                    // make a reflection object
115
+                    $reflectionObj = new ReflectionClass($class);
116
+
117
+                    // use Reflection to create a new instance, using the $args
118
+                    $backend = $reflectionObj->newInstanceArgs($arguments);
119
+                    self::useBackend($backend);
120
+                    self::$_setupedBackends[] = $i;
121
+                } else {
122
+                    Server::get(LoggerInterface::class)->debug('User backend ' . $class . ' already initialized.', ['app' => 'core']);
123
+                }
124
+            } else {
125
+                Server::get(LoggerInterface::class)->error('User backend ' . $class . ' not found.', ['app' => 'core']);
126
+            }
127
+        }
128
+    }
129
+
130
+    /**
131
+     * Try to login a user, assuming authentication
132
+     * has already happened (e.g. via Single Sign On).
133
+     *
134
+     * Log in a user and regenerate a new session.
135
+     *
136
+     * @param \OCP\Authentication\IApacheBackend $backend
137
+     * @return bool
138
+     */
139
+    public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
140
+        $uid = $backend->getCurrentUserId();
141
+        $run = true;
142
+        OC_Hook::emit('OC_User', 'pre_login', ['run' => &$run, 'uid' => $uid, 'backend' => $backend]);
143
+
144
+        if ($uid) {
145
+            if (self::getUser() !== $uid) {
146
+                self::setUserId($uid);
147
+                $userSession = \OC::$server->getUserSession();
148
+
149
+                /** @var IEventDispatcher $dispatcher */
150
+                $dispatcher = \OC::$server->get(IEventDispatcher::class);
151
+
152
+                if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
153
+                    $message = \OC::$server->getL10N('lib')->t('Account disabled');
154
+                    throw new DisabledUserException($message);
155
+                }
156
+                $userSession->setLoginName($uid);
157
+                $request = OC::$server->getRequest();
158
+                $password = null;
159
+                if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
160
+                    $password = $backend->getCurrentUserSecret();
161
+                }
162
+
163
+                /** @var IEventDispatcher $dispatcher */
164
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password, $backend));
165
+
166
+                $userSession->createSessionToken($request, $uid, $uid, $password);
167
+                $userSession->createRememberMeToken($userSession->getUser());
168
+
169
+                if (empty($password)) {
170
+                    $tokenProvider = \OC::$server->get(IProvider::class);
171
+                    try {
172
+                        $token = $tokenProvider->getToken($userSession->getSession()->getId());
173
+                        $token->setScope([
174
+                            IToken::SCOPE_SKIP_PASSWORD_VALIDATION => true,
175
+                            IToken::SCOPE_FILESYSTEM => true,
176
+                        ]);
177
+                        $tokenProvider->updateToken($token);
178
+                    } catch (InvalidTokenException|WipeTokenException|SessionNotAvailableException) {
179
+                        // swallow the exceptions as we do not deal with them here
180
+                        // simply skip updating the token when is it missing
181
+                    }
182
+                }
183
+
184
+                // setup the filesystem
185
+                OC_Util::setupFS($uid);
186
+                // first call the post_login hooks, the login-process needs to be
187
+                // completed before we can safely create the users folder.
188
+                // For example encryption needs to initialize the users keys first
189
+                // before we can create the user folder with the skeleton files
190
+                OC_Hook::emit(
191
+                    'OC_User',
192
+                    'post_login',
193
+                    [
194
+                        'uid' => $uid,
195
+                        'password' => $password,
196
+                        'isTokenLogin' => false,
197
+                    ]
198
+                );
199
+                $dispatcher->dispatchTyped(new UserLoggedInEvent(
200
+                    \OC::$server->get(IUserManager::class)->get($uid),
201
+                    $uid,
202
+                    null,
203
+                    false)
204
+                );
205
+
206
+                //trigger creation of user home and /files folder
207
+                \OC::$server->getUserFolder($uid);
208
+            }
209
+            return true;
210
+        }
211
+        return false;
212
+    }
213
+
214
+    /**
215
+     * Verify with Apache whether user is authenticated.
216
+     *
217
+     * @return boolean|null
218
+     *                      true: authenticated
219
+     *                      false: not authenticated
220
+     *                      null: not handled / no backend available
221
+     */
222
+    public static function handleApacheAuth() {
223
+        $backend = self::findFirstActiveUsedBackend();
224
+        if ($backend) {
225
+            OC_App::loadApps();
226
+
227
+            //setup extra user backends
228
+            self::setupBackends();
229
+            \OC::$server->getUserSession()->unsetMagicInCookie();
230
+
231
+            return self::loginWithApache($backend);
232
+        }
233
+
234
+        return null;
235
+    }
236
+
237
+
238
+    /**
239
+     * Sets user id for session and triggers emit
240
+     *
241
+     * @param string $uid
242
+     */
243
+    public static function setUserId($uid) {
244
+        $userSession = \OC::$server->getUserSession();
245
+        $userManager = Server::get(IUserManager::class);
246
+        if ($user = $userManager->get($uid)) {
247
+            $userSession->setUser($user);
248
+        } else {
249
+            \OC::$server->getSession()->set('user_id', $uid);
250
+        }
251
+    }
252
+
253
+    /**
254
+     * set incognito mode, e.g. if a user wants to open a public link
255
+     *
256
+     * @param bool $status
257
+     */
258
+    public static function setIncognitoMode($status) {
259
+        self::$incognitoMode = $status;
260
+    }
261
+
262
+    /**
263
+     * get incognito mode status
264
+     *
265
+     * @return bool
266
+     */
267
+    public static function isIncognitoMode() {
268
+        return self::$incognitoMode;
269
+    }
270
+
271
+    /**
272
+     * Returns the current logout URL valid for the currently logged-in user
273
+     *
274
+     * @param \OCP\IURLGenerator $urlGenerator
275
+     * @return string
276
+     */
277
+    public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
278
+        $backend = self::findFirstActiveUsedBackend();
279
+        if ($backend) {
280
+            return $backend->getLogoutUrl();
281
+        }
282
+
283
+        $user = \OC::$server->getUserSession()->getUser();
284
+        if ($user instanceof IUser) {
285
+            $backend = $user->getBackend();
286
+            if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
287
+                return $backend->getLogoutUrl();
288
+            }
289
+        }
290
+
291
+        $logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
292
+        $logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
293
+
294
+        return $logoutUrl;
295
+    }
296
+
297
+    /**
298
+     * Check if the user is an admin user
299
+     *
300
+     * @param string $uid uid of the admin
301
+     * @return bool
302
+     */
303
+    public static function isAdminUser($uid) {
304
+        $user = Server::get(IUserManager::class)->get($uid);
305
+        $isAdmin = $user && Server::get(IGroupManager::class)->isAdmin($user->getUID());
306
+        return $isAdmin && self::$incognitoMode === false;
307
+    }
308
+
309
+
310
+    /**
311
+     * get the user id of the user currently logged in.
312
+     *
313
+     * @return string|false uid or false
314
+     */
315
+    public static function getUser() {
316
+        $uid = Server::get(ISession::class)?->get('user_id');
317
+        if (!is_null($uid) && self::$incognitoMode === false) {
318
+            return $uid;
319
+        } else {
320
+            return false;
321
+        }
322
+    }
323
+
324
+    /**
325
+     * Set password
326
+     *
327
+     * @param string $uid The username
328
+     * @param string $password The new password
329
+     * @param string $recoveryPassword for the encryption app to reset encryption keys
330
+     * @return bool
331
+     *
332
+     * Change the password of a user
333
+     */
334
+    public static function setPassword($uid, $password, $recoveryPassword = null) {
335
+        $user = Server::get(IUserManager::class)->get($uid);
336
+        if ($user) {
337
+            return $user->setPassword($password, $recoveryPassword);
338
+        } else {
339
+            return false;
340
+        }
341
+    }
342
+
343
+    /**
344
+     * Returns the first active backend from self::$_usedBackends.
345
+     *
346
+     * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
347
+     */
348
+    private static function findFirstActiveUsedBackend() {
349
+        foreach (Server::get(IUserManager::class)->getBackends() as $backend) {
350
+            if ($backend instanceof OCP\Authentication\IApacheBackend) {
351
+                if ($backend->isSessionActive()) {
352
+                    return $backend;
353
+                }
354
+            }
355
+        }
356
+
357
+        return null;
358
+    }
359 359
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -68,15 +68,15 @@  discard block
 block discarded – undo
68 68
 				case 'database':
69 69
 				case 'mysql':
70 70
 				case 'sqlite':
71
-					Server::get(LoggerInterface::class)->debug('Adding user backend ' . $backend . '.', ['app' => 'core']);
71
+					Server::get(LoggerInterface::class)->debug('Adding user backend '.$backend.'.', ['app' => 'core']);
72 72
 					Server::get(IUserManager::class)->registerBackend(new \OC\User\Database());
73 73
 					break;
74 74
 				case 'dummy':
75 75
 					Server::get(IUserManager::class)->registerBackend(new \Test\Util\User\Dummy());
76 76
 					break;
77 77
 				default:
78
-					Server::get(LoggerInterface::class)->debug('Adding default user backend ' . $backend . '.', ['app' => 'core']);
79
-					$className = 'OC_USER_' . strtoupper($backend);
78
+					Server::get(LoggerInterface::class)->debug('Adding default user backend '.$backend.'.', ['app' => 'core']);
79
+					$className = 'OC_USER_'.strtoupper($backend);
80 80
 					Server::get(IUserManager::class)->registerBackend(new $className());
81 81
 					break;
82 82
 			}
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
 					self::useBackend($backend);
120 120
 					self::$_setupedBackends[] = $i;
121 121
 				} else {
122
-					Server::get(LoggerInterface::class)->debug('User backend ' . $class . ' already initialized.', ['app' => 'core']);
122
+					Server::get(LoggerInterface::class)->debug('User backend '.$class.' already initialized.', ['app' => 'core']);
123 123
 				}
124 124
 			} else {
125
-				Server::get(LoggerInterface::class)->error('User backend ' . $class . ' not found.', ['app' => 'core']);
125
+				Server::get(LoggerInterface::class)->error('User backend '.$class.' not found.', ['app' => 'core']);
126 126
 			}
127 127
 		}
128 128
 	}
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 							IToken::SCOPE_FILESYSTEM => true,
176 176
 						]);
177 177
 						$tokenProvider->updateToken($token);
178
-					} catch (InvalidTokenException|WipeTokenException|SessionNotAvailableException) {
178
+					} catch (InvalidTokenException | WipeTokenException | SessionNotAvailableException) {
179 179
 						// swallow the exceptions as we do not deal with them here
180 180
 						// simply skip updating the token when is it missing
181 181
 					}
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 		}
290 290
 
291 291
 		$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
292
-		$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
292
+		$logoutUrl .= '?requesttoken='.urlencode(\OCP\Util::callRegister());
293 293
 
294 294
 		return $logoutUrl;
295 295
 	}
Please login to merge, or discard this patch.
lib/private/Files/Filesystem.php 2 patches
Indentation   +690 added lines, -690 removed lines patch added patch discarded remove patch
@@ -22,694 +22,694 @@
 block discarded – undo
22 22
 use Psr\Log\LoggerInterface;
23 23
 
24 24
 class Filesystem {
25
-	private static ?Mount\Manager $mounts = null;
26
-
27
-	public static bool $loaded = false;
28
-
29
-	private static ?View $defaultInstance = null;
30
-
31
-	private static ?CappedMemoryCache $normalizedPathCache = null;
32
-
33
-	private static ?FilenameValidator $validator = null;
34
-
35
-	/**
36
-	 * classname which used for hooks handling
37
-	 * used as signalclass in OC_Hooks::emit()
38
-	 */
39
-	public const CLASSNAME = 'OC_Filesystem';
40
-
41
-	/**
42
-	 * signalname emitted before file renaming
43
-	 *
44
-	 * @param string $oldpath
45
-	 * @param string $newpath
46
-	 */
47
-	public const signal_rename = 'rename';
48
-
49
-	/**
50
-	 * signal emitted after file renaming
51
-	 *
52
-	 * @param string $oldpath
53
-	 * @param string $newpath
54
-	 */
55
-	public const signal_post_rename = 'post_rename';
56
-
57
-	/**
58
-	 * signal emitted before file/dir creation
59
-	 *
60
-	 * @param string $path
61
-	 * @param bool $run changing this flag to false in hook handler will cancel event
62
-	 */
63
-	public const signal_create = 'create';
64
-
65
-	/**
66
-	 * signal emitted after file/dir creation
67
-	 *
68
-	 * @param string $path
69
-	 * @param bool $run changing this flag to false in hook handler will cancel event
70
-	 */
71
-	public const signal_post_create = 'post_create';
72
-
73
-	/**
74
-	 * signal emits before file/dir copy
75
-	 *
76
-	 * @param string $oldpath
77
-	 * @param string $newpath
78
-	 * @param bool $run changing this flag to false in hook handler will cancel event
79
-	 */
80
-	public const signal_copy = 'copy';
81
-
82
-	/**
83
-	 * signal emits after file/dir copy
84
-	 *
85
-	 * @param string $oldpath
86
-	 * @param string $newpath
87
-	 */
88
-	public const signal_post_copy = 'post_copy';
89
-
90
-	/**
91
-	 * signal emits before file/dir save
92
-	 *
93
-	 * @param string $path
94
-	 * @param bool $run changing this flag to false in hook handler will cancel event
95
-	 */
96
-	public const signal_write = 'write';
97
-
98
-	/**
99
-	 * signal emits after file/dir save
100
-	 *
101
-	 * @param string $path
102
-	 */
103
-	public const signal_post_write = 'post_write';
104
-
105
-	/**
106
-	 * signal emitted before file/dir update
107
-	 *
108
-	 * @param string $path
109
-	 * @param bool $run changing this flag to false in hook handler will cancel event
110
-	 */
111
-	public const signal_update = 'update';
112
-
113
-	/**
114
-	 * signal emitted after file/dir update
115
-	 *
116
-	 * @param string $path
117
-	 * @param bool $run changing this flag to false in hook handler will cancel event
118
-	 */
119
-	public const signal_post_update = 'post_update';
120
-
121
-	/**
122
-	 * signal emits when reading file/dir
123
-	 *
124
-	 * @param string $path
125
-	 */
126
-	public const signal_read = 'read';
127
-
128
-	/**
129
-	 * signal emits when removing file/dir
130
-	 *
131
-	 * @param string $path
132
-	 */
133
-	public const signal_delete = 'delete';
134
-
135
-	/**
136
-	 * parameters definitions for signals
137
-	 */
138
-	public const signal_param_path = 'path';
139
-	public const signal_param_oldpath = 'oldpath';
140
-	public const signal_param_newpath = 'newpath';
141
-
142
-	/**
143
-	 * run - changing this flag to false in hook handler will cancel event
144
-	 */
145
-	public const signal_param_run = 'run';
146
-
147
-	public const signal_create_mount = 'create_mount';
148
-	public const signal_delete_mount = 'delete_mount';
149
-	public const signal_param_mount_type = 'mounttype';
150
-	public const signal_param_users = 'users';
151
-
152
-	private static ?\OC\Files\Storage\StorageFactory $loader = null;
153
-
154
-	private static bool $logWarningWhenAddingStorageWrapper = true;
155
-
156
-	/**
157
-	 * @param bool $shouldLog
158
-	 * @return bool previous value
159
-	 * @internal
160
-	 */
161
-	public static function logWarningWhenAddingStorageWrapper(bool $shouldLog): bool {
162
-		$previousValue = self::$logWarningWhenAddingStorageWrapper;
163
-		self::$logWarningWhenAddingStorageWrapper = $shouldLog;
164
-		return $previousValue;
165
-	}
166
-
167
-	/**
168
-	 * @param string $wrapperName
169
-	 * @param callable $wrapper
170
-	 * @param int $priority
171
-	 */
172
-	public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50) {
173
-		if (self::$logWarningWhenAddingStorageWrapper) {
174
-			\OCP\Server::get(LoggerInterface::class)->warning("Storage wrapper '{wrapper}' was not registered via the 'OC_Filesystem - preSetup' hook which could cause potential problems.", [
175
-				'wrapper' => $wrapperName,
176
-				'app' => 'filesystem',
177
-			]);
178
-		}
179
-
180
-		$mounts = self::getMountManager()->getAll();
181
-		/** @var StorageFactory $loader */
182
-		$loader = self::getLoader();
183
-		if (!$loader->addStorageWrapper($wrapperName, $wrapper, $priority, $mounts)) {
184
-			// do not re-wrap if storage with this name already existed
185
-			return;
186
-		}
187
-	}
188
-
189
-	/**
190
-	 * Returns the storage factory
191
-	 *
192
-	 * @return IStorageFactory
193
-	 */
194
-	public static function getLoader() {
195
-		if (!self::$loader) {
196
-			self::$loader = \OC::$server->get(IStorageFactory::class);
197
-		}
198
-		return self::$loader;
199
-	}
200
-
201
-	/**
202
-	 * Returns the mount manager
203
-	 */
204
-	public static function getMountManager(): Mount\Manager {
205
-		self::initMountManager();
206
-		assert(self::$mounts !== null);
207
-		return self::$mounts;
208
-	}
209
-
210
-	/**
211
-	 * get the mountpoint of the storage object for a path
212
-	 * ( note: because a storage is not always mounted inside the fakeroot, the
213
-	 * returned mountpoint is relative to the absolute root of the filesystem
214
-	 * and doesn't take the chroot into account )
215
-	 *
216
-	 * @param string $path
217
-	 * @return string
218
-	 */
219
-	public static function getMountPoint($path) {
220
-		if (!self::$mounts) {
221
-			\OC_Util::setupFS();
222
-		}
223
-		$mount = self::$mounts->find($path);
224
-		return $mount->getMountPoint();
225
-	}
226
-
227
-	/**
228
-	 * get a list of all mount points in a directory
229
-	 *
230
-	 * @param string $path
231
-	 * @return string[]
232
-	 */
233
-	public static function getMountPoints($path) {
234
-		if (!self::$mounts) {
235
-			\OC_Util::setupFS();
236
-		}
237
-		$result = [];
238
-		$mounts = self::$mounts->findIn($path);
239
-		foreach ($mounts as $mount) {
240
-			$result[] = $mount->getMountPoint();
241
-		}
242
-		return $result;
243
-	}
244
-
245
-	/**
246
-	 * get the storage mounted at $mountPoint
247
-	 *
248
-	 * @param string $mountPoint
249
-	 * @return \OC\Files\Storage\Storage|null
250
-	 */
251
-	public static function getStorage($mountPoint) {
252
-		$mount = self::getMountManager()->find($mountPoint);
253
-		return $mount->getStorage();
254
-	}
255
-
256
-	/**
257
-	 * @param string $id
258
-	 * @return Mount\MountPoint[]
259
-	 */
260
-	public static function getMountByStorageId($id) {
261
-		return self::getMountManager()->findByStorageId($id);
262
-	}
263
-
264
-	/**
265
-	 * @param int $id
266
-	 * @return Mount\MountPoint[]
267
-	 */
268
-	public static function getMountByNumericId($id) {
269
-		return self::getMountManager()->findByNumericId($id);
270
-	}
271
-
272
-	/**
273
-	 * resolve a path to a storage and internal path
274
-	 *
275
-	 * @param string $path
276
-	 * @return array{?\OCP\Files\Storage\IStorage, string} an array consisting of the storage and the internal path
277
-	 */
278
-	public static function resolvePath($path): array {
279
-		$mount = self::getMountManager()->find($path);
280
-		return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')];
281
-	}
282
-
283
-	public static function init(string|IUser|null $user, string $root): bool {
284
-		if (self::$defaultInstance) {
285
-			return false;
286
-		}
287
-		self::initInternal($root);
288
-
289
-		//load custom mount config
290
-		self::initMountPoints($user);
291
-
292
-		return true;
293
-	}
294
-
295
-	public static function initInternal(string $root): bool {
296
-		if (self::$defaultInstance) {
297
-			return false;
298
-		}
299
-		self::getLoader();
300
-		self::$defaultInstance = new View($root);
301
-		/** @var IEventDispatcher $eventDispatcher */
302
-		$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
303
-		$eventDispatcher->addListener(FilesystemTornDownEvent::class, function () {
304
-			self::$defaultInstance = null;
305
-			self::$loaded = false;
306
-		});
307
-
308
-		self::initMountManager();
309
-
310
-		self::$loaded = true;
311
-
312
-		return true;
313
-	}
314
-
315
-	public static function initMountManager(): void {
316
-		if (!self::$mounts) {
317
-			self::$mounts = \OC::$server->get(IMountManager::class);
318
-		}
319
-	}
320
-
321
-	/**
322
-	 * Initialize system and personal mount points for a user
323
-	 *
324
-	 * @throws \OC\User\NoUserException if the user is not available
325
-	 */
326
-	public static function initMountPoints(string|IUser|null $user = ''): void {
327
-		/** @var IUserManager $userManager */
328
-		$userManager = \OC::$server->get(IUserManager::class);
329
-
330
-		$userObject = ($user instanceof IUser) ? $user : $userManager->get($user);
331
-		if ($userObject) {
332
-			/** @var SetupManager $setupManager */
333
-			$setupManager = \OC::$server->get(SetupManager::class);
334
-			$setupManager->setupForUser($userObject);
335
-		} else {
336
-			throw new NoUserException();
337
-		}
338
-	}
339
-
340
-	/**
341
-	 * Get the default filesystem view
342
-	 */
343
-	public static function getView(): ?View {
344
-		if (!self::$defaultInstance) {
345
-			/** @var IUserSession $session */
346
-			$session = \OC::$server->get(IUserSession::class);
347
-			$user = $session->getUser();
348
-			if ($user) {
349
-				$userDir = '/' . $user->getUID() . '/files';
350
-				self::initInternal($userDir);
351
-			}
352
-		}
353
-		return self::$defaultInstance;
354
-	}
355
-
356
-	/**
357
-	 * tear down the filesystem, removing all storage providers
358
-	 */
359
-	public static function tearDown() {
360
-		\OC_Util::tearDownFS();
361
-	}
362
-
363
-	/**
364
-	 * get the relative path of the root data directory for the current user
365
-	 *
366
-	 * @return ?string
367
-	 *
368
-	 * Returns path like /admin/files
369
-	 */
370
-	public static function getRoot() {
371
-		if (!self::$defaultInstance) {
372
-			return null;
373
-		}
374
-		return self::$defaultInstance->getRoot();
375
-	}
376
-
377
-	/**
378
-	 * mount an \OC\Files\Storage\Storage in our virtual filesystem
379
-	 *
380
-	 * @param \OC\Files\Storage\Storage|string $class
381
-	 * @param array $arguments
382
-	 * @param string $mountpoint
383
-	 */
384
-	public static function mount($class, $arguments, $mountpoint) {
385
-		if (!self::$mounts) {
386
-			\OC_Util::setupFS();
387
-		}
388
-		$mount = new Mount\MountPoint($class, $mountpoint, $arguments, self::getLoader());
389
-		self::$mounts->addMount($mount);
390
-	}
391
-
392
-	/**
393
-	 * check if the requested path is valid
394
-	 *
395
-	 * @param string $path
396
-	 * @return bool
397
-	 */
398
-	public static function isValidPath($path) {
399
-		$path = self::normalizePath($path);
400
-		if (!$path || $path[0] !== '/') {
401
-			$path = '/' . $path;
402
-		}
403
-		if (str_contains($path, '/../') || strrchr($path, '/') === '/..') {
404
-			return false;
405
-		}
406
-		return true;
407
-	}
408
-
409
-	/**
410
-	 * @param string $filename
411
-	 * @return bool
412
-	 *
413
-	 * @deprecated 30.0.0 - use \OC\Files\FilenameValidator::isForbidden
414
-	 */
415
-	public static function isFileBlacklisted($filename) {
416
-		if (self::$validator === null) {
417
-			self::$validator = \OCP\Server::get(FilenameValidator::class);
418
-		}
419
-
420
-		$filename = self::normalizePath($filename);
421
-		return self::$validator->isForbidden($filename);
422
-	}
423
-
424
-	/**
425
-	 * check if the directory should be ignored when scanning
426
-	 * NOTE: the special directories . and .. would cause never ending recursion
427
-	 *
428
-	 * @param string $dir
429
-	 * @return boolean
430
-	 */
431
-	public static function isIgnoredDir($dir) {
432
-		if ($dir === '.' || $dir === '..') {
433
-			return true;
434
-		}
435
-		return false;
436
-	}
437
-
438
-	/**
439
-	 * following functions are equivalent to their php builtin equivalents for arguments/return values.
440
-	 */
441
-	public static function mkdir($path) {
442
-		return self::$defaultInstance->mkdir($path);
443
-	}
444
-
445
-	public static function rmdir($path) {
446
-		return self::$defaultInstance->rmdir($path);
447
-	}
448
-
449
-	public static function is_dir($path) {
450
-		return self::$defaultInstance->is_dir($path);
451
-	}
452
-
453
-	public static function is_file($path) {
454
-		return self::$defaultInstance->is_file($path);
455
-	}
456
-
457
-	public static function stat($path) {
458
-		return self::$defaultInstance->stat($path);
459
-	}
460
-
461
-	public static function filetype($path) {
462
-		return self::$defaultInstance->filetype($path);
463
-	}
464
-
465
-	public static function filesize($path) {
466
-		return self::$defaultInstance->filesize($path);
467
-	}
468
-
469
-	public static function readfile($path) {
470
-		return self::$defaultInstance->readfile($path);
471
-	}
472
-
473
-	public static function isCreatable($path) {
474
-		return self::$defaultInstance->isCreatable($path);
475
-	}
476
-
477
-	public static function isReadable($path) {
478
-		return self::$defaultInstance->isReadable($path);
479
-	}
480
-
481
-	public static function isUpdatable($path) {
482
-		return self::$defaultInstance->isUpdatable($path);
483
-	}
484
-
485
-	public static function isDeletable($path) {
486
-		return self::$defaultInstance->isDeletable($path);
487
-	}
488
-
489
-	public static function isSharable($path) {
490
-		return self::$defaultInstance->isSharable($path);
491
-	}
492
-
493
-	public static function file_exists($path) {
494
-		return self::$defaultInstance->file_exists($path);
495
-	}
496
-
497
-	public static function filemtime($path) {
498
-		return self::$defaultInstance->filemtime($path);
499
-	}
500
-
501
-	public static function touch($path, $mtime = null) {
502
-		return self::$defaultInstance->touch($path, $mtime);
503
-	}
504
-
505
-	/**
506
-	 * @return string|false
507
-	 */
508
-	public static function file_get_contents($path) {
509
-		return self::$defaultInstance->file_get_contents($path);
510
-	}
511
-
512
-	public static function file_put_contents($path, $data) {
513
-		return self::$defaultInstance->file_put_contents($path, $data);
514
-	}
515
-
516
-	public static function unlink($path) {
517
-		return self::$defaultInstance->unlink($path);
518
-	}
519
-
520
-	public static function rename($source, $target) {
521
-		return self::$defaultInstance->rename($source, $target);
522
-	}
523
-
524
-	public static function copy($source, $target) {
525
-		return self::$defaultInstance->copy($source, $target);
526
-	}
527
-
528
-	public static function fopen($path, $mode) {
529
-		return self::$defaultInstance->fopen($path, $mode);
530
-	}
531
-
532
-	/**
533
-	 * @param string $path
534
-	 * @throws \OCP\Files\InvalidPathException
535
-	 */
536
-	public static function toTmpFile($path): string|false {
537
-		return self::$defaultInstance->toTmpFile($path);
538
-	}
539
-
540
-	public static function fromTmpFile($tmpFile, $path) {
541
-		return self::$defaultInstance->fromTmpFile($tmpFile, $path);
542
-	}
543
-
544
-	public static function getMimeType($path) {
545
-		return self::$defaultInstance->getMimeType($path);
546
-	}
547
-
548
-	public static function hash($type, $path, $raw = false) {
549
-		return self::$defaultInstance->hash($type, $path, $raw);
550
-	}
551
-
552
-	public static function free_space($path = '/') {
553
-		return self::$defaultInstance->free_space($path);
554
-	}
555
-
556
-	public static function search($query) {
557
-		return self::$defaultInstance->search($query);
558
-	}
559
-
560
-	/**
561
-	 * @param string $query
562
-	 */
563
-	public static function searchByMime($query) {
564
-		return self::$defaultInstance->searchByMime($query);
565
-	}
566
-
567
-	/**
568
-	 * @param string|int $tag name or tag id
569
-	 * @param string $userId owner of the tags
570
-	 * @return FileInfo[] array or file info
571
-	 */
572
-	public static function searchByTag($tag, $userId) {
573
-		return self::$defaultInstance->searchByTag($tag, $userId);
574
-	}
575
-
576
-	/**
577
-	 * check if a file or folder has been updated since $time
578
-	 *
579
-	 * @param string $path
580
-	 * @param int $time
581
-	 * @return bool
582
-	 */
583
-	public static function hasUpdated($path, $time) {
584
-		return self::$defaultInstance->hasUpdated($path, $time);
585
-	}
586
-
587
-	/**
588
-	 * Fix common problems with a file path
589
-	 *
590
-	 * @param string $path
591
-	 * @param bool $stripTrailingSlash whether to strip the trailing slash
592
-	 * @param bool $isAbsolutePath whether the given path is absolute
593
-	 * @param bool $keepUnicode true to disable unicode normalization
594
-	 * @psalm-taint-escape file
595
-	 * @return string
596
-	 */
597
-	public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) {
598
-		/**
599
-		 * FIXME: This is a workaround for existing classes and files which call
600
-		 *        this function with another type than a valid string. This
601
-		 *        conversion should get removed as soon as all existing
602
-		 *        function calls have been fixed.
603
-		 */
604
-		$path = (string)$path;
605
-
606
-		if ($path === '') {
607
-			return '/';
608
-		}
609
-
610
-		if (is_null(self::$normalizedPathCache)) {
611
-			self::$normalizedPathCache = new CappedMemoryCache(2048);
612
-		}
613
-
614
-		$cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath, $keepUnicode]);
615
-
616
-		if ($cacheKey && isset(self::$normalizedPathCache[$cacheKey])) {
617
-			return self::$normalizedPathCache[$cacheKey];
618
-		}
619
-
620
-		//normalize unicode if possible
621
-		if (!$keepUnicode) {
622
-			$path = \OC_Util::normalizeUnicode($path);
623
-		}
624
-
625
-		//add leading slash, if it is already there we strip it anyway
626
-		$path = '/' . $path;
627
-
628
-		$patterns = [
629
-			'#\\\\#s',       // no windows style '\\' slashes
630
-			'#/\.(/\.)*/#s', // remove '/./'
631
-			'#\//+#s',       // remove sequence of slashes
632
-			'#/\.$#s',       // remove trailing '/.'
633
-		];
634
-
635
-		do {
636
-			$count = 0;
637
-			$path = preg_replace($patterns, '/', $path, -1, $count);
638
-		} while ($count > 0);
639
-
640
-		//remove trailing slash
641
-		if ($stripTrailingSlash && strlen($path) > 1) {
642
-			$path = rtrim($path, '/');
643
-		}
644
-
645
-		self::$normalizedPathCache[$cacheKey] = $path;
646
-
647
-		return $path;
648
-	}
649
-
650
-	/**
651
-	 * get the filesystem info
652
-	 *
653
-	 * @param string $path
654
-	 * @param bool|string $includeMountPoints whether to add mountpoint sizes,
655
-	 *                                        defaults to true
656
-	 * @return \OC\Files\FileInfo|false False if file does not exist
657
-	 */
658
-	public static function getFileInfo($path, $includeMountPoints = true) {
659
-		return self::getView()->getFileInfo($path, $includeMountPoints);
660
-	}
661
-
662
-	/**
663
-	 * change file metadata
664
-	 *
665
-	 * @param string $path
666
-	 * @param array $data
667
-	 * @return int
668
-	 *
669
-	 * returns the fileid of the updated file
670
-	 */
671
-	public static function putFileInfo($path, $data) {
672
-		return self::$defaultInstance->putFileInfo($path, $data);
673
-	}
674
-
675
-	/**
676
-	 * get the content of a directory
677
-	 *
678
-	 * @param string $directory path under datadirectory
679
-	 * @param string $mimetype_filter limit returned content to this mimetype or mimepart
680
-	 * @return \OC\Files\FileInfo[]
681
-	 */
682
-	public static function getDirectoryContent($directory, $mimetype_filter = '') {
683
-		return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
684
-	}
685
-
686
-	/**
687
-	 * Get the path of a file by id
688
-	 *
689
-	 * Note that the resulting path is not guaranteed to be unique for the id, multiple paths can point to the same file
690
-	 *
691
-	 * @param int $id
692
-	 * @throws NotFoundException
693
-	 * @return string
694
-	 */
695
-	public static function getPath($id) {
696
-		return self::$defaultInstance->getPath($id);
697
-	}
698
-
699
-	/**
700
-	 * Get the owner for a file or folder
701
-	 *
702
-	 * @param string $path
703
-	 * @return string
704
-	 */
705
-	public static function getOwner($path) {
706
-		return self::$defaultInstance->getOwner($path);
707
-	}
708
-
709
-	/**
710
-	 * get the ETag for a file or folder
711
-	 */
712
-	public static function getETag(string $path): string|false {
713
-		return self::$defaultInstance->getETag($path);
714
-	}
25
+    private static ?Mount\Manager $mounts = null;
26
+
27
+    public static bool $loaded = false;
28
+
29
+    private static ?View $defaultInstance = null;
30
+
31
+    private static ?CappedMemoryCache $normalizedPathCache = null;
32
+
33
+    private static ?FilenameValidator $validator = null;
34
+
35
+    /**
36
+     * classname which used for hooks handling
37
+     * used as signalclass in OC_Hooks::emit()
38
+     */
39
+    public const CLASSNAME = 'OC_Filesystem';
40
+
41
+    /**
42
+     * signalname emitted before file renaming
43
+     *
44
+     * @param string $oldpath
45
+     * @param string $newpath
46
+     */
47
+    public const signal_rename = 'rename';
48
+
49
+    /**
50
+     * signal emitted after file renaming
51
+     *
52
+     * @param string $oldpath
53
+     * @param string $newpath
54
+     */
55
+    public const signal_post_rename = 'post_rename';
56
+
57
+    /**
58
+     * signal emitted before file/dir creation
59
+     *
60
+     * @param string $path
61
+     * @param bool $run changing this flag to false in hook handler will cancel event
62
+     */
63
+    public const signal_create = 'create';
64
+
65
+    /**
66
+     * signal emitted after file/dir creation
67
+     *
68
+     * @param string $path
69
+     * @param bool $run changing this flag to false in hook handler will cancel event
70
+     */
71
+    public const signal_post_create = 'post_create';
72
+
73
+    /**
74
+     * signal emits before file/dir copy
75
+     *
76
+     * @param string $oldpath
77
+     * @param string $newpath
78
+     * @param bool $run changing this flag to false in hook handler will cancel event
79
+     */
80
+    public const signal_copy = 'copy';
81
+
82
+    /**
83
+     * signal emits after file/dir copy
84
+     *
85
+     * @param string $oldpath
86
+     * @param string $newpath
87
+     */
88
+    public const signal_post_copy = 'post_copy';
89
+
90
+    /**
91
+     * signal emits before file/dir save
92
+     *
93
+     * @param string $path
94
+     * @param bool $run changing this flag to false in hook handler will cancel event
95
+     */
96
+    public const signal_write = 'write';
97
+
98
+    /**
99
+     * signal emits after file/dir save
100
+     *
101
+     * @param string $path
102
+     */
103
+    public const signal_post_write = 'post_write';
104
+
105
+    /**
106
+     * signal emitted before file/dir update
107
+     *
108
+     * @param string $path
109
+     * @param bool $run changing this flag to false in hook handler will cancel event
110
+     */
111
+    public const signal_update = 'update';
112
+
113
+    /**
114
+     * signal emitted after file/dir update
115
+     *
116
+     * @param string $path
117
+     * @param bool $run changing this flag to false in hook handler will cancel event
118
+     */
119
+    public const signal_post_update = 'post_update';
120
+
121
+    /**
122
+     * signal emits when reading file/dir
123
+     *
124
+     * @param string $path
125
+     */
126
+    public const signal_read = 'read';
127
+
128
+    /**
129
+     * signal emits when removing file/dir
130
+     *
131
+     * @param string $path
132
+     */
133
+    public const signal_delete = 'delete';
134
+
135
+    /**
136
+     * parameters definitions for signals
137
+     */
138
+    public const signal_param_path = 'path';
139
+    public const signal_param_oldpath = 'oldpath';
140
+    public const signal_param_newpath = 'newpath';
141
+
142
+    /**
143
+     * run - changing this flag to false in hook handler will cancel event
144
+     */
145
+    public const signal_param_run = 'run';
146
+
147
+    public const signal_create_mount = 'create_mount';
148
+    public const signal_delete_mount = 'delete_mount';
149
+    public const signal_param_mount_type = 'mounttype';
150
+    public const signal_param_users = 'users';
151
+
152
+    private static ?\OC\Files\Storage\StorageFactory $loader = null;
153
+
154
+    private static bool $logWarningWhenAddingStorageWrapper = true;
155
+
156
+    /**
157
+     * @param bool $shouldLog
158
+     * @return bool previous value
159
+     * @internal
160
+     */
161
+    public static function logWarningWhenAddingStorageWrapper(bool $shouldLog): bool {
162
+        $previousValue = self::$logWarningWhenAddingStorageWrapper;
163
+        self::$logWarningWhenAddingStorageWrapper = $shouldLog;
164
+        return $previousValue;
165
+    }
166
+
167
+    /**
168
+     * @param string $wrapperName
169
+     * @param callable $wrapper
170
+     * @param int $priority
171
+     */
172
+    public static function addStorageWrapper($wrapperName, $wrapper, $priority = 50) {
173
+        if (self::$logWarningWhenAddingStorageWrapper) {
174
+            \OCP\Server::get(LoggerInterface::class)->warning("Storage wrapper '{wrapper}' was not registered via the 'OC_Filesystem - preSetup' hook which could cause potential problems.", [
175
+                'wrapper' => $wrapperName,
176
+                'app' => 'filesystem',
177
+            ]);
178
+        }
179
+
180
+        $mounts = self::getMountManager()->getAll();
181
+        /** @var StorageFactory $loader */
182
+        $loader = self::getLoader();
183
+        if (!$loader->addStorageWrapper($wrapperName, $wrapper, $priority, $mounts)) {
184
+            // do not re-wrap if storage with this name already existed
185
+            return;
186
+        }
187
+    }
188
+
189
+    /**
190
+     * Returns the storage factory
191
+     *
192
+     * @return IStorageFactory
193
+     */
194
+    public static function getLoader() {
195
+        if (!self::$loader) {
196
+            self::$loader = \OC::$server->get(IStorageFactory::class);
197
+        }
198
+        return self::$loader;
199
+    }
200
+
201
+    /**
202
+     * Returns the mount manager
203
+     */
204
+    public static function getMountManager(): Mount\Manager {
205
+        self::initMountManager();
206
+        assert(self::$mounts !== null);
207
+        return self::$mounts;
208
+    }
209
+
210
+    /**
211
+     * get the mountpoint of the storage object for a path
212
+     * ( note: because a storage is not always mounted inside the fakeroot, the
213
+     * returned mountpoint is relative to the absolute root of the filesystem
214
+     * and doesn't take the chroot into account )
215
+     *
216
+     * @param string $path
217
+     * @return string
218
+     */
219
+    public static function getMountPoint($path) {
220
+        if (!self::$mounts) {
221
+            \OC_Util::setupFS();
222
+        }
223
+        $mount = self::$mounts->find($path);
224
+        return $mount->getMountPoint();
225
+    }
226
+
227
+    /**
228
+     * get a list of all mount points in a directory
229
+     *
230
+     * @param string $path
231
+     * @return string[]
232
+     */
233
+    public static function getMountPoints($path) {
234
+        if (!self::$mounts) {
235
+            \OC_Util::setupFS();
236
+        }
237
+        $result = [];
238
+        $mounts = self::$mounts->findIn($path);
239
+        foreach ($mounts as $mount) {
240
+            $result[] = $mount->getMountPoint();
241
+        }
242
+        return $result;
243
+    }
244
+
245
+    /**
246
+     * get the storage mounted at $mountPoint
247
+     *
248
+     * @param string $mountPoint
249
+     * @return \OC\Files\Storage\Storage|null
250
+     */
251
+    public static function getStorage($mountPoint) {
252
+        $mount = self::getMountManager()->find($mountPoint);
253
+        return $mount->getStorage();
254
+    }
255
+
256
+    /**
257
+     * @param string $id
258
+     * @return Mount\MountPoint[]
259
+     */
260
+    public static function getMountByStorageId($id) {
261
+        return self::getMountManager()->findByStorageId($id);
262
+    }
263
+
264
+    /**
265
+     * @param int $id
266
+     * @return Mount\MountPoint[]
267
+     */
268
+    public static function getMountByNumericId($id) {
269
+        return self::getMountManager()->findByNumericId($id);
270
+    }
271
+
272
+    /**
273
+     * resolve a path to a storage and internal path
274
+     *
275
+     * @param string $path
276
+     * @return array{?\OCP\Files\Storage\IStorage, string} an array consisting of the storage and the internal path
277
+     */
278
+    public static function resolvePath($path): array {
279
+        $mount = self::getMountManager()->find($path);
280
+        return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')];
281
+    }
282
+
283
+    public static function init(string|IUser|null $user, string $root): bool {
284
+        if (self::$defaultInstance) {
285
+            return false;
286
+        }
287
+        self::initInternal($root);
288
+
289
+        //load custom mount config
290
+        self::initMountPoints($user);
291
+
292
+        return true;
293
+    }
294
+
295
+    public static function initInternal(string $root): bool {
296
+        if (self::$defaultInstance) {
297
+            return false;
298
+        }
299
+        self::getLoader();
300
+        self::$defaultInstance = new View($root);
301
+        /** @var IEventDispatcher $eventDispatcher */
302
+        $eventDispatcher = \OC::$server->get(IEventDispatcher::class);
303
+        $eventDispatcher->addListener(FilesystemTornDownEvent::class, function () {
304
+            self::$defaultInstance = null;
305
+            self::$loaded = false;
306
+        });
307
+
308
+        self::initMountManager();
309
+
310
+        self::$loaded = true;
311
+
312
+        return true;
313
+    }
314
+
315
+    public static function initMountManager(): void {
316
+        if (!self::$mounts) {
317
+            self::$mounts = \OC::$server->get(IMountManager::class);
318
+        }
319
+    }
320
+
321
+    /**
322
+     * Initialize system and personal mount points for a user
323
+     *
324
+     * @throws \OC\User\NoUserException if the user is not available
325
+     */
326
+    public static function initMountPoints(string|IUser|null $user = ''): void {
327
+        /** @var IUserManager $userManager */
328
+        $userManager = \OC::$server->get(IUserManager::class);
329
+
330
+        $userObject = ($user instanceof IUser) ? $user : $userManager->get($user);
331
+        if ($userObject) {
332
+            /** @var SetupManager $setupManager */
333
+            $setupManager = \OC::$server->get(SetupManager::class);
334
+            $setupManager->setupForUser($userObject);
335
+        } else {
336
+            throw new NoUserException();
337
+        }
338
+    }
339
+
340
+    /**
341
+     * Get the default filesystem view
342
+     */
343
+    public static function getView(): ?View {
344
+        if (!self::$defaultInstance) {
345
+            /** @var IUserSession $session */
346
+            $session = \OC::$server->get(IUserSession::class);
347
+            $user = $session->getUser();
348
+            if ($user) {
349
+                $userDir = '/' . $user->getUID() . '/files';
350
+                self::initInternal($userDir);
351
+            }
352
+        }
353
+        return self::$defaultInstance;
354
+    }
355
+
356
+    /**
357
+     * tear down the filesystem, removing all storage providers
358
+     */
359
+    public static function tearDown() {
360
+        \OC_Util::tearDownFS();
361
+    }
362
+
363
+    /**
364
+     * get the relative path of the root data directory for the current user
365
+     *
366
+     * @return ?string
367
+     *
368
+     * Returns path like /admin/files
369
+     */
370
+    public static function getRoot() {
371
+        if (!self::$defaultInstance) {
372
+            return null;
373
+        }
374
+        return self::$defaultInstance->getRoot();
375
+    }
376
+
377
+    /**
378
+     * mount an \OC\Files\Storage\Storage in our virtual filesystem
379
+     *
380
+     * @param \OC\Files\Storage\Storage|string $class
381
+     * @param array $arguments
382
+     * @param string $mountpoint
383
+     */
384
+    public static function mount($class, $arguments, $mountpoint) {
385
+        if (!self::$mounts) {
386
+            \OC_Util::setupFS();
387
+        }
388
+        $mount = new Mount\MountPoint($class, $mountpoint, $arguments, self::getLoader());
389
+        self::$mounts->addMount($mount);
390
+    }
391
+
392
+    /**
393
+     * check if the requested path is valid
394
+     *
395
+     * @param string $path
396
+     * @return bool
397
+     */
398
+    public static function isValidPath($path) {
399
+        $path = self::normalizePath($path);
400
+        if (!$path || $path[0] !== '/') {
401
+            $path = '/' . $path;
402
+        }
403
+        if (str_contains($path, '/../') || strrchr($path, '/') === '/..') {
404
+            return false;
405
+        }
406
+        return true;
407
+    }
408
+
409
+    /**
410
+     * @param string $filename
411
+     * @return bool
412
+     *
413
+     * @deprecated 30.0.0 - use \OC\Files\FilenameValidator::isForbidden
414
+     */
415
+    public static function isFileBlacklisted($filename) {
416
+        if (self::$validator === null) {
417
+            self::$validator = \OCP\Server::get(FilenameValidator::class);
418
+        }
419
+
420
+        $filename = self::normalizePath($filename);
421
+        return self::$validator->isForbidden($filename);
422
+    }
423
+
424
+    /**
425
+     * check if the directory should be ignored when scanning
426
+     * NOTE: the special directories . and .. would cause never ending recursion
427
+     *
428
+     * @param string $dir
429
+     * @return boolean
430
+     */
431
+    public static function isIgnoredDir($dir) {
432
+        if ($dir === '.' || $dir === '..') {
433
+            return true;
434
+        }
435
+        return false;
436
+    }
437
+
438
+    /**
439
+     * following functions are equivalent to their php builtin equivalents for arguments/return values.
440
+     */
441
+    public static function mkdir($path) {
442
+        return self::$defaultInstance->mkdir($path);
443
+    }
444
+
445
+    public static function rmdir($path) {
446
+        return self::$defaultInstance->rmdir($path);
447
+    }
448
+
449
+    public static function is_dir($path) {
450
+        return self::$defaultInstance->is_dir($path);
451
+    }
452
+
453
+    public static function is_file($path) {
454
+        return self::$defaultInstance->is_file($path);
455
+    }
456
+
457
+    public static function stat($path) {
458
+        return self::$defaultInstance->stat($path);
459
+    }
460
+
461
+    public static function filetype($path) {
462
+        return self::$defaultInstance->filetype($path);
463
+    }
464
+
465
+    public static function filesize($path) {
466
+        return self::$defaultInstance->filesize($path);
467
+    }
468
+
469
+    public static function readfile($path) {
470
+        return self::$defaultInstance->readfile($path);
471
+    }
472
+
473
+    public static function isCreatable($path) {
474
+        return self::$defaultInstance->isCreatable($path);
475
+    }
476
+
477
+    public static function isReadable($path) {
478
+        return self::$defaultInstance->isReadable($path);
479
+    }
480
+
481
+    public static function isUpdatable($path) {
482
+        return self::$defaultInstance->isUpdatable($path);
483
+    }
484
+
485
+    public static function isDeletable($path) {
486
+        return self::$defaultInstance->isDeletable($path);
487
+    }
488
+
489
+    public static function isSharable($path) {
490
+        return self::$defaultInstance->isSharable($path);
491
+    }
492
+
493
+    public static function file_exists($path) {
494
+        return self::$defaultInstance->file_exists($path);
495
+    }
496
+
497
+    public static function filemtime($path) {
498
+        return self::$defaultInstance->filemtime($path);
499
+    }
500
+
501
+    public static function touch($path, $mtime = null) {
502
+        return self::$defaultInstance->touch($path, $mtime);
503
+    }
504
+
505
+    /**
506
+     * @return string|false
507
+     */
508
+    public static function file_get_contents($path) {
509
+        return self::$defaultInstance->file_get_contents($path);
510
+    }
511
+
512
+    public static function file_put_contents($path, $data) {
513
+        return self::$defaultInstance->file_put_contents($path, $data);
514
+    }
515
+
516
+    public static function unlink($path) {
517
+        return self::$defaultInstance->unlink($path);
518
+    }
519
+
520
+    public static function rename($source, $target) {
521
+        return self::$defaultInstance->rename($source, $target);
522
+    }
523
+
524
+    public static function copy($source, $target) {
525
+        return self::$defaultInstance->copy($source, $target);
526
+    }
527
+
528
+    public static function fopen($path, $mode) {
529
+        return self::$defaultInstance->fopen($path, $mode);
530
+    }
531
+
532
+    /**
533
+     * @param string $path
534
+     * @throws \OCP\Files\InvalidPathException
535
+     */
536
+    public static function toTmpFile($path): string|false {
537
+        return self::$defaultInstance->toTmpFile($path);
538
+    }
539
+
540
+    public static function fromTmpFile($tmpFile, $path) {
541
+        return self::$defaultInstance->fromTmpFile($tmpFile, $path);
542
+    }
543
+
544
+    public static function getMimeType($path) {
545
+        return self::$defaultInstance->getMimeType($path);
546
+    }
547
+
548
+    public static function hash($type, $path, $raw = false) {
549
+        return self::$defaultInstance->hash($type, $path, $raw);
550
+    }
551
+
552
+    public static function free_space($path = '/') {
553
+        return self::$defaultInstance->free_space($path);
554
+    }
555
+
556
+    public static function search($query) {
557
+        return self::$defaultInstance->search($query);
558
+    }
559
+
560
+    /**
561
+     * @param string $query
562
+     */
563
+    public static function searchByMime($query) {
564
+        return self::$defaultInstance->searchByMime($query);
565
+    }
566
+
567
+    /**
568
+     * @param string|int $tag name or tag id
569
+     * @param string $userId owner of the tags
570
+     * @return FileInfo[] array or file info
571
+     */
572
+    public static function searchByTag($tag, $userId) {
573
+        return self::$defaultInstance->searchByTag($tag, $userId);
574
+    }
575
+
576
+    /**
577
+     * check if a file or folder has been updated since $time
578
+     *
579
+     * @param string $path
580
+     * @param int $time
581
+     * @return bool
582
+     */
583
+    public static function hasUpdated($path, $time) {
584
+        return self::$defaultInstance->hasUpdated($path, $time);
585
+    }
586
+
587
+    /**
588
+     * Fix common problems with a file path
589
+     *
590
+     * @param string $path
591
+     * @param bool $stripTrailingSlash whether to strip the trailing slash
592
+     * @param bool $isAbsolutePath whether the given path is absolute
593
+     * @param bool $keepUnicode true to disable unicode normalization
594
+     * @psalm-taint-escape file
595
+     * @return string
596
+     */
597
+    public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false, $keepUnicode = false) {
598
+        /**
599
+         * FIXME: This is a workaround for existing classes and files which call
600
+         *        this function with another type than a valid string. This
601
+         *        conversion should get removed as soon as all existing
602
+         *        function calls have been fixed.
603
+         */
604
+        $path = (string)$path;
605
+
606
+        if ($path === '') {
607
+            return '/';
608
+        }
609
+
610
+        if (is_null(self::$normalizedPathCache)) {
611
+            self::$normalizedPathCache = new CappedMemoryCache(2048);
612
+        }
613
+
614
+        $cacheKey = json_encode([$path, $stripTrailingSlash, $isAbsolutePath, $keepUnicode]);
615
+
616
+        if ($cacheKey && isset(self::$normalizedPathCache[$cacheKey])) {
617
+            return self::$normalizedPathCache[$cacheKey];
618
+        }
619
+
620
+        //normalize unicode if possible
621
+        if (!$keepUnicode) {
622
+            $path = \OC_Util::normalizeUnicode($path);
623
+        }
624
+
625
+        //add leading slash, if it is already there we strip it anyway
626
+        $path = '/' . $path;
627
+
628
+        $patterns = [
629
+            '#\\\\#s',       // no windows style '\\' slashes
630
+            '#/\.(/\.)*/#s', // remove '/./'
631
+            '#\//+#s',       // remove sequence of slashes
632
+            '#/\.$#s',       // remove trailing '/.'
633
+        ];
634
+
635
+        do {
636
+            $count = 0;
637
+            $path = preg_replace($patterns, '/', $path, -1, $count);
638
+        } while ($count > 0);
639
+
640
+        //remove trailing slash
641
+        if ($stripTrailingSlash && strlen($path) > 1) {
642
+            $path = rtrim($path, '/');
643
+        }
644
+
645
+        self::$normalizedPathCache[$cacheKey] = $path;
646
+
647
+        return $path;
648
+    }
649
+
650
+    /**
651
+     * get the filesystem info
652
+     *
653
+     * @param string $path
654
+     * @param bool|string $includeMountPoints whether to add mountpoint sizes,
655
+     *                                        defaults to true
656
+     * @return \OC\Files\FileInfo|false False if file does not exist
657
+     */
658
+    public static function getFileInfo($path, $includeMountPoints = true) {
659
+        return self::getView()->getFileInfo($path, $includeMountPoints);
660
+    }
661
+
662
+    /**
663
+     * change file metadata
664
+     *
665
+     * @param string $path
666
+     * @param array $data
667
+     * @return int
668
+     *
669
+     * returns the fileid of the updated file
670
+     */
671
+    public static function putFileInfo($path, $data) {
672
+        return self::$defaultInstance->putFileInfo($path, $data);
673
+    }
674
+
675
+    /**
676
+     * get the content of a directory
677
+     *
678
+     * @param string $directory path under datadirectory
679
+     * @param string $mimetype_filter limit returned content to this mimetype or mimepart
680
+     * @return \OC\Files\FileInfo[]
681
+     */
682
+    public static function getDirectoryContent($directory, $mimetype_filter = '') {
683
+        return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
684
+    }
685
+
686
+    /**
687
+     * Get the path of a file by id
688
+     *
689
+     * Note that the resulting path is not guaranteed to be unique for the id, multiple paths can point to the same file
690
+     *
691
+     * @param int $id
692
+     * @throws NotFoundException
693
+     * @return string
694
+     */
695
+    public static function getPath($id) {
696
+        return self::$defaultInstance->getPath($id);
697
+    }
698
+
699
+    /**
700
+     * Get the owner for a file or folder
701
+     *
702
+     * @param string $path
703
+     * @return string
704
+     */
705
+    public static function getOwner($path) {
706
+        return self::$defaultInstance->getOwner($path);
707
+    }
708
+
709
+    /**
710
+     * get the ETag for a file or folder
711
+     */
712
+    public static function getETag(string $path): string|false {
713
+        return self::$defaultInstance->getETag($path);
714
+    }
715 715
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 use Psr\Log\LoggerInterface;
23 23
 
24 24
 class Filesystem {
25
-	private static ?Mount\Manager $mounts = null;
25
+	private static ? Mount\Manager $mounts = null;
26 26
 
27 27
 	public static bool $loaded = false;
28 28
 
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	public const signal_param_mount_type = 'mounttype';
150 150
 	public const signal_param_users = 'users';
151 151
 
152
-	private static ?\OC\Files\Storage\StorageFactory $loader = null;
152
+	private static ? \OC\Files\Storage\StorageFactory $loader = null;
153 153
 
154 154
 	private static bool $logWarningWhenAddingStorageWrapper = true;
155 155
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 		return [$mount->getStorage(), rtrim($mount->getInternalPath($path), '/')];
281 281
 	}
282 282
 
283
-	public static function init(string|IUser|null $user, string $root): bool {
283
+	public static function init(string | IUser | null $user, string $root): bool {
284 284
 		if (self::$defaultInstance) {
285 285
 			return false;
286 286
 		}
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 		self::$defaultInstance = new View($root);
301 301
 		/** @var IEventDispatcher $eventDispatcher */
302 302
 		$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
303
-		$eventDispatcher->addListener(FilesystemTornDownEvent::class, function () {
303
+		$eventDispatcher->addListener(FilesystemTornDownEvent::class, function() {
304 304
 			self::$defaultInstance = null;
305 305
 			self::$loaded = false;
306 306
 		});
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 	 *
324 324
 	 * @throws \OC\User\NoUserException if the user is not available
325 325
 	 */
326
-	public static function initMountPoints(string|IUser|null $user = ''): void {
326
+	public static function initMountPoints(string | IUser | null $user = ''): void {
327 327
 		/** @var IUserManager $userManager */
328 328
 		$userManager = \OC::$server->get(IUserManager::class);
329 329
 
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 			$session = \OC::$server->get(IUserSession::class);
347 347
 			$user = $session->getUser();
348 348
 			if ($user) {
349
-				$userDir = '/' . $user->getUID() . '/files';
349
+				$userDir = '/'.$user->getUID().'/files';
350 350
 				self::initInternal($userDir);
351 351
 			}
352 352
 		}
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	public static function isValidPath($path) {
399 399
 		$path = self::normalizePath($path);
400 400
 		if (!$path || $path[0] !== '/') {
401
-			$path = '/' . $path;
401
+			$path = '/'.$path;
402 402
 		}
403 403
 		if (str_contains($path, '/../') || strrchr($path, '/') === '/..') {
404 404
 			return false;
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 	 * @param string $path
534 534
 	 * @throws \OCP\Files\InvalidPathException
535 535
 	 */
536
-	public static function toTmpFile($path): string|false {
536
+	public static function toTmpFile($path): string | false {
537 537
 		return self::$defaultInstance->toTmpFile($path);
538 538
 	}
539 539
 
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 		 *        conversion should get removed as soon as all existing
602 602
 		 *        function calls have been fixed.
603 603
 		 */
604
-		$path = (string)$path;
604
+		$path = (string) $path;
605 605
 
606 606
 		if ($path === '') {
607 607
 			return '/';
@@ -623,13 +623,13 @@  discard block
 block discarded – undo
623 623
 		}
624 624
 
625 625
 		//add leading slash, if it is already there we strip it anyway
626
-		$path = '/' . $path;
626
+		$path = '/'.$path;
627 627
 
628 628
 		$patterns = [
629
-			'#\\\\#s',       // no windows style '\\' slashes
629
+			'#\\\\#s', // no windows style '\\' slashes
630 630
 			'#/\.(/\.)*/#s', // remove '/./'
631
-			'#\//+#s',       // remove sequence of slashes
632
-			'#/\.$#s',       // remove trailing '/.'
631
+			'#\//+#s', // remove sequence of slashes
632
+			'#/\.$#s', // remove trailing '/.'
633 633
 		];
634 634
 
635 635
 		do {
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	/**
710 710
 	 * get the ETag for a file or folder
711 711
 	 */
712
-	public static function getETag(string $path): string|false {
712
+	public static function getETag(string $path): string | false {
713 713
 		return self::$defaultInstance->getETag($path);
714 714
 	}
715 715
 }
Please login to merge, or discard this patch.