Passed
Push — master ( 6f31d2...35b910 )
by Julius
34:16 queued 19:13
created
apps/files/lib/Controller/ApiController.php 2 patches
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -61,316 +61,316 @@
 block discarded – undo
61 61
  * @package OCA\Files\Controller
62 62
  */
63 63
 class ApiController extends Controller {
64
-	/** @var TagService */
65
-	private $tagService;
66
-	/** @var IManager * */
67
-	private $shareManager;
68
-	/** @var IPreview */
69
-	private $previewManager;
70
-	/** IUserSession */
71
-	private $userSession;
72
-	/** IConfig */
73
-	private $config;
74
-	/** @var Folder */
75
-	private $userFolder;
64
+    /** @var TagService */
65
+    private $tagService;
66
+    /** @var IManager * */
67
+    private $shareManager;
68
+    /** @var IPreview */
69
+    private $previewManager;
70
+    /** IUserSession */
71
+    private $userSession;
72
+    /** IConfig */
73
+    private $config;
74
+    /** @var Folder */
75
+    private $userFolder;
76 76
 
77
-	/**
78
-	 * @param string $appName
79
-	 * @param IRequest $request
80
-	 * @param IUserSession $userSession
81
-	 * @param TagService $tagService
82
-	 * @param IPreview $previewManager
83
-	 * @param IManager $shareManager
84
-	 * @param IConfig $config
85
-	 * @param Folder $userFolder
86
-	 */
87
-	public function __construct($appName,
88
-								IRequest $request,
89
-								IUserSession $userSession,
90
-								TagService $tagService,
91
-								IPreview $previewManager,
92
-								IManager $shareManager,
93
-								IConfig $config,
94
-								Folder $userFolder) {
95
-		parent::__construct($appName, $request);
96
-		$this->userSession = $userSession;
97
-		$this->tagService = $tagService;
98
-		$this->previewManager = $previewManager;
99
-		$this->shareManager = $shareManager;
100
-		$this->config = $config;
101
-		$this->userFolder = $userFolder;
102
-	}
77
+    /**
78
+     * @param string $appName
79
+     * @param IRequest $request
80
+     * @param IUserSession $userSession
81
+     * @param TagService $tagService
82
+     * @param IPreview $previewManager
83
+     * @param IManager $shareManager
84
+     * @param IConfig $config
85
+     * @param Folder $userFolder
86
+     */
87
+    public function __construct($appName,
88
+                                IRequest $request,
89
+                                IUserSession $userSession,
90
+                                TagService $tagService,
91
+                                IPreview $previewManager,
92
+                                IManager $shareManager,
93
+                                IConfig $config,
94
+                                Folder $userFolder) {
95
+        parent::__construct($appName, $request);
96
+        $this->userSession = $userSession;
97
+        $this->tagService = $tagService;
98
+        $this->previewManager = $previewManager;
99
+        $this->shareManager = $shareManager;
100
+        $this->config = $config;
101
+        $this->userFolder = $userFolder;
102
+    }
103 103
 
104
-	/**
105
-	 * Gets a thumbnail of the specified file
106
-	 *
107
-	 * @since API version 1.0
108
-	 *
109
-	 * @NoAdminRequired
110
-	 * @NoCSRFRequired
111
-	 * @StrictCookieRequired
112
-	 *
113
-	 * @param int $x
114
-	 * @param int $y
115
-	 * @param string $file URL-encoded filename
116
-	 * @return DataResponse|FileDisplayResponse
117
-	 */
118
-	public function getThumbnail($x, $y, $file) {
119
-		if ($x < 1 || $y < 1) {
120
-			return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
121
-		}
104
+    /**
105
+     * Gets a thumbnail of the specified file
106
+     *
107
+     * @since API version 1.0
108
+     *
109
+     * @NoAdminRequired
110
+     * @NoCSRFRequired
111
+     * @StrictCookieRequired
112
+     *
113
+     * @param int $x
114
+     * @param int $y
115
+     * @param string $file URL-encoded filename
116
+     * @return DataResponse|FileDisplayResponse
117
+     */
118
+    public function getThumbnail($x, $y, $file) {
119
+        if ($x < 1 || $y < 1) {
120
+            return new DataResponse(['message' => 'Requested size must be numeric and a positive value.'], Http::STATUS_BAD_REQUEST);
121
+        }
122 122
 
123
-		try {
124
-			$file = $this->userFolder->get($file);
125
-			if ($file instanceof Folder) {
126
-				throw new NotFoundException();
127
-			}
123
+        try {
124
+            $file = $this->userFolder->get($file);
125
+            if ($file instanceof Folder) {
126
+                throw new NotFoundException();
127
+            }
128 128
 
129
-			/** @var File $file */
130
-			$preview = $this->previewManager->getPreview($file, $x, $y, true);
129
+            /** @var File $file */
130
+            $preview = $this->previewManager->getPreview($file, $x, $y, true);
131 131
 
132
-			return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
133
-		} catch (NotFoundException $e) {
134
-			return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
135
-		} catch (\Exception $e) {
136
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
137
-		}
138
-	}
132
+            return new FileDisplayResponse($preview, Http::STATUS_OK, ['Content-Type' => $preview->getMimeType()]);
133
+        } catch (NotFoundException $e) {
134
+            return new DataResponse(['message' => 'File not found.'], Http::STATUS_NOT_FOUND);
135
+        } catch (\Exception $e) {
136
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
137
+        }
138
+    }
139 139
 
140
-	/**
141
-	 * Updates the info of the specified file path
142
-	 * The passed tags are absolute, which means they will
143
-	 * replace the actual tag selection.
144
-	 *
145
-	 * @NoAdminRequired
146
-	 *
147
-	 * @param string $path path
148
-	 * @param array|string $tags array of tags
149
-	 * @return DataResponse
150
-	 */
151
-	public function updateFileTags($path, $tags = null) {
152
-		$result = [];
153
-		// if tags specified or empty array, update tags
154
-		if (!is_null($tags)) {
155
-			try {
156
-				$this->tagService->updateFileTags($path, $tags);
157
-			} catch (\OCP\Files\NotFoundException $e) {
158
-				return new DataResponse([
159
-					'message' => $e->getMessage()
160
-				], Http::STATUS_NOT_FOUND);
161
-			} catch (\OCP\Files\StorageNotAvailableException $e) {
162
-				return new DataResponse([
163
-					'message' => $e->getMessage()
164
-				], Http::STATUS_SERVICE_UNAVAILABLE);
165
-			} catch (\Exception $e) {
166
-				return new DataResponse([
167
-					'message' => $e->getMessage()
168
-				], Http::STATUS_NOT_FOUND);
169
-			}
170
-			$result['tags'] = $tags;
171
-		}
172
-		return new DataResponse($result);
173
-	}
140
+    /**
141
+     * Updates the info of the specified file path
142
+     * The passed tags are absolute, which means they will
143
+     * replace the actual tag selection.
144
+     *
145
+     * @NoAdminRequired
146
+     *
147
+     * @param string $path path
148
+     * @param array|string $tags array of tags
149
+     * @return DataResponse
150
+     */
151
+    public function updateFileTags($path, $tags = null) {
152
+        $result = [];
153
+        // if tags specified or empty array, update tags
154
+        if (!is_null($tags)) {
155
+            try {
156
+                $this->tagService->updateFileTags($path, $tags);
157
+            } catch (\OCP\Files\NotFoundException $e) {
158
+                return new DataResponse([
159
+                    'message' => $e->getMessage()
160
+                ], Http::STATUS_NOT_FOUND);
161
+            } catch (\OCP\Files\StorageNotAvailableException $e) {
162
+                return new DataResponse([
163
+                    'message' => $e->getMessage()
164
+                ], Http::STATUS_SERVICE_UNAVAILABLE);
165
+            } catch (\Exception $e) {
166
+                return new DataResponse([
167
+                    'message' => $e->getMessage()
168
+                ], Http::STATUS_NOT_FOUND);
169
+            }
170
+            $result['tags'] = $tags;
171
+        }
172
+        return new DataResponse($result);
173
+    }
174 174
 
175
-	/**
176
-	 * @param \OCP\Files\Node[] $nodes
177
-	 * @return array
178
-	 */
179
-	private function formatNodes(array $nodes) {
180
-		$shareTypesForNodes = $this->getShareTypesForNodes($nodes);
181
-		return array_values(array_map(function (Node $node) use ($shareTypesForNodes) {
182
-			$shareTypes = $shareTypesForNodes[$node->getId()] ?? [];
183
-			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
184
-			$file['hasPreview'] = $this->previewManager->isAvailable($node);
185
-			$parts = explode('/', dirname($node->getPath()), 4);
186
-			if (isset($parts[3])) {
187
-				$file['path'] = '/' . $parts[3];
188
-			} else {
189
-				$file['path'] = '/';
190
-			}
191
-			if (!empty($shareTypes)) {
192
-				$file['shareTypes'] = $shareTypes;
193
-			}
194
-			return $file;
195
-		}, $nodes));
196
-	}
175
+    /**
176
+     * @param \OCP\Files\Node[] $nodes
177
+     * @return array
178
+     */
179
+    private function formatNodes(array $nodes) {
180
+        $shareTypesForNodes = $this->getShareTypesForNodes($nodes);
181
+        return array_values(array_map(function (Node $node) use ($shareTypesForNodes) {
182
+            $shareTypes = $shareTypesForNodes[$node->getId()] ?? [];
183
+            $file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
184
+            $file['hasPreview'] = $this->previewManager->isAvailable($node);
185
+            $parts = explode('/', dirname($node->getPath()), 4);
186
+            if (isset($parts[3])) {
187
+                $file['path'] = '/' . $parts[3];
188
+            } else {
189
+                $file['path'] = '/';
190
+            }
191
+            if (!empty($shareTypes)) {
192
+                $file['shareTypes'] = $shareTypes;
193
+            }
194
+            return $file;
195
+        }, $nodes));
196
+    }
197 197
 
198
-	/**
199
-	 * Get the share types for each node
200
-	 *
201
-	 * @param \OCP\Files\Node[] $nodes
202
-	 * @return array<int, int[]> list of share types for each fileid
203
-	 */
204
-	private function getShareTypesForNodes(array $nodes): array {
205
-		$userId = $this->userSession->getUser()->getUID();
206
-		$requestedShareTypes = [
207
-			IShare::TYPE_USER,
208
-			IShare::TYPE_GROUP,
209
-			IShare::TYPE_LINK,
210
-			IShare::TYPE_REMOTE,
211
-			IShare::TYPE_EMAIL,
212
-			IShare::TYPE_ROOM,
213
-			IShare::TYPE_DECK,
214
-		];
215
-		$shareTypes = [];
198
+    /**
199
+     * Get the share types for each node
200
+     *
201
+     * @param \OCP\Files\Node[] $nodes
202
+     * @return array<int, int[]> list of share types for each fileid
203
+     */
204
+    private function getShareTypesForNodes(array $nodes): array {
205
+        $userId = $this->userSession->getUser()->getUID();
206
+        $requestedShareTypes = [
207
+            IShare::TYPE_USER,
208
+            IShare::TYPE_GROUP,
209
+            IShare::TYPE_LINK,
210
+            IShare::TYPE_REMOTE,
211
+            IShare::TYPE_EMAIL,
212
+            IShare::TYPE_ROOM,
213
+            IShare::TYPE_DECK,
214
+        ];
215
+        $shareTypes = [];
216 216
 
217
-		$nodeIds = array_map(function (Node $node) {
218
-			return $node->getId();
219
-		}, $nodes);
217
+        $nodeIds = array_map(function (Node $node) {
218
+            return $node->getId();
219
+        }, $nodes);
220 220
 
221
-		foreach ($requestedShareTypes as $shareType) {
222
-			$nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true));
223
-			$offset = 0;
221
+        foreach ($requestedShareTypes as $shareType) {
222
+            $nodesLeft = array_combine($nodeIds, array_fill(0, count($nodeIds), true));
223
+            $offset = 0;
224 224
 
225
-			// fetch shares until we've either found shares for all nodes or there are no more shares left
226
-			while (count($nodesLeft) > 0) {
227
-				$shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset);
228
-				foreach ($shares as $share) {
229
-					$fileId = $share->getNodeId();
230
-					if (isset($nodesLeft[$fileId])) {
231
-						if (!isset($shareTypes[$fileId])) {
232
-							$shareTypes[$fileId] = [];
233
-						}
234
-						$shareTypes[$fileId][] = $shareType;
235
-						unset($nodesLeft[$fileId]);
236
-					}
237
-				}
225
+            // fetch shares until we've either found shares for all nodes or there are no more shares left
226
+            while (count($nodesLeft) > 0) {
227
+                $shares = $this->shareManager->getSharesBy($userId, $shareType, null, false, 100, $offset);
228
+                foreach ($shares as $share) {
229
+                    $fileId = $share->getNodeId();
230
+                    if (isset($nodesLeft[$fileId])) {
231
+                        if (!isset($shareTypes[$fileId])) {
232
+                            $shareTypes[$fileId] = [];
233
+                        }
234
+                        $shareTypes[$fileId][] = $shareType;
235
+                        unset($nodesLeft[$fileId]);
236
+                    }
237
+                }
238 238
 
239
-				if (count($shares) < 100) {
240
-					break;
241
-				} else {
242
-					$offset += count($shares);
243
-				}
244
-			}
245
-		}
246
-		return $shareTypes;
247
-	}
239
+                if (count($shares) < 100) {
240
+                    break;
241
+                } else {
242
+                    $offset += count($shares);
243
+                }
244
+            }
245
+        }
246
+        return $shareTypes;
247
+    }
248 248
 
249
-	/**
250
-	 * Returns a list of recently modifed files.
251
-	 *
252
-	 * @NoAdminRequired
253
-	 *
254
-	 * @return DataResponse
255
-	 */
256
-	public function getRecentFiles() {
257
-		$nodes = $this->userFolder->getRecent(100);
258
-		$files = $this->formatNodes($nodes);
259
-		return new DataResponse(['files' => $files]);
260
-	}
249
+    /**
250
+     * Returns a list of recently modifed files.
251
+     *
252
+     * @NoAdminRequired
253
+     *
254
+     * @return DataResponse
255
+     */
256
+    public function getRecentFiles() {
257
+        $nodes = $this->userFolder->getRecent(100);
258
+        $files = $this->formatNodes($nodes);
259
+        return new DataResponse(['files' => $files]);
260
+    }
261 261
 
262
-	/**
263
-	 * Change the default sort mode
264
-	 *
265
-	 * @NoAdminRequired
266
-	 *
267
-	 * @param string $mode
268
-	 * @param string $direction
269
-	 * @return Response
270
-	 * @throws \OCP\PreConditionNotMetException
271
-	 */
272
-	public function updateFileSorting($mode, $direction) {
273
-		$allowedMode = ['name', 'size', 'mtime'];
274
-		$allowedDirection = ['asc', 'desc'];
275
-		if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
276
-			$response = new Response();
277
-			$response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
278
-			return $response;
279
-		}
280
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
281
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
282
-		return new Response();
283
-	}
262
+    /**
263
+     * Change the default sort mode
264
+     *
265
+     * @NoAdminRequired
266
+     *
267
+     * @param string $mode
268
+     * @param string $direction
269
+     * @return Response
270
+     * @throws \OCP\PreConditionNotMetException
271
+     */
272
+    public function updateFileSorting($mode, $direction) {
273
+        $allowedMode = ['name', 'size', 'mtime'];
274
+        $allowedDirection = ['asc', 'desc'];
275
+        if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
276
+            $response = new Response();
277
+            $response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
278
+            return $response;
279
+        }
280
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
281
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
282
+        return new Response();
283
+    }
284 284
 
285
-	/**
286
-	 * Toggle default for showing/hiding hidden files
287
-	 *
288
-	 * @NoAdminRequired
289
-	 *
290
-	 * @param bool $show
291
-	 * @return Response
292
-	 * @throws \OCP\PreConditionNotMetException
293
-	 */
294
-	public function showHiddenFiles($show) {
295
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
296
-		return new Response();
297
-	}
285
+    /**
286
+     * Toggle default for showing/hiding hidden files
287
+     *
288
+     * @NoAdminRequired
289
+     *
290
+     * @param bool $show
291
+     * @return Response
292
+     * @throws \OCP\PreConditionNotMetException
293
+     */
294
+    public function showHiddenFiles($show) {
295
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
296
+        return new Response();
297
+    }
298 298
 
299
-	/**
300
-	 * Toggle default for cropping preview images
301
-	 *
302
-	 * @NoAdminRequired
303
-	 *
304
-	 * @param bool $crop
305
-	 * @return Response
306
-	 * @throws \OCP\PreConditionNotMetException
307
-	 */
308
-	public function cropImagePreviews($crop) {
309
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', (int)$crop);
310
-		return new Response();
311
-	}
299
+    /**
300
+     * Toggle default for cropping preview images
301
+     *
302
+     * @NoAdminRequired
303
+     *
304
+     * @param bool $crop
305
+     * @return Response
306
+     * @throws \OCP\PreConditionNotMetException
307
+     */
308
+    public function cropImagePreviews($crop) {
309
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', (int)$crop);
310
+        return new Response();
311
+    }
312 312
 
313
-	/**
314
-	 * Toggle default for files grid view
315
-	 *
316
-	 * @NoAdminRequired
317
-	 *
318
-	 * @param bool $show
319
-	 * @return Response
320
-	 * @throws \OCP\PreConditionNotMetException
321
-	 */
322
-	public function showGridView($show) {
323
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
324
-		return new Response();
325
-	}
313
+    /**
314
+     * Toggle default for files grid view
315
+     *
316
+     * @NoAdminRequired
317
+     *
318
+     * @param bool $show
319
+     * @return Response
320
+     * @throws \OCP\PreConditionNotMetException
321
+     */
322
+    public function showGridView($show) {
323
+        $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
324
+        return new Response();
325
+    }
326 326
 
327
-	/**
328
-	 * Get default settings for the grid view
329
-	 *
330
-	 * @NoAdminRequired
331
-	 */
332
-	public function getGridView() {
333
-		$status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1';
334
-		return new JSONResponse(['gridview' => $status]);
335
-	}
327
+    /**
328
+     * Get default settings for the grid view
329
+     *
330
+     * @NoAdminRequired
331
+     */
332
+    public function getGridView() {
333
+        $status = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', '0') === '1';
334
+        return new JSONResponse(['gridview' => $status]);
335
+    }
336 336
 
337
-	/**
338
-	 * Toggle default for showing/hiding xxx folder
339
-	 *
340
-	 * @NoAdminRequired
341
-	 *
342
-	 * @param int $show
343
-	 * @param string $key the key of the folder
344
-	 *
345
-	 * @return Response
346
-	 * @throws \OCP\PreConditionNotMetException
347
-	 */
348
-	public function toggleShowFolder(int $show, string $key) {
349
-		// ensure the edited key exists
350
-		$navItems = \OCA\Files\App::getNavigationManager()->getAll();
351
-		foreach ($navItems as $item) {
352
-			// check if data is valid
353
-			if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
354
-				$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, $show);
355
-				return new Response();
356
-			}
357
-		}
358
-		$response = new Response();
359
-		$response->setStatus(Http::STATUS_FORBIDDEN);
360
-		return $response;
361
-	}
337
+    /**
338
+     * Toggle default for showing/hiding xxx folder
339
+     *
340
+     * @NoAdminRequired
341
+     *
342
+     * @param int $show
343
+     * @param string $key the key of the folder
344
+     *
345
+     * @return Response
346
+     * @throws \OCP\PreConditionNotMetException
347
+     */
348
+    public function toggleShowFolder(int $show, string $key) {
349
+        // ensure the edited key exists
350
+        $navItems = \OCA\Files\App::getNavigationManager()->getAll();
351
+        foreach ($navItems as $item) {
352
+            // check if data is valid
353
+            if (($show === 0 || $show === 1) && isset($item['expandedState']) && $key === $item['expandedState']) {
354
+                $this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', $key, $show);
355
+                return new Response();
356
+            }
357
+        }
358
+        $response = new Response();
359
+        $response->setStatus(Http::STATUS_FORBIDDEN);
360
+        return $response;
361
+    }
362 362
 
363
-	/**
364
-	 * Get sorting-order for custom sorting
365
-	 *
366
-	 * @NoAdminRequired
367
-	 *
368
-	 * @param string $folderpath
369
-	 * @return string
370
-	 * @throws \OCP\Files\NotFoundException
371
-	 */
372
-	public function getNodeType($folderpath) {
373
-		$node = $this->userFolder->get($folderpath);
374
-		return $node->getType();
375
-	}
363
+    /**
364
+     * Get sorting-order for custom sorting
365
+     *
366
+     * @NoAdminRequired
367
+     *
368
+     * @param string $folderpath
369
+     * @return string
370
+     * @throws \OCP\Files\NotFoundException
371
+     */
372
+    public function getNodeType($folderpath) {
373
+        $node = $this->userFolder->get($folderpath);
374
+        return $node->getType();
375
+    }
376 376
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -178,13 +178,13 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	private function formatNodes(array $nodes) {
180 180
 		$shareTypesForNodes = $this->getShareTypesForNodes($nodes);
181
-		return array_values(array_map(function (Node $node) use ($shareTypesForNodes) {
181
+		return array_values(array_map(function(Node $node) use ($shareTypesForNodes) {
182 182
 			$shareTypes = $shareTypesForNodes[$node->getId()] ?? [];
183 183
 			$file = \OCA\Files\Helper::formatFileInfo($node->getFileInfo());
184 184
 			$file['hasPreview'] = $this->previewManager->isAvailable($node);
185 185
 			$parts = explode('/', dirname($node->getPath()), 4);
186 186
 			if (isset($parts[3])) {
187
-				$file['path'] = '/' . $parts[3];
187
+				$file['path'] = '/'.$parts[3];
188 188
 			} else {
189 189
 				$file['path'] = '/';
190 190
 			}
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 		];
215 215
 		$shareTypes = [];
216 216
 
217
-		$nodeIds = array_map(function (Node $node) {
217
+		$nodeIds = array_map(function(Node $node) {
218 218
 			return $node->getId();
219 219
 		}, $nodes);
220 220
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @throws \OCP\PreConditionNotMetException
293 293
 	 */
294 294
 	public function showHiddenFiles($show) {
295
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int)$show);
295
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', (int) $show);
296 296
 		return new Response();
297 297
 	}
298 298
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 	 * @throws \OCP\PreConditionNotMetException
307 307
 	 */
308 308
 	public function cropImagePreviews($crop) {
309
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', (int)$crop);
309
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'crop_image_previews', (int) $crop);
310 310
 		return new Response();
311 311
 	}
312 312
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	 * @throws \OCP\PreConditionNotMetException
321 321
 	 */
322 322
 	public function showGridView($show) {
323
-		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int)$show);
323
+		$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'show_grid', (int) $show);
324 324
 		return new Response();
325 325
 	}
326 326
 
Please login to merge, or discard this patch.
lib/private/Files/Node/Folder.php 2 patches
Indentation   +472 added lines, -472 removed lines patch added patch discarded remove patch
@@ -49,476 +49,476 @@
 block discarded – undo
49 49
 use OCP\IUserManager;
50 50
 
51 51
 class Folder extends Node implements \OCP\Files\Folder {
52
-	/**
53
-	 * Creates a Folder that represents a non-existing path
54
-	 *
55
-	 * @param string $path path
56
-	 * @return string non-existing node class
57
-	 */
58
-	protected function createNonExistingNode($path) {
59
-		return new NonExistingFolder($this->root, $this->view, $path);
60
-	}
61
-
62
-	/**
63
-	 * @param string $path path relative to the folder
64
-	 * @return string
65
-	 * @throws \OCP\Files\NotPermittedException
66
-	 */
67
-	public function getFullPath($path) {
68
-		if (!$this->isValidPath($path)) {
69
-			throw new NotPermittedException('Invalid path');
70
-		}
71
-		return $this->path . $this->normalizePath($path);
72
-	}
73
-
74
-	/**
75
-	 * @param string $path
76
-	 * @return string|null
77
-	 */
78
-	public function getRelativePath($path) {
79
-		if ($this->path === '' or $this->path === '/') {
80
-			return $this->normalizePath($path);
81
-		}
82
-		if ($path === $this->path) {
83
-			return '/';
84
-		} elseif (strpos($path, $this->path . '/') !== 0) {
85
-			return null;
86
-		} else {
87
-			$path = substr($path, strlen($this->path));
88
-			return $this->normalizePath($path);
89
-		}
90
-	}
91
-
92
-	/**
93
-	 * check if a node is a (grand-)child of the folder
94
-	 *
95
-	 * @param \OC\Files\Node\Node $node
96
-	 * @return bool
97
-	 */
98
-	public function isSubNode($node) {
99
-		return strpos($node->getPath(), $this->path . '/') === 0;
100
-	}
101
-
102
-	/**
103
-	 * get the content of this directory
104
-	 *
105
-	 * @return Node[]
106
-	 * @throws \OCP\Files\NotFoundException
107
-	 */
108
-	public function getDirectoryListing() {
109
-		$folderContent = $this->view->getDirectoryContent($this->path);
110
-
111
-		return array_map(function (FileInfo $info) {
112
-			if ($info->getMimetype() === 'httpd/unix-directory') {
113
-				return new Folder($this->root, $this->view, $info->getPath(), $info);
114
-			} else {
115
-				return new File($this->root, $this->view, $info->getPath(), $info);
116
-			}
117
-		}, $folderContent);
118
-	}
119
-
120
-	/**
121
-	 * @param string $path
122
-	 * @param FileInfo $info
123
-	 * @return File|Folder
124
-	 */
125
-	protected function createNode($path, FileInfo $info = null) {
126
-		if (is_null($info)) {
127
-			$isDir = $this->view->is_dir($path);
128
-		} else {
129
-			$isDir = $info->getType() === FileInfo::TYPE_FOLDER;
130
-		}
131
-		if ($isDir) {
132
-			return new Folder($this->root, $this->view, $path, $info);
133
-		} else {
134
-			return new File($this->root, $this->view, $path, $info);
135
-		}
136
-	}
137
-
138
-	/**
139
-	 * Get the node at $path
140
-	 *
141
-	 * @param string $path
142
-	 * @return \OC\Files\Node\Node
143
-	 * @throws \OCP\Files\NotFoundException
144
-	 */
145
-	public function get($path) {
146
-		return $this->root->get($this->getFullPath($path));
147
-	}
148
-
149
-	/**
150
-	 * @param string $path
151
-	 * @return bool
152
-	 */
153
-	public function nodeExists($path) {
154
-		try {
155
-			$this->get($path);
156
-			return true;
157
-		} catch (NotFoundException $e) {
158
-			return false;
159
-		}
160
-	}
161
-
162
-	/**
163
-	 * @param string $path
164
-	 * @return \OC\Files\Node\Folder
165
-	 * @throws \OCP\Files\NotPermittedException
166
-	 */
167
-	public function newFolder($path) {
168
-		if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) {
169
-			$fullPath = $this->getFullPath($path);
170
-			$nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath);
171
-			$this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]);
172
-			if (!$this->view->mkdir($fullPath)) {
173
-				throw new NotPermittedException('Could not create folder');
174
-			}
175
-			$node = new Folder($this->root, $this->view, $fullPath);
176
-			$this->sendHooks(['postWrite', 'postCreate'], [$node]);
177
-			return $node;
178
-		} else {
179
-			throw new NotPermittedException('No create permission for folder');
180
-		}
181
-	}
182
-
183
-	/**
184
-	 * @param string $path
185
-	 * @param string | resource | null $content
186
-	 * @return \OC\Files\Node\File
187
-	 * @throws \OCP\Files\NotPermittedException
188
-	 */
189
-	public function newFile($path, $content = null) {
190
-		if (empty($path)) {
191
-			throw new NotPermittedException('Could not create as provided path is empty');
192
-		}
193
-		if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) {
194
-			$fullPath = $this->getFullPath($path);
195
-			$nonExisting = new NonExistingFile($this->root, $this->view, $fullPath);
196
-			$this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]);
197
-			if ($content !== null) {
198
-				$result = $this->view->file_put_contents($fullPath, $content);
199
-			} else {
200
-				$result = $this->view->touch($fullPath);
201
-			}
202
-			if ($result === false) {
203
-				throw new NotPermittedException('Could not create path');
204
-			}
205
-			$node = new File($this->root, $this->view, $fullPath);
206
-			$this->sendHooks(['postWrite', 'postCreate'], [$node]);
207
-			return $node;
208
-		}
209
-		throw new NotPermittedException('No create permission for path');
210
-	}
211
-
212
-	private function queryFromOperator(ISearchOperator $operator, string $uid = null): ISearchQuery {
213
-		if ($uid === null) {
214
-			$user = null;
215
-		} else {
216
-			/** @var IUserManager $userManager */
217
-			$userManager = \OC::$server->query(IUserManager::class);
218
-			$user = $userManager->get($uid);
219
-		}
220
-		return new SearchQuery($operator, 0, 0, [], $user);
221
-	}
222
-
223
-	/**
224
-	 * search for files with the name matching $query
225
-	 *
226
-	 * @param string|ISearchQuery $query
227
-	 * @return \OC\Files\Node\Node[]
228
-	 */
229
-	public function search($query) {
230
-		if (is_string($query)) {
231
-			$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%' . $query . '%'));
232
-		}
233
-
234
-		// Limit+offset for queries with ordering
235
-		//
236
-		// Because we currently can't do ordering between the results from different storages in sql
237
-		// The only way to do ordering is requesting the $limit number of entries from all storages
238
-		// sorting them and returning the first $limit entries.
239
-		//
240
-		// For offset we have the same problem, we don't know how many entries from each storage should be skipped
241
-		// by a given $offset, so instead we query $offset + $limit from each storage and return entries $offset..($offset+$limit)
242
-		// after merging and sorting them.
243
-		//
244
-		// This is suboptimal but because limit and offset tend to be fairly small in real world use cases it should
245
-		// still be significantly better than disabling paging altogether
246
-
247
-		$limitToHome = $query->limitToHome();
248
-		if ($limitToHome && count(explode('/', $this->path)) !== 3) {
249
-			throw new \InvalidArgumentException('searching by owner is only allows on the users home folder');
250
-		}
251
-
252
-		$rootLength = strlen($this->path);
253
-		$mount = $this->root->getMount($this->path);
254
-		$storage = $mount->getStorage();
255
-		$internalPath = $mount->getInternalPath($this->path);
256
-		$internalPath = rtrim($internalPath, '/');
257
-		if ($internalPath !== '') {
258
-			$internalPath = $internalPath . '/';
259
-		}
260
-
261
-		$subQueryLimit = $query->getLimit() > 0 ? $query->getLimit() + $query->getOffset() : 0;
262
-		$rootQuery = new SearchQuery(
263
-			new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [
264
-				new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $internalPath . '%'),
265
-				$query->getSearchOperation(),
266
-			]),
267
-			$subQueryLimit,
268
-			0,
269
-			$query->getOrder(),
270
-			$query->getUser()
271
-		);
272
-
273
-		$files = [];
274
-
275
-		$cache = $storage->getCache('');
276
-
277
-		$results = $cache->searchQuery($rootQuery);
278
-		foreach ($results as $result) {
279
-			$files[] = $this->cacheEntryToFileInfo($mount, '', $internalPath, $result);
280
-		}
281
-
282
-		if (!$limitToHome) {
283
-			$mounts = $this->root->getMountsIn($this->path);
284
-			foreach ($mounts as $mount) {
285
-				$subQuery = new SearchQuery(
286
-					$query->getSearchOperation(),
287
-					$subQueryLimit,
288
-					0,
289
-					$query->getOrder(),
290
-					$query->getUser()
291
-				);
292
-
293
-				$storage = $mount->getStorage();
294
-				if ($storage) {
295
-					$cache = $storage->getCache('');
296
-
297
-					$relativeMountPoint = ltrim(substr($mount->getMountPoint(), $rootLength), '/');
298
-					$results = $cache->searchQuery($subQuery);
299
-					foreach ($results as $result) {
300
-						$files[] = $this->cacheEntryToFileInfo($mount, $relativeMountPoint, '', $result);
301
-					}
302
-				}
303
-			}
304
-		}
305
-
306
-		$order = $query->getOrder();
307
-		if ($order) {
308
-			usort($files, function (FileInfo $a, FileInfo $b) use ($order) {
309
-				foreach ($order as $orderField) {
310
-					$cmp = $orderField->sortFileInfo($a, $b);
311
-					if ($cmp !== 0) {
312
-						return $cmp;
313
-					}
314
-				}
315
-				return 0;
316
-			});
317
-		}
318
-		$files = array_values(array_slice($files, $query->getOffset(), $query->getLimit() > 0 ? $query->getLimit() : null));
319
-
320
-		return array_map(function (FileInfo $file) {
321
-			return $this->createNode($file->getPath(), $file);
322
-		}, $files);
323
-	}
324
-
325
-	private function cacheEntryToFileInfo(IMountPoint $mount, string $appendRoot, string $trimRoot, ICacheEntry $cacheEntry): FileInfo {
326
-		$trimLength = strlen($trimRoot);
327
-		$cacheEntry['internalPath'] = $cacheEntry['path'];
328
-		$cacheEntry['path'] = $appendRoot . substr($cacheEntry['path'], $trimLength);
329
-		return new \OC\Files\FileInfo($this->path . '/' . $cacheEntry['path'], $mount->getStorage(), $cacheEntry['internalPath'], $cacheEntry, $mount);
330
-	}
331
-
332
-	/**
333
-	 * search for files by mimetype
334
-	 *
335
-	 * @param string $mimetype
336
-	 * @return Node[]
337
-	 */
338
-	public function searchByMime($mimetype) {
339
-		if (strpos($mimetype, '/') === false) {
340
-			$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $mimetype . '/%'));
341
-		} else {
342
-			$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', $mimetype));
343
-		}
344
-		return $this->search($query);
345
-	}
346
-
347
-	/**
348
-	 * search for files by tag
349
-	 *
350
-	 * @param string|int $tag name or tag id
351
-	 * @param string $userId owner of the tags
352
-	 * @return Node[]
353
-	 */
354
-	public function searchByTag($tag, $userId) {
355
-		$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'tagname', $tag), $userId);
356
-		return $this->search($query);
357
-	}
358
-
359
-	/**
360
-	 * @param int $id
361
-	 * @return \OC\Files\Node\Node[]
362
-	 */
363
-	public function getById($id) {
364
-		$mountCache = $this->root->getUserMountCache();
365
-		if (strpos($this->getPath(), '/', 1) > 0) {
366
-			[, $user] = explode('/', $this->getPath());
367
-		} else {
368
-			$user = null;
369
-		}
370
-		$mountsContainingFile = $mountCache->getMountsForFileId((int)$id, $user);
371
-		$mounts = $this->root->getMountsIn($this->path);
372
-		$mounts[] = $this->root->getMount($this->path);
373
-		/** @var IMountPoint[] $folderMounts */
374
-		$folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) {
375
-			return $mountPoint->getMountPoint();
376
-		}, $mounts), $mounts);
377
-
378
-		/** @var ICachedMountInfo[] $mountsContainingFile */
379
-		$mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) {
380
-			return isset($folderMounts[$cachedMountInfo->getMountPoint()]);
381
-		}));
382
-
383
-		if (count($mountsContainingFile) === 0) {
384
-			if ($user === $this->getAppDataDirectoryName()) {
385
-				return $this->getByIdInRootMount((int)$id);
386
-			}
387
-			return [];
388
-		}
389
-
390
-		$nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) {
391
-			$mount = $folderMounts[$cachedMountInfo->getMountPoint()];
392
-			$cacheEntry = $mount->getStorage()->getCache()->get((int)$id);
393
-			if (!$cacheEntry) {
394
-				return null;
395
-			}
396
-
397
-			// cache jails will hide the "true" internal path
398
-			$internalPath = ltrim($cachedMountInfo->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/');
399
-			$pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath()));
400
-			$pathRelativeToMount = ltrim($pathRelativeToMount, '/');
401
-			$absolutePath = rtrim($cachedMountInfo->getMountPoint() . $pathRelativeToMount, '/');
402
-			return $this->root->createNode($absolutePath, new \OC\Files\FileInfo(
403
-				$absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount,
404
-				\OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount))
405
-			));
406
-		}, $mountsContainingFile);
407
-
408
-		$nodes = array_filter($nodes);
409
-
410
-		return array_filter($nodes, function (Node $node) {
411
-			return $this->getRelativePath($node->getPath());
412
-		});
413
-	}
414
-
415
-	protected function getAppDataDirectoryName(): string {
416
-		$instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid');
417
-		return 'appdata_' . $instanceId;
418
-	}
419
-
420
-	/**
421
-	 * In case the path we are currently in is inside the appdata_* folder,
422
-	 * the original getById method does not work, because it can only look inside
423
-	 * the user's mount points. But the user has no mount point for the root storage.
424
-	 *
425
-	 * So in that case we directly check the mount of the root if it contains
426
-	 * the id. If it does we check if the path is inside the path we are working
427
-	 * in.
428
-	 *
429
-	 * @param int $id
430
-	 * @return array
431
-	 */
432
-	protected function getByIdInRootMount(int $id): array {
433
-		$mount = $this->root->getMount('');
434
-		$cacheEntry = $mount->getStorage()->getCache($this->path)->get($id);
435
-		if (!$cacheEntry) {
436
-			return [];
437
-		}
438
-
439
-		$absolutePath = '/' . ltrim($cacheEntry->getPath(), '/');
440
-		$currentPath = rtrim($this->path, '/') . '/';
441
-
442
-		if (strpos($absolutePath, $currentPath) !== 0) {
443
-			return [];
444
-		}
445
-
446
-		return [$this->root->createNode(
447
-			$absolutePath, new \OC\Files\FileInfo(
448
-			$absolutePath,
449
-			$mount->getStorage(),
450
-			$cacheEntry->getPath(),
451
-			$cacheEntry,
452
-			$mount
453
-		))];
454
-	}
455
-
456
-	public function getFreeSpace() {
457
-		return $this->view->free_space($this->path);
458
-	}
459
-
460
-	public function delete() {
461
-		if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
462
-			$this->sendHooks(['preDelete']);
463
-			$fileInfo = $this->getFileInfo();
464
-			$this->view->rmdir($this->path);
465
-			$nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo);
466
-			$this->sendHooks(['postDelete'], [$nonExisting]);
467
-			$this->exists = false;
468
-		} else {
469
-			throw new NotPermittedException('No delete permission for path');
470
-		}
471
-	}
472
-
473
-	/**
474
-	 * Add a suffix to the name in case the file exists
475
-	 *
476
-	 * @param string $name
477
-	 * @return string
478
-	 * @throws NotPermittedException
479
-	 */
480
-	public function getNonExistingName($name) {
481
-		$uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view);
482
-		return trim($this->getRelativePath($uniqueName), '/');
483
-	}
484
-
485
-	/**
486
-	 * @param int $limit
487
-	 * @param int $offset
488
-	 * @return \OCP\Files\Node[]
489
-	 */
490
-	public function getRecent($limit, $offset = 0) {
491
-		$query = new SearchQuery(
492
-			new SearchBinaryOperator(
493
-				// filter out non empty folders
494
-				ISearchBinaryOperator::OPERATOR_OR,
495
-				[
496
-					new SearchBinaryOperator(
497
-						ISearchBinaryOperator::OPERATOR_NOT,
498
-						[
499
-							new SearchComparison(
500
-								ISearchComparison::COMPARE_EQUAL,
501
-								'mimetype',
502
-								FileInfo::MIMETYPE_FOLDER
503
-							),
504
-						]
505
-					),
506
-					new SearchComparison(
507
-						ISearchComparison::COMPARE_EQUAL,
508
-						'size',
509
-						0
510
-					),
511
-				]
512
-			),
513
-			$limit,
514
-			$offset,
515
-			[
516
-				new SearchOrder(
517
-					ISearchOrder::DIRECTION_DESCENDING,
518
-					'mtime'
519
-				),
520
-			]
521
-		);
522
-		return $this->search($query);
523
-	}
52
+    /**
53
+     * Creates a Folder that represents a non-existing path
54
+     *
55
+     * @param string $path path
56
+     * @return string non-existing node class
57
+     */
58
+    protected function createNonExistingNode($path) {
59
+        return new NonExistingFolder($this->root, $this->view, $path);
60
+    }
61
+
62
+    /**
63
+     * @param string $path path relative to the folder
64
+     * @return string
65
+     * @throws \OCP\Files\NotPermittedException
66
+     */
67
+    public function getFullPath($path) {
68
+        if (!$this->isValidPath($path)) {
69
+            throw new NotPermittedException('Invalid path');
70
+        }
71
+        return $this->path . $this->normalizePath($path);
72
+    }
73
+
74
+    /**
75
+     * @param string $path
76
+     * @return string|null
77
+     */
78
+    public function getRelativePath($path) {
79
+        if ($this->path === '' or $this->path === '/') {
80
+            return $this->normalizePath($path);
81
+        }
82
+        if ($path === $this->path) {
83
+            return '/';
84
+        } elseif (strpos($path, $this->path . '/') !== 0) {
85
+            return null;
86
+        } else {
87
+            $path = substr($path, strlen($this->path));
88
+            return $this->normalizePath($path);
89
+        }
90
+    }
91
+
92
+    /**
93
+     * check if a node is a (grand-)child of the folder
94
+     *
95
+     * @param \OC\Files\Node\Node $node
96
+     * @return bool
97
+     */
98
+    public function isSubNode($node) {
99
+        return strpos($node->getPath(), $this->path . '/') === 0;
100
+    }
101
+
102
+    /**
103
+     * get the content of this directory
104
+     *
105
+     * @return Node[]
106
+     * @throws \OCP\Files\NotFoundException
107
+     */
108
+    public function getDirectoryListing() {
109
+        $folderContent = $this->view->getDirectoryContent($this->path);
110
+
111
+        return array_map(function (FileInfo $info) {
112
+            if ($info->getMimetype() === 'httpd/unix-directory') {
113
+                return new Folder($this->root, $this->view, $info->getPath(), $info);
114
+            } else {
115
+                return new File($this->root, $this->view, $info->getPath(), $info);
116
+            }
117
+        }, $folderContent);
118
+    }
119
+
120
+    /**
121
+     * @param string $path
122
+     * @param FileInfo $info
123
+     * @return File|Folder
124
+     */
125
+    protected function createNode($path, FileInfo $info = null) {
126
+        if (is_null($info)) {
127
+            $isDir = $this->view->is_dir($path);
128
+        } else {
129
+            $isDir = $info->getType() === FileInfo::TYPE_FOLDER;
130
+        }
131
+        if ($isDir) {
132
+            return new Folder($this->root, $this->view, $path, $info);
133
+        } else {
134
+            return new File($this->root, $this->view, $path, $info);
135
+        }
136
+    }
137
+
138
+    /**
139
+     * Get the node at $path
140
+     *
141
+     * @param string $path
142
+     * @return \OC\Files\Node\Node
143
+     * @throws \OCP\Files\NotFoundException
144
+     */
145
+    public function get($path) {
146
+        return $this->root->get($this->getFullPath($path));
147
+    }
148
+
149
+    /**
150
+     * @param string $path
151
+     * @return bool
152
+     */
153
+    public function nodeExists($path) {
154
+        try {
155
+            $this->get($path);
156
+            return true;
157
+        } catch (NotFoundException $e) {
158
+            return false;
159
+        }
160
+    }
161
+
162
+    /**
163
+     * @param string $path
164
+     * @return \OC\Files\Node\Folder
165
+     * @throws \OCP\Files\NotPermittedException
166
+     */
167
+    public function newFolder($path) {
168
+        if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) {
169
+            $fullPath = $this->getFullPath($path);
170
+            $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath);
171
+            $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]);
172
+            if (!$this->view->mkdir($fullPath)) {
173
+                throw new NotPermittedException('Could not create folder');
174
+            }
175
+            $node = new Folder($this->root, $this->view, $fullPath);
176
+            $this->sendHooks(['postWrite', 'postCreate'], [$node]);
177
+            return $node;
178
+        } else {
179
+            throw new NotPermittedException('No create permission for folder');
180
+        }
181
+    }
182
+
183
+    /**
184
+     * @param string $path
185
+     * @param string | resource | null $content
186
+     * @return \OC\Files\Node\File
187
+     * @throws \OCP\Files\NotPermittedException
188
+     */
189
+    public function newFile($path, $content = null) {
190
+        if (empty($path)) {
191
+            throw new NotPermittedException('Could not create as provided path is empty');
192
+        }
193
+        if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) {
194
+            $fullPath = $this->getFullPath($path);
195
+            $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath);
196
+            $this->sendHooks(['preWrite', 'preCreate'], [$nonExisting]);
197
+            if ($content !== null) {
198
+                $result = $this->view->file_put_contents($fullPath, $content);
199
+            } else {
200
+                $result = $this->view->touch($fullPath);
201
+            }
202
+            if ($result === false) {
203
+                throw new NotPermittedException('Could not create path');
204
+            }
205
+            $node = new File($this->root, $this->view, $fullPath);
206
+            $this->sendHooks(['postWrite', 'postCreate'], [$node]);
207
+            return $node;
208
+        }
209
+        throw new NotPermittedException('No create permission for path');
210
+    }
211
+
212
+    private function queryFromOperator(ISearchOperator $operator, string $uid = null): ISearchQuery {
213
+        if ($uid === null) {
214
+            $user = null;
215
+        } else {
216
+            /** @var IUserManager $userManager */
217
+            $userManager = \OC::$server->query(IUserManager::class);
218
+            $user = $userManager->get($uid);
219
+        }
220
+        return new SearchQuery($operator, 0, 0, [], $user);
221
+    }
222
+
223
+    /**
224
+     * search for files with the name matching $query
225
+     *
226
+     * @param string|ISearchQuery $query
227
+     * @return \OC\Files\Node\Node[]
228
+     */
229
+    public function search($query) {
230
+        if (is_string($query)) {
231
+            $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%' . $query . '%'));
232
+        }
233
+
234
+        // Limit+offset for queries with ordering
235
+        //
236
+        // Because we currently can't do ordering between the results from different storages in sql
237
+        // The only way to do ordering is requesting the $limit number of entries from all storages
238
+        // sorting them and returning the first $limit entries.
239
+        //
240
+        // For offset we have the same problem, we don't know how many entries from each storage should be skipped
241
+        // by a given $offset, so instead we query $offset + $limit from each storage and return entries $offset..($offset+$limit)
242
+        // after merging and sorting them.
243
+        //
244
+        // This is suboptimal but because limit and offset tend to be fairly small in real world use cases it should
245
+        // still be significantly better than disabling paging altogether
246
+
247
+        $limitToHome = $query->limitToHome();
248
+        if ($limitToHome && count(explode('/', $this->path)) !== 3) {
249
+            throw new \InvalidArgumentException('searching by owner is only allows on the users home folder');
250
+        }
251
+
252
+        $rootLength = strlen($this->path);
253
+        $mount = $this->root->getMount($this->path);
254
+        $storage = $mount->getStorage();
255
+        $internalPath = $mount->getInternalPath($this->path);
256
+        $internalPath = rtrim($internalPath, '/');
257
+        if ($internalPath !== '') {
258
+            $internalPath = $internalPath . '/';
259
+        }
260
+
261
+        $subQueryLimit = $query->getLimit() > 0 ? $query->getLimit() + $query->getOffset() : 0;
262
+        $rootQuery = new SearchQuery(
263
+            new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [
264
+                new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $internalPath . '%'),
265
+                $query->getSearchOperation(),
266
+            ]),
267
+            $subQueryLimit,
268
+            0,
269
+            $query->getOrder(),
270
+            $query->getUser()
271
+        );
272
+
273
+        $files = [];
274
+
275
+        $cache = $storage->getCache('');
276
+
277
+        $results = $cache->searchQuery($rootQuery);
278
+        foreach ($results as $result) {
279
+            $files[] = $this->cacheEntryToFileInfo($mount, '', $internalPath, $result);
280
+        }
281
+
282
+        if (!$limitToHome) {
283
+            $mounts = $this->root->getMountsIn($this->path);
284
+            foreach ($mounts as $mount) {
285
+                $subQuery = new SearchQuery(
286
+                    $query->getSearchOperation(),
287
+                    $subQueryLimit,
288
+                    0,
289
+                    $query->getOrder(),
290
+                    $query->getUser()
291
+                );
292
+
293
+                $storage = $mount->getStorage();
294
+                if ($storage) {
295
+                    $cache = $storage->getCache('');
296
+
297
+                    $relativeMountPoint = ltrim(substr($mount->getMountPoint(), $rootLength), '/');
298
+                    $results = $cache->searchQuery($subQuery);
299
+                    foreach ($results as $result) {
300
+                        $files[] = $this->cacheEntryToFileInfo($mount, $relativeMountPoint, '', $result);
301
+                    }
302
+                }
303
+            }
304
+        }
305
+
306
+        $order = $query->getOrder();
307
+        if ($order) {
308
+            usort($files, function (FileInfo $a, FileInfo $b) use ($order) {
309
+                foreach ($order as $orderField) {
310
+                    $cmp = $orderField->sortFileInfo($a, $b);
311
+                    if ($cmp !== 0) {
312
+                        return $cmp;
313
+                    }
314
+                }
315
+                return 0;
316
+            });
317
+        }
318
+        $files = array_values(array_slice($files, $query->getOffset(), $query->getLimit() > 0 ? $query->getLimit() : null));
319
+
320
+        return array_map(function (FileInfo $file) {
321
+            return $this->createNode($file->getPath(), $file);
322
+        }, $files);
323
+    }
324
+
325
+    private function cacheEntryToFileInfo(IMountPoint $mount, string $appendRoot, string $trimRoot, ICacheEntry $cacheEntry): FileInfo {
326
+        $trimLength = strlen($trimRoot);
327
+        $cacheEntry['internalPath'] = $cacheEntry['path'];
328
+        $cacheEntry['path'] = $appendRoot . substr($cacheEntry['path'], $trimLength);
329
+        return new \OC\Files\FileInfo($this->path . '/' . $cacheEntry['path'], $mount->getStorage(), $cacheEntry['internalPath'], $cacheEntry, $mount);
330
+    }
331
+
332
+    /**
333
+     * search for files by mimetype
334
+     *
335
+     * @param string $mimetype
336
+     * @return Node[]
337
+     */
338
+    public function searchByMime($mimetype) {
339
+        if (strpos($mimetype, '/') === false) {
340
+            $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $mimetype . '/%'));
341
+        } else {
342
+            $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', $mimetype));
343
+        }
344
+        return $this->search($query);
345
+    }
346
+
347
+    /**
348
+     * search for files by tag
349
+     *
350
+     * @param string|int $tag name or tag id
351
+     * @param string $userId owner of the tags
352
+     * @return Node[]
353
+     */
354
+    public function searchByTag($tag, $userId) {
355
+        $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'tagname', $tag), $userId);
356
+        return $this->search($query);
357
+    }
358
+
359
+    /**
360
+     * @param int $id
361
+     * @return \OC\Files\Node\Node[]
362
+     */
363
+    public function getById($id) {
364
+        $mountCache = $this->root->getUserMountCache();
365
+        if (strpos($this->getPath(), '/', 1) > 0) {
366
+            [, $user] = explode('/', $this->getPath());
367
+        } else {
368
+            $user = null;
369
+        }
370
+        $mountsContainingFile = $mountCache->getMountsForFileId((int)$id, $user);
371
+        $mounts = $this->root->getMountsIn($this->path);
372
+        $mounts[] = $this->root->getMount($this->path);
373
+        /** @var IMountPoint[] $folderMounts */
374
+        $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) {
375
+            return $mountPoint->getMountPoint();
376
+        }, $mounts), $mounts);
377
+
378
+        /** @var ICachedMountInfo[] $mountsContainingFile */
379
+        $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) {
380
+            return isset($folderMounts[$cachedMountInfo->getMountPoint()]);
381
+        }));
382
+
383
+        if (count($mountsContainingFile) === 0) {
384
+            if ($user === $this->getAppDataDirectoryName()) {
385
+                return $this->getByIdInRootMount((int)$id);
386
+            }
387
+            return [];
388
+        }
389
+
390
+        $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) {
391
+            $mount = $folderMounts[$cachedMountInfo->getMountPoint()];
392
+            $cacheEntry = $mount->getStorage()->getCache()->get((int)$id);
393
+            if (!$cacheEntry) {
394
+                return null;
395
+            }
396
+
397
+            // cache jails will hide the "true" internal path
398
+            $internalPath = ltrim($cachedMountInfo->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/');
399
+            $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath()));
400
+            $pathRelativeToMount = ltrim($pathRelativeToMount, '/');
401
+            $absolutePath = rtrim($cachedMountInfo->getMountPoint() . $pathRelativeToMount, '/');
402
+            return $this->root->createNode($absolutePath, new \OC\Files\FileInfo(
403
+                $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount,
404
+                \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount))
405
+            ));
406
+        }, $mountsContainingFile);
407
+
408
+        $nodes = array_filter($nodes);
409
+
410
+        return array_filter($nodes, function (Node $node) {
411
+            return $this->getRelativePath($node->getPath());
412
+        });
413
+    }
414
+
415
+    protected function getAppDataDirectoryName(): string {
416
+        $instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid');
417
+        return 'appdata_' . $instanceId;
418
+    }
419
+
420
+    /**
421
+     * In case the path we are currently in is inside the appdata_* folder,
422
+     * the original getById method does not work, because it can only look inside
423
+     * the user's mount points. But the user has no mount point for the root storage.
424
+     *
425
+     * So in that case we directly check the mount of the root if it contains
426
+     * the id. If it does we check if the path is inside the path we are working
427
+     * in.
428
+     *
429
+     * @param int $id
430
+     * @return array
431
+     */
432
+    protected function getByIdInRootMount(int $id): array {
433
+        $mount = $this->root->getMount('');
434
+        $cacheEntry = $mount->getStorage()->getCache($this->path)->get($id);
435
+        if (!$cacheEntry) {
436
+            return [];
437
+        }
438
+
439
+        $absolutePath = '/' . ltrim($cacheEntry->getPath(), '/');
440
+        $currentPath = rtrim($this->path, '/') . '/';
441
+
442
+        if (strpos($absolutePath, $currentPath) !== 0) {
443
+            return [];
444
+        }
445
+
446
+        return [$this->root->createNode(
447
+            $absolutePath, new \OC\Files\FileInfo(
448
+            $absolutePath,
449
+            $mount->getStorage(),
450
+            $cacheEntry->getPath(),
451
+            $cacheEntry,
452
+            $mount
453
+        ))];
454
+    }
455
+
456
+    public function getFreeSpace() {
457
+        return $this->view->free_space($this->path);
458
+    }
459
+
460
+    public function delete() {
461
+        if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) {
462
+            $this->sendHooks(['preDelete']);
463
+            $fileInfo = $this->getFileInfo();
464
+            $this->view->rmdir($this->path);
465
+            $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo);
466
+            $this->sendHooks(['postDelete'], [$nonExisting]);
467
+            $this->exists = false;
468
+        } else {
469
+            throw new NotPermittedException('No delete permission for path');
470
+        }
471
+    }
472
+
473
+    /**
474
+     * Add a suffix to the name in case the file exists
475
+     *
476
+     * @param string $name
477
+     * @return string
478
+     * @throws NotPermittedException
479
+     */
480
+    public function getNonExistingName($name) {
481
+        $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view);
482
+        return trim($this->getRelativePath($uniqueName), '/');
483
+    }
484
+
485
+    /**
486
+     * @param int $limit
487
+     * @param int $offset
488
+     * @return \OCP\Files\Node[]
489
+     */
490
+    public function getRecent($limit, $offset = 0) {
491
+        $query = new SearchQuery(
492
+            new SearchBinaryOperator(
493
+                // filter out non empty folders
494
+                ISearchBinaryOperator::OPERATOR_OR,
495
+                [
496
+                    new SearchBinaryOperator(
497
+                        ISearchBinaryOperator::OPERATOR_NOT,
498
+                        [
499
+                            new SearchComparison(
500
+                                ISearchComparison::COMPARE_EQUAL,
501
+                                'mimetype',
502
+                                FileInfo::MIMETYPE_FOLDER
503
+                            ),
504
+                        ]
505
+                    ),
506
+                    new SearchComparison(
507
+                        ISearchComparison::COMPARE_EQUAL,
508
+                        'size',
509
+                        0
510
+                    ),
511
+                ]
512
+            ),
513
+            $limit,
514
+            $offset,
515
+            [
516
+                new SearchOrder(
517
+                    ISearchOrder::DIRECTION_DESCENDING,
518
+                    'mtime'
519
+                ),
520
+            ]
521
+        );
522
+        return $this->search($query);
523
+    }
524 524
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		if (!$this->isValidPath($path)) {
69 69
 			throw new NotPermittedException('Invalid path');
70 70
 		}
71
-		return $this->path . $this->normalizePath($path);
71
+		return $this->path.$this->normalizePath($path);
72 72
 	}
73 73
 
74 74
 	/**
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 		}
82 82
 		if ($path === $this->path) {
83 83
 			return '/';
84
-		} elseif (strpos($path, $this->path . '/') !== 0) {
84
+		} elseif (strpos($path, $this->path.'/') !== 0) {
85 85
 			return null;
86 86
 		} else {
87 87
 			$path = substr($path, strlen($this->path));
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @return bool
97 97
 	 */
98 98
 	public function isSubNode($node) {
99
-		return strpos($node->getPath(), $this->path . '/') === 0;
99
+		return strpos($node->getPath(), $this->path.'/') === 0;
100 100
 	}
101 101
 
102 102
 	/**
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	public function getDirectoryListing() {
109 109
 		$folderContent = $this->view->getDirectoryContent($this->path);
110 110
 
111
-		return array_map(function (FileInfo $info) {
111
+		return array_map(function(FileInfo $info) {
112 112
 			if ($info->getMimetype() === 'httpd/unix-directory') {
113 113
 				return new Folder($this->root, $this->view, $info->getPath(), $info);
114 114
 			} else {
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 */
229 229
 	public function search($query) {
230 230
 		if (is_string($query)) {
231
-			$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%' . $query . '%'));
231
+			$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%'.$query.'%'));
232 232
 		}
233 233
 
234 234
 		// Limit+offset for queries with ordering
@@ -255,13 +255,13 @@  discard block
 block discarded – undo
255 255
 		$internalPath = $mount->getInternalPath($this->path);
256 256
 		$internalPath = rtrim($internalPath, '/');
257 257
 		if ($internalPath !== '') {
258
-			$internalPath = $internalPath . '/';
258
+			$internalPath = $internalPath.'/';
259 259
 		}
260 260
 
261 261
 		$subQueryLimit = $query->getLimit() > 0 ? $query->getLimit() + $query->getOffset() : 0;
262 262
 		$rootQuery = new SearchQuery(
263 263
 			new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [
264
-				new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $internalPath . '%'),
264
+				new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $internalPath.'%'),
265 265
 				$query->getSearchOperation(),
266 266
 			]),
267 267
 			$subQueryLimit,
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 
306 306
 		$order = $query->getOrder();
307 307
 		if ($order) {
308
-			usort($files, function (FileInfo $a, FileInfo $b) use ($order) {
308
+			usort($files, function(FileInfo $a, FileInfo $b) use ($order) {
309 309
 				foreach ($order as $orderField) {
310 310
 					$cmp = $orderField->sortFileInfo($a, $b);
311 311
 					if ($cmp !== 0) {
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 		}
318 318
 		$files = array_values(array_slice($files, $query->getOffset(), $query->getLimit() > 0 ? $query->getLimit() : null));
319 319
 
320
-		return array_map(function (FileInfo $file) {
320
+		return array_map(function(FileInfo $file) {
321 321
 			return $this->createNode($file->getPath(), $file);
322 322
 		}, $files);
323 323
 	}
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 	private function cacheEntryToFileInfo(IMountPoint $mount, string $appendRoot, string $trimRoot, ICacheEntry $cacheEntry): FileInfo {
326 326
 		$trimLength = strlen($trimRoot);
327 327
 		$cacheEntry['internalPath'] = $cacheEntry['path'];
328
-		$cacheEntry['path'] = $appendRoot . substr($cacheEntry['path'], $trimLength);
329
-		return new \OC\Files\FileInfo($this->path . '/' . $cacheEntry['path'], $mount->getStorage(), $cacheEntry['internalPath'], $cacheEntry, $mount);
328
+		$cacheEntry['path'] = $appendRoot.substr($cacheEntry['path'], $trimLength);
329
+		return new \OC\Files\FileInfo($this->path.'/'.$cacheEntry['path'], $mount->getStorage(), $cacheEntry['internalPath'], $cacheEntry, $mount);
330 330
 	}
331 331
 
332 332
 	/**
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 	 */
338 338
 	public function searchByMime($mimetype) {
339 339
 		if (strpos($mimetype, '/') === false) {
340
-			$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $mimetype . '/%'));
340
+			$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', $mimetype.'/%'));
341 341
 		} else {
342 342
 			$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', $mimetype));
343 343
 		}
@@ -367,38 +367,38 @@  discard block
 block discarded – undo
367 367
 		} else {
368 368
 			$user = null;
369 369
 		}
370
-		$mountsContainingFile = $mountCache->getMountsForFileId((int)$id, $user);
370
+		$mountsContainingFile = $mountCache->getMountsForFileId((int) $id, $user);
371 371
 		$mounts = $this->root->getMountsIn($this->path);
372 372
 		$mounts[] = $this->root->getMount($this->path);
373 373
 		/** @var IMountPoint[] $folderMounts */
374
-		$folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) {
374
+		$folderMounts = array_combine(array_map(function(IMountPoint $mountPoint) {
375 375
 			return $mountPoint->getMountPoint();
376 376
 		}, $mounts), $mounts);
377 377
 
378 378
 		/** @var ICachedMountInfo[] $mountsContainingFile */
379
-		$mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) {
379
+		$mountsContainingFile = array_values(array_filter($mountsContainingFile, function(ICachedMountInfo $cachedMountInfo) use ($folderMounts) {
380 380
 			return isset($folderMounts[$cachedMountInfo->getMountPoint()]);
381 381
 		}));
382 382
 
383 383
 		if (count($mountsContainingFile) === 0) {
384 384
 			if ($user === $this->getAppDataDirectoryName()) {
385
-				return $this->getByIdInRootMount((int)$id);
385
+				return $this->getByIdInRootMount((int) $id);
386 386
 			}
387 387
 			return [];
388 388
 		}
389 389
 
390
-		$nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) {
390
+		$nodes = array_map(function(ICachedMountInfo $cachedMountInfo) use ($folderMounts, $id) {
391 391
 			$mount = $folderMounts[$cachedMountInfo->getMountPoint()];
392
-			$cacheEntry = $mount->getStorage()->getCache()->get((int)$id);
392
+			$cacheEntry = $mount->getStorage()->getCache()->get((int) $id);
393 393
 			if (!$cacheEntry) {
394 394
 				return null;
395 395
 			}
396 396
 
397 397
 			// cache jails will hide the "true" internal path
398
-			$internalPath = ltrim($cachedMountInfo->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/');
398
+			$internalPath = ltrim($cachedMountInfo->getRootInternalPath().'/'.$cacheEntry->getPath(), '/');
399 399
 			$pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath()));
400 400
 			$pathRelativeToMount = ltrim($pathRelativeToMount, '/');
401
-			$absolutePath = rtrim($cachedMountInfo->getMountPoint() . $pathRelativeToMount, '/');
401
+			$absolutePath = rtrim($cachedMountInfo->getMountPoint().$pathRelativeToMount, '/');
402 402
 			return $this->root->createNode($absolutePath, new \OC\Files\FileInfo(
403 403
 				$absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount,
404 404
 				\OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount))
@@ -407,14 +407,14 @@  discard block
 block discarded – undo
407 407
 
408 408
 		$nodes = array_filter($nodes);
409 409
 
410
-		return array_filter($nodes, function (Node $node) {
410
+		return array_filter($nodes, function(Node $node) {
411 411
 			return $this->getRelativePath($node->getPath());
412 412
 		});
413 413
 	}
414 414
 
415 415
 	protected function getAppDataDirectoryName(): string {
416 416
 		$instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid');
417
-		return 'appdata_' . $instanceId;
417
+		return 'appdata_'.$instanceId;
418 418
 	}
419 419
 
420 420
 	/**
@@ -436,8 +436,8 @@  discard block
 block discarded – undo
436 436
 			return [];
437 437
 		}
438 438
 
439
-		$absolutePath = '/' . ltrim($cacheEntry->getPath(), '/');
440
-		$currentPath = rtrim($this->path, '/') . '/';
439
+		$absolutePath = '/'.ltrim($cacheEntry->getPath(), '/');
440
+		$currentPath = rtrim($this->path, '/').'/';
441 441
 
442 442
 		if (strpos($absolutePath, $currentPath) !== 0) {
443 443
 			return [];
Please login to merge, or discard this patch.