Passed
Push — master ( 323f40...cdc43c )
by Roeland
13:28 queued 10s
created
lib/private/Lockdown/Filesystem/NullCache.php 1 patch
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -30,97 +30,97 @@
 block discarded – undo
30 30
 use OCP\Files\Search\ISearchQuery;
31 31
 
32 32
 class NullCache implements ICache {
33
-	public function getNumericStorageId() {
34
-		return -1;
35
-	}
36
-
37
-	public function get($file) {
38
-		return $file !== '' ? null :
39
-			new CacheEntry([
40
-				'fileid' => -1,
41
-				'parent' => -1,
42
-				'name' => '',
43
-				'path' => '',
44
-				'size' => '0',
45
-				'mtime' => time(),
46
-				'storage_mtime' => time(),
47
-				'etag' => '',
48
-				'mimetype' => FileInfo::MIMETYPE_FOLDER,
49
-				'mimepart' => 'httpd',
50
-				'permissions' => Constants::PERMISSION_READ
51
-			]);
52
-	}
53
-
54
-	public function getFolderContents($folder) {
55
-		return [];
56
-	}
57
-
58
-	public function getFolderContentsById($fileId) {
59
-		return [];
60
-	}
61
-
62
-	public function put($file, array $data) {
63
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
64
-	}
65
-
66
-	public function insert($file, array $data) {
67
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
68
-	}
69
-
70
-	public function update($id, array $data) {
71
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
72
-	}
73
-
74
-	public function getId($file) {
75
-		return -1;
76
-	}
77
-
78
-	public function getParentId($file) {
79
-		return -1;
80
-	}
81
-
82
-	public function inCache($file) {
83
-		return $file === '';
84
-	}
85
-
86
-	public function remove($file) {
87
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
88
-	}
89
-
90
-	public function move($source, $target) {
91
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
92
-	}
93
-
94
-	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
95
-		throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
96
-	}
97
-
98
-	public function getStatus($file) {
99
-		return ICache::COMPLETE;
100
-	}
101
-
102
-	public function search($pattern) {
103
-		return [];
104
-	}
105
-
106
-	public function searchByMime($mimetype) {
107
-		return [];
108
-	}
109
-
110
-	public function searchQuery(ISearchQuery $query) {
111
-		return [];
112
-	}
113
-
114
-	public function getIncomplete() {
115
-		return [];
116
-	}
117
-
118
-	public function getPathById($id) {
119
-		return '';
120
-	}
121
-
122
-	public function normalize($path) {
123
-		return $path;
124
-	}
33
+    public function getNumericStorageId() {
34
+        return -1;
35
+    }
36
+
37
+    public function get($file) {
38
+        return $file !== '' ? null :
39
+            new CacheEntry([
40
+                'fileid' => -1,
41
+                'parent' => -1,
42
+                'name' => '',
43
+                'path' => '',
44
+                'size' => '0',
45
+                'mtime' => time(),
46
+                'storage_mtime' => time(),
47
+                'etag' => '',
48
+                'mimetype' => FileInfo::MIMETYPE_FOLDER,
49
+                'mimepart' => 'httpd',
50
+                'permissions' => Constants::PERMISSION_READ
51
+            ]);
52
+    }
53
+
54
+    public function getFolderContents($folder) {
55
+        return [];
56
+    }
57
+
58
+    public function getFolderContentsById($fileId) {
59
+        return [];
60
+    }
61
+
62
+    public function put($file, array $data) {
63
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
64
+    }
65
+
66
+    public function insert($file, array $data) {
67
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
68
+    }
69
+
70
+    public function update($id, array $data) {
71
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
72
+    }
73
+
74
+    public function getId($file) {
75
+        return -1;
76
+    }
77
+
78
+    public function getParentId($file) {
79
+        return -1;
80
+    }
81
+
82
+    public function inCache($file) {
83
+        return $file === '';
84
+    }
85
+
86
+    public function remove($file) {
87
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
88
+    }
89
+
90
+    public function move($source, $target) {
91
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
92
+    }
93
+
94
+    public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
95
+        throw new \OC\ForbiddenException('This request is not allowed to access the filesystem');
96
+    }
97
+
98
+    public function getStatus($file) {
99
+        return ICache::COMPLETE;
100
+    }
101
+
102
+    public function search($pattern) {
103
+        return [];
104
+    }
105
+
106
+    public function searchByMime($mimetype) {
107
+        return [];
108
+    }
109
+
110
+    public function searchQuery(ISearchQuery $query) {
111
+        return [];
112
+    }
113
+
114
+    public function getIncomplete() {
115
+        return [];
116
+    }
117
+
118
+    public function getPathById($id) {
119
+        return '';
120
+    }
121
+
122
+    public function normalize($path) {
123
+        return $path;
124
+    }
125 125
 
126 126
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/Cache.php 2 patches
Indentation   +825 added lines, -825 removed lines patch added patch discarded remove patch
@@ -61,840 +61,840 @@
 block discarded – undo
61 61
  * - ChangePropagator: updates the mtime and etags of parent folders whenever a change to the cache is made to the cache by the updater
62 62
  */
63 63
 class Cache implements ICache {
64
-	use MoveFromCacheTrait {
65
-		MoveFromCacheTrait::moveFromCache as moveFromCacheFallback;
66
-	}
67
-
68
-	/**
69
-	 * @var array partial data for the cache
70
-	 */
71
-	protected $partial = array();
72
-
73
-	/**
74
-	 * @var string
75
-	 */
76
-	protected $storageId;
77
-
78
-	private $storage;
79
-
80
-	/**
81
-	 * @var Storage $storageCache
82
-	 */
83
-	protected $storageCache;
84
-
85
-	/** @var IMimeTypeLoader */
86
-	protected $mimetypeLoader;
87
-
88
-	/**
89
-	 * @var IDBConnection
90
-	 */
91
-	protected $connection;
92
-
93
-	protected $eventDispatcher;
94
-
95
-	/** @var QuerySearchHelper */
96
-	protected $querySearchHelper;
97
-
98
-	/**
99
-	 * @param IStorage $storage
100
-	 */
101
-	public function __construct(IStorage $storage) {
102
-		$this->storageId = $storage->getId();
103
-		$this->storage = $storage;
104
-		if (strlen($this->storageId) > 64) {
105
-			$this->storageId = md5($this->storageId);
106
-		}
107
-
108
-		$this->storageCache = new Storage($storage);
109
-		$this->mimetypeLoader = \OC::$server->getMimeTypeLoader();
110
-		$this->connection = \OC::$server->getDatabaseConnection();
111
-		$this->eventDispatcher = \OC::$server->getEventDispatcher();
112
-		$this->querySearchHelper = new QuerySearchHelper($this->mimetypeLoader);
113
-	}
114
-
115
-	/**
116
-	 * Get the numeric storage id for this cache's storage
117
-	 *
118
-	 * @return int
119
-	 */
120
-	public function getNumericStorageId() {
121
-		return $this->storageCache->getNumericId();
122
-	}
123
-
124
-	/**
125
-	 * get the stored metadata of a file or folder
126
-	 *
127
-	 * @param string | int $file either the path of a file or folder or the file id for a file or folder
128
-	 * @return ICacheEntry|false the cache entry as array of false if the file is not found in the cache
129
-	 */
130
-	public function get($file) {
131
-		if (is_string($file) or $file == '') {
132
-			// normalize file
133
-			$file = $this->normalize($file);
134
-
135
-			$where = 'WHERE `storage` = ? AND `path_hash` = ?';
136
-			$params = array($this->getNumericStorageId(), md5($file));
137
-		} else { //file id
138
-			$where = 'WHERE `fileid` = ?';
139
-			$params = array($file);
140
-		}
141
-		$sql = 'SELECT `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
64
+    use MoveFromCacheTrait {
65
+        MoveFromCacheTrait::moveFromCache as moveFromCacheFallback;
66
+    }
67
+
68
+    /**
69
+     * @var array partial data for the cache
70
+     */
71
+    protected $partial = array();
72
+
73
+    /**
74
+     * @var string
75
+     */
76
+    protected $storageId;
77
+
78
+    private $storage;
79
+
80
+    /**
81
+     * @var Storage $storageCache
82
+     */
83
+    protected $storageCache;
84
+
85
+    /** @var IMimeTypeLoader */
86
+    protected $mimetypeLoader;
87
+
88
+    /**
89
+     * @var IDBConnection
90
+     */
91
+    protected $connection;
92
+
93
+    protected $eventDispatcher;
94
+
95
+    /** @var QuerySearchHelper */
96
+    protected $querySearchHelper;
97
+
98
+    /**
99
+     * @param IStorage $storage
100
+     */
101
+    public function __construct(IStorage $storage) {
102
+        $this->storageId = $storage->getId();
103
+        $this->storage = $storage;
104
+        if (strlen($this->storageId) > 64) {
105
+            $this->storageId = md5($this->storageId);
106
+        }
107
+
108
+        $this->storageCache = new Storage($storage);
109
+        $this->mimetypeLoader = \OC::$server->getMimeTypeLoader();
110
+        $this->connection = \OC::$server->getDatabaseConnection();
111
+        $this->eventDispatcher = \OC::$server->getEventDispatcher();
112
+        $this->querySearchHelper = new QuerySearchHelper($this->mimetypeLoader);
113
+    }
114
+
115
+    /**
116
+     * Get the numeric storage id for this cache's storage
117
+     *
118
+     * @return int
119
+     */
120
+    public function getNumericStorageId() {
121
+        return $this->storageCache->getNumericId();
122
+    }
123
+
124
+    /**
125
+     * get the stored metadata of a file or folder
126
+     *
127
+     * @param string | int $file either the path of a file or folder or the file id for a file or folder
128
+     * @return ICacheEntry|false the cache entry as array of false if the file is not found in the cache
129
+     */
130
+    public function get($file) {
131
+        if (is_string($file) or $file == '') {
132
+            // normalize file
133
+            $file = $this->normalize($file);
134
+
135
+            $where = 'WHERE `storage` = ? AND `path_hash` = ?';
136
+            $params = array($this->getNumericStorageId(), md5($file));
137
+        } else { //file id
138
+            $where = 'WHERE `fileid` = ?';
139
+            $params = array($file);
140
+        }
141
+        $sql = 'SELECT `fileid`, `storage`, `path`, `path_hash`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
142 142
 					   `storage_mtime`, `encrypted`, `etag`, `permissions`, `checksum`
143 143
 				FROM `*PREFIX*filecache` ' . $where;
144
-		$result = $this->connection->executeQuery($sql, $params);
145
-		$data = $result->fetch();
146
-
147
-		//FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO
148
-		//PDO returns false, MDB2 returns null, oracle always uses MDB2, so convert null to false
149
-		if ($data === null) {
150
-			$data = false;
151
-		}
152
-
153
-		//merge partial data
154
-		if (!$data and is_string($file)) {
155
-			if (isset($this->partial[$file])) {
156
-				$data = $this->partial[$file];
157
-			}
158
-			return $data;
159
-		} else if (!$data) {
160
-			return $data;
161
-		} else {
162
-			return self::cacheEntryFromData($data, $this->mimetypeLoader);
163
-		}
164
-	}
165
-
166
-	/**
167
-	 * Create a CacheEntry from database row
168
-	 *
169
-	 * @param array $data
170
-	 * @param IMimeTypeLoader $mimetypeLoader
171
-	 * @return CacheEntry
172
-	 */
173
-	public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader) {
174
-		//fix types
175
-		$data['fileid'] = (int)$data['fileid'];
176
-		$data['parent'] = (int)$data['parent'];
177
-		$data['size'] = 0 + $data['size'];
178
-		$data['mtime'] = (int)$data['mtime'];
179
-		$data['storage_mtime'] = (int)$data['storage_mtime'];
180
-		$data['encryptedVersion'] = (int)$data['encrypted'];
181
-		$data['encrypted'] = (bool)$data['encrypted'];
182
-		$data['storage_id'] = $data['storage'];
183
-		$data['storage'] = (int)$data['storage'];
184
-		$data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']);
185
-		$data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']);
186
-		if ($data['storage_mtime'] == 0) {
187
-			$data['storage_mtime'] = $data['mtime'];
188
-		}
189
-		$data['permissions'] = (int)$data['permissions'];
190
-		return new CacheEntry($data);
191
-	}
192
-
193
-	/**
194
-	 * get the metadata of all files stored in $folder
195
-	 *
196
-	 * @param string $folder
197
-	 * @return ICacheEntry[]
198
-	 */
199
-	public function getFolderContents($folder) {
200
-		$fileId = $this->getId($folder);
201
-		return $this->getFolderContentsById($fileId);
202
-	}
203
-
204
-	/**
205
-	 * get the metadata of all files stored in $folder
206
-	 *
207
-	 * @param int $fileId the file id of the folder
208
-	 * @return ICacheEntry[]
209
-	 */
210
-	public function getFolderContentsById($fileId) {
211
-		if ($fileId > -1) {
212
-			$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
144
+        $result = $this->connection->executeQuery($sql, $params);
145
+        $data = $result->fetch();
146
+
147
+        //FIXME hide this HACK in the next database layer, or just use doctrine and get rid of MDB2 and PDO
148
+        //PDO returns false, MDB2 returns null, oracle always uses MDB2, so convert null to false
149
+        if ($data === null) {
150
+            $data = false;
151
+        }
152
+
153
+        //merge partial data
154
+        if (!$data and is_string($file)) {
155
+            if (isset($this->partial[$file])) {
156
+                $data = $this->partial[$file];
157
+            }
158
+            return $data;
159
+        } else if (!$data) {
160
+            return $data;
161
+        } else {
162
+            return self::cacheEntryFromData($data, $this->mimetypeLoader);
163
+        }
164
+    }
165
+
166
+    /**
167
+     * Create a CacheEntry from database row
168
+     *
169
+     * @param array $data
170
+     * @param IMimeTypeLoader $mimetypeLoader
171
+     * @return CacheEntry
172
+     */
173
+    public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader) {
174
+        //fix types
175
+        $data['fileid'] = (int)$data['fileid'];
176
+        $data['parent'] = (int)$data['parent'];
177
+        $data['size'] = 0 + $data['size'];
178
+        $data['mtime'] = (int)$data['mtime'];
179
+        $data['storage_mtime'] = (int)$data['storage_mtime'];
180
+        $data['encryptedVersion'] = (int)$data['encrypted'];
181
+        $data['encrypted'] = (bool)$data['encrypted'];
182
+        $data['storage_id'] = $data['storage'];
183
+        $data['storage'] = (int)$data['storage'];
184
+        $data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']);
185
+        $data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']);
186
+        if ($data['storage_mtime'] == 0) {
187
+            $data['storage_mtime'] = $data['mtime'];
188
+        }
189
+        $data['permissions'] = (int)$data['permissions'];
190
+        return new CacheEntry($data);
191
+    }
192
+
193
+    /**
194
+     * get the metadata of all files stored in $folder
195
+     *
196
+     * @param string $folder
197
+     * @return ICacheEntry[]
198
+     */
199
+    public function getFolderContents($folder) {
200
+        $fileId = $this->getId($folder);
201
+        return $this->getFolderContentsById($fileId);
202
+    }
203
+
204
+    /**
205
+     * get the metadata of all files stored in $folder
206
+     *
207
+     * @param int $fileId the file id of the folder
208
+     * @return ICacheEntry[]
209
+     */
210
+    public function getFolderContentsById($fileId) {
211
+        if ($fileId > -1) {
212
+            $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`,
213 213
 						   `storage_mtime`, `encrypted`, `etag`, `permissions`, `checksum`
214 214
 					FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC';
215
-			$result = $this->connection->executeQuery($sql, [$fileId]);
216
-			$files = $result->fetchAll();
217
-			return array_map(function (array $data) {
218
-				return self::cacheEntryFromData($data, $this->mimetypeLoader);
219
-			}, $files);
220
-		}
221
-		return [];
222
-	}
223
-
224
-	/**
225
-	 * insert or update meta data for a file or folder
226
-	 *
227
-	 * @param string $file
228
-	 * @param array $data
229
-	 *
230
-	 * @return int file id
231
-	 * @throws \RuntimeException
232
-	 */
233
-	public function put($file, array $data) {
234
-		if (($id = $this->getId($file)) > -1) {
235
-			$this->update($id, $data);
236
-			return $id;
237
-		} else {
238
-			return $this->insert($file, $data);
239
-		}
240
-	}
241
-
242
-	/**
243
-	 * insert meta data for a new file or folder
244
-	 *
245
-	 * @param string $file
246
-	 * @param array $data
247
-	 *
248
-	 * @return int file id
249
-	 * @throws \RuntimeException
250
-	 *
251
-	 * @suppress SqlInjectionChecker
252
-	 */
253
-	public function insert($file, array $data) {
254
-		// normalize file
255
-		$file = $this->normalize($file);
256
-
257
-		if (isset($this->partial[$file])) { //add any saved partial data
258
-			$data = array_merge($this->partial[$file], $data);
259
-			unset($this->partial[$file]);
260
-		}
261
-
262
-		$requiredFields = array('size', 'mtime', 'mimetype');
263
-		foreach ($requiredFields as $field) {
264
-			if (!isset($data[$field])) { //data not complete save as partial and return
265
-				$this->partial[$file] = $data;
266
-				return -1;
267
-			}
268
-		}
269
-
270
-		$data['path'] = $file;
271
-		$data['parent'] = $this->getParentId($file);
272
-		$data['name'] = basename($file);
273
-
274
-		list($queryParts, $params) = $this->buildParts($data);
275
-		$queryParts[] = '`storage`';
276
-		$params[] = $this->getNumericStorageId();
277
-
278
-		$queryParts = array_map(function ($item) {
279
-			return trim($item, "`");
280
-		}, $queryParts);
281
-		$values = array_combine($queryParts, $params);
282
-
283
-		try {
284
-			$builder = $this->connection->getQueryBuilder();
285
-			$builder->insert('filecache');
286
-
287
-			foreach ($values as $column => $value) {
288
-				$builder->setValue($column, $builder->createNamedParameter($value));
289
-			}
290
-
291
-			if ($builder->execute()) {
292
-				$fileId = (int)$this->connection->lastInsertId('*PREFIX*filecache');
293
-				$this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId));
294
-				return $fileId;
295
-			}
296
-		} catch (UniqueConstraintViolationException $e) {
297
-			// entry exists already
298
-		}
299
-
300
-		// The file was created in the mean time
301
-		if (($id = $this->getId($file)) > -1) {
302
-			$this->update($id, $data);
303
-			return $id;
304
-		} else {
305
-			throw new \RuntimeException('File entry could not be inserted but could also not be selected with getId() in order to perform an update. Please try again.');
306
-		}
307
-	}
308
-
309
-	/**
310
-	 * update the metadata of an existing file or folder in the cache
311
-	 *
312
-	 * @param int $id the fileid of the existing file or folder
313
-	 * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged
314
-	 */
315
-	public function update($id, array $data) {
316
-
317
-		if (isset($data['path'])) {
318
-			// normalize path
319
-			$data['path'] = $this->normalize($data['path']);
320
-		}
321
-
322
-		if (isset($data['name'])) {
323
-			// normalize path
324
-			$data['name'] = $this->normalize($data['name']);
325
-		}
326
-
327
-		list($queryParts, $params) = $this->buildParts($data);
328
-		// duplicate $params because we need the parts twice in the SQL statement
329
-		// once for the SET part, once in the WHERE clause
330
-		$params = array_merge($params, $params);
331
-		$params[] = $id;
332
-
333
-		// don't update if the data we try to set is the same as the one in the record
334
-		// some databases (Postgres) don't like superfluous updates
335
-		$sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' .
336
-			'WHERE (' .
337
-			implode(' <> ? OR ', $queryParts) . ' <> ? OR ' .
338
-			implode(' IS NULL OR ', $queryParts) . ' IS NULL' .
339
-			') AND `fileid` = ? ';
340
-		$this->connection->executeQuery($sql, $params);
341
-
342
-		$path = $this->getPathById($id);
343
-		// path can still be null if the file doesn't exist
344
-		if ($path !== null) {
345
-			$this->eventDispatcher->dispatch(CacheUpdateEvent::class, new CacheUpdateEvent($this->storage, $path, $id));
346
-		}
347
-	}
348
-
349
-	/**
350
-	 * extract query parts and params array from data array
351
-	 *
352
-	 * @param array $data
353
-	 * @return array [$queryParts, $params]
354
-	 *        $queryParts: string[], the (escaped) column names to be set in the query
355
-	 *        $params: mixed[], the new values for the columns, to be passed as params to the query
356
-	 */
357
-	protected function buildParts(array $data) {
358
-		$fields = array(
359
-			'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted',
360
-			'etag', 'permissions', 'checksum', 'storage');
361
-
362
-		$doNotCopyStorageMTime = false;
363
-		if (array_key_exists('mtime', $data) && $data['mtime'] === null) {
364
-			// this horrific magic tells it to not copy storage_mtime to mtime
365
-			unset($data['mtime']);
366
-			$doNotCopyStorageMTime = true;
367
-		}
368
-
369
-		$params = array();
370
-		$queryParts = array();
371
-		foreach ($data as $name => $value) {
372
-			if (array_search($name, $fields) !== false) {
373
-				if ($name === 'path') {
374
-					$params[] = md5($value);
375
-					$queryParts[] = '`path_hash`';
376
-				} elseif ($name === 'mimetype') {
377
-					$params[] = $this->mimetypeLoader->getId(substr($value, 0, strpos($value, '/')));
378
-					$queryParts[] = '`mimepart`';
379
-					$value = $this->mimetypeLoader->getId($value);
380
-				} elseif ($name === 'storage_mtime') {
381
-					if (!$doNotCopyStorageMTime && !isset($data['mtime'])) {
382
-						$params[] = $value;
383
-						$queryParts[] = '`mtime`';
384
-					}
385
-				} elseif ($name === 'encrypted') {
386
-					if (isset($data['encryptedVersion'])) {
387
-						$value = $data['encryptedVersion'];
388
-					} else {
389
-						// Boolean to integer conversion
390
-						$value = $value ? 1 : 0;
391
-					}
392
-				}
393
-				$params[] = $value;
394
-				$queryParts[] = '`' . $name . '`';
395
-			}
396
-		}
397
-		return array($queryParts, $params);
398
-	}
399
-
400
-	/**
401
-	 * get the file id for a file
402
-	 *
403
-	 * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file
404
-	 *
405
-	 * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing
406
-	 *
407
-	 * @param string $file
408
-	 * @return int
409
-	 */
410
-	public function getId($file) {
411
-		// normalize file
412
-		$file = $this->normalize($file);
413
-
414
-		$pathHash = md5($file);
415
-
416
-		$sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?';
417
-		$result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash));
418
-		if ($row = $result->fetch()) {
419
-			return $row['fileid'];
420
-		} else {
421
-			return -1;
422
-		}
423
-	}
424
-
425
-	/**
426
-	 * get the id of the parent folder of a file
427
-	 *
428
-	 * @param string $file
429
-	 * @return int
430
-	 */
431
-	public function getParentId($file) {
432
-		if ($file === '') {
433
-			return -1;
434
-		} else {
435
-			$parent = $this->getParentPath($file);
436
-			return (int)$this->getId($parent);
437
-		}
438
-	}
439
-
440
-	private function getParentPath($path) {
441
-		$parent = dirname($path);
442
-		if ($parent === '.') {
443
-			$parent = '';
444
-		}
445
-		return $parent;
446
-	}
447
-
448
-	/**
449
-	 * check if a file is available in the cache
450
-	 *
451
-	 * @param string $file
452
-	 * @return bool
453
-	 */
454
-	public function inCache($file) {
455
-		return $this->getId($file) != -1;
456
-	}
457
-
458
-	/**
459
-	 * remove a file or folder from the cache
460
-	 *
461
-	 * when removing a folder from the cache all files and folders inside the folder will be removed as well
462
-	 *
463
-	 * @param string $file
464
-	 */
465
-	public function remove($file) {
466
-		$entry = $this->get($file);
467
-		$sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
468
-		$this->connection->executeQuery($sql, array($entry['fileid']));
469
-		if ($entry['mimetype'] === 'httpd/unix-directory') {
470
-			$this->removeChildren($entry);
471
-		}
472
-	}
473
-
474
-	/**
475
-	 * Get all sub folders of a folder
476
-	 *
477
-	 * @param array $entry the cache entry of the folder to get the subfolders for
478
-	 * @return array[] the cache entries for the subfolders
479
-	 */
480
-	private function getSubFolders($entry) {
481
-		$children = $this->getFolderContentsById($entry['fileid']);
482
-		return array_filter($children, function ($child) {
483
-			return $child['mimetype'] === 'httpd/unix-directory';
484
-		});
485
-	}
486
-
487
-	/**
488
-	 * Recursively remove all children of a folder
489
-	 *
490
-	 * @param array $entry the cache entry of the folder to remove the children of
491
-	 * @throws \OC\DatabaseException
492
-	 */
493
-	private function removeChildren($entry) {
494
-		$subFolders = $this->getSubFolders($entry);
495
-		foreach ($subFolders as $folder) {
496
-			$this->removeChildren($folder);
497
-		}
498
-		$sql = 'DELETE FROM `*PREFIX*filecache` WHERE `parent` = ?';
499
-		$this->connection->executeQuery($sql, array($entry['fileid']));
500
-	}
501
-
502
-	/**
503
-	 * Move a file or folder in the cache
504
-	 *
505
-	 * @param string $source
506
-	 * @param string $target
507
-	 */
508
-	public function move($source, $target) {
509
-		$this->moveFromCache($this, $source, $target);
510
-	}
511
-
512
-	/**
513
-	 * Get the storage id and path needed for a move
514
-	 *
515
-	 * @param string $path
516
-	 * @return array [$storageId, $internalPath]
517
-	 */
518
-	protected function getMoveInfo($path) {
519
-		return [$this->getNumericStorageId(), $path];
520
-	}
521
-
522
-	/**
523
-	 * Move a file or folder in the cache
524
-	 *
525
-	 * @param \OCP\Files\Cache\ICache $sourceCache
526
-	 * @param string $sourcePath
527
-	 * @param string $targetPath
528
-	 * @throws \OC\DatabaseException
529
-	 * @throws \Exception if the given storages have an invalid id
530
-	 * @suppress SqlInjectionChecker
531
-	 */
532
-	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
533
-		if ($sourceCache instanceof Cache) {
534
-			// normalize source and target
535
-			$sourcePath = $this->normalize($sourcePath);
536
-			$targetPath = $this->normalize($targetPath);
537
-
538
-			$sourceData = $sourceCache->get($sourcePath);
539
-			$sourceId = $sourceData['fileid'];
540
-			$newParentId = $this->getParentId($targetPath);
541
-
542
-			list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath);
543
-			list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath);
544
-
545
-			if (is_null($sourceStorageId) || $sourceStorageId === false) {
546
-				throw new \Exception('Invalid source storage id: ' . $sourceStorageId);
547
-			}
548
-			if (is_null($targetStorageId) || $targetStorageId === false) {
549
-				throw new \Exception('Invalid target storage id: ' . $targetStorageId);
550
-			}
551
-
552
-			$this->connection->beginTransaction();
553
-			if ($sourceData['mimetype'] === 'httpd/unix-directory') {
554
-				//update all child entries
555
-				$sourceLength = mb_strlen($sourcePath);
556
-				$query = $this->connection->getQueryBuilder();
557
-
558
-				$fun = $query->func();
559
-				$newPathFunction = $fun->concat(
560
-					$query->createNamedParameter($targetPath),
561
-					$fun->substring('path', $query->createNamedParameter($sourceLength + 1, IQueryBuilder::PARAM_INT))// +1 for the leading slash
562
-				);
563
-				$query->update('filecache')
564
-					->set('storage', $query->createNamedParameter($targetStorageId, IQueryBuilder::PARAM_INT))
565
-					->set('path_hash', $fun->md5($newPathFunction))
566
-					->set('path', $newPathFunction)
567
-					->where($query->expr()->eq('storage', $query->createNamedParameter($sourceStorageId, IQueryBuilder::PARAM_INT)))
568
-					->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($sourcePath) . '/%')));
569
-
570
-				try {
571
-					$query->execute();
572
-				} catch (\OC\DatabaseException $e) {
573
-					$this->connection->rollBack();
574
-					throw $e;
575
-				}
576
-			}
577
-
578
-			$sql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` = ? WHERE `fileid` = ?';
579
-			$this->connection->executeQuery($sql, array($targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId));
580
-			$this->connection->commit();
581
-		} else {
582
-			$this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath);
583
-		}
584
-	}
585
-
586
-	/**
587
-	 * remove all entries for files that are stored on the storage from the cache
588
-	 */
589
-	public function clear() {
590
-		$sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?';
591
-		$this->connection->executeQuery($sql, array($this->getNumericStorageId()));
592
-
593
-		$sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?';
594
-		$this->connection->executeQuery($sql, array($this->storageId));
595
-	}
596
-
597
-	/**
598
-	 * Get the scan status of a file
599
-	 *
600
-	 * - Cache::NOT_FOUND: File is not in the cache
601
-	 * - Cache::PARTIAL: File is not stored in the cache but some incomplete data is known
602
-	 * - Cache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned
603
-	 * - Cache::COMPLETE: The file or folder, with all it's children) are fully scanned
604
-	 *
605
-	 * @param string $file
606
-	 *
607
-	 * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
608
-	 */
609
-	public function getStatus($file) {
610
-		// normalize file
611
-		$file = $this->normalize($file);
612
-
613
-		$pathHash = md5($file);
614
-		$sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?';
615
-		$result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash));
616
-		if ($row = $result->fetch()) {
617
-			if ((int)$row['size'] === -1) {
618
-				return self::SHALLOW;
619
-			} else {
620
-				return self::COMPLETE;
621
-			}
622
-		} else {
623
-			if (isset($this->partial[$file])) {
624
-				return self::PARTIAL;
625
-			} else {
626
-				return self::NOT_FOUND;
627
-			}
628
-		}
629
-	}
630
-
631
-	/**
632
-	 * search for files matching $pattern
633
-	 *
634
-	 * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%')
635
-	 * @return ICacheEntry[] an array of cache entries where the name matches the search pattern
636
-	 */
637
-	public function search($pattern) {
638
-		// normalize pattern
639
-		$pattern = $this->normalize($pattern);
640
-
641
-		if ($pattern === '%%') {
642
-			return [];
643
-		}
644
-
645
-
646
-		$sql = '
215
+            $result = $this->connection->executeQuery($sql, [$fileId]);
216
+            $files = $result->fetchAll();
217
+            return array_map(function (array $data) {
218
+                return self::cacheEntryFromData($data, $this->mimetypeLoader);
219
+            }, $files);
220
+        }
221
+        return [];
222
+    }
223
+
224
+    /**
225
+     * insert or update meta data for a file or folder
226
+     *
227
+     * @param string $file
228
+     * @param array $data
229
+     *
230
+     * @return int file id
231
+     * @throws \RuntimeException
232
+     */
233
+    public function put($file, array $data) {
234
+        if (($id = $this->getId($file)) > -1) {
235
+            $this->update($id, $data);
236
+            return $id;
237
+        } else {
238
+            return $this->insert($file, $data);
239
+        }
240
+    }
241
+
242
+    /**
243
+     * insert meta data for a new file or folder
244
+     *
245
+     * @param string $file
246
+     * @param array $data
247
+     *
248
+     * @return int file id
249
+     * @throws \RuntimeException
250
+     *
251
+     * @suppress SqlInjectionChecker
252
+     */
253
+    public function insert($file, array $data) {
254
+        // normalize file
255
+        $file = $this->normalize($file);
256
+
257
+        if (isset($this->partial[$file])) { //add any saved partial data
258
+            $data = array_merge($this->partial[$file], $data);
259
+            unset($this->partial[$file]);
260
+        }
261
+
262
+        $requiredFields = array('size', 'mtime', 'mimetype');
263
+        foreach ($requiredFields as $field) {
264
+            if (!isset($data[$field])) { //data not complete save as partial and return
265
+                $this->partial[$file] = $data;
266
+                return -1;
267
+            }
268
+        }
269
+
270
+        $data['path'] = $file;
271
+        $data['parent'] = $this->getParentId($file);
272
+        $data['name'] = basename($file);
273
+
274
+        list($queryParts, $params) = $this->buildParts($data);
275
+        $queryParts[] = '`storage`';
276
+        $params[] = $this->getNumericStorageId();
277
+
278
+        $queryParts = array_map(function ($item) {
279
+            return trim($item, "`");
280
+        }, $queryParts);
281
+        $values = array_combine($queryParts, $params);
282
+
283
+        try {
284
+            $builder = $this->connection->getQueryBuilder();
285
+            $builder->insert('filecache');
286
+
287
+            foreach ($values as $column => $value) {
288
+                $builder->setValue($column, $builder->createNamedParameter($value));
289
+            }
290
+
291
+            if ($builder->execute()) {
292
+                $fileId = (int)$this->connection->lastInsertId('*PREFIX*filecache');
293
+                $this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId));
294
+                return $fileId;
295
+            }
296
+        } catch (UniqueConstraintViolationException $e) {
297
+            // entry exists already
298
+        }
299
+
300
+        // The file was created in the mean time
301
+        if (($id = $this->getId($file)) > -1) {
302
+            $this->update($id, $data);
303
+            return $id;
304
+        } else {
305
+            throw new \RuntimeException('File entry could not be inserted but could also not be selected with getId() in order to perform an update. Please try again.');
306
+        }
307
+    }
308
+
309
+    /**
310
+     * update the metadata of an existing file or folder in the cache
311
+     *
312
+     * @param int $id the fileid of the existing file or folder
313
+     * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged
314
+     */
315
+    public function update($id, array $data) {
316
+
317
+        if (isset($data['path'])) {
318
+            // normalize path
319
+            $data['path'] = $this->normalize($data['path']);
320
+        }
321
+
322
+        if (isset($data['name'])) {
323
+            // normalize path
324
+            $data['name'] = $this->normalize($data['name']);
325
+        }
326
+
327
+        list($queryParts, $params) = $this->buildParts($data);
328
+        // duplicate $params because we need the parts twice in the SQL statement
329
+        // once for the SET part, once in the WHERE clause
330
+        $params = array_merge($params, $params);
331
+        $params[] = $id;
332
+
333
+        // don't update if the data we try to set is the same as the one in the record
334
+        // some databases (Postgres) don't like superfluous updates
335
+        $sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' .
336
+            'WHERE (' .
337
+            implode(' <> ? OR ', $queryParts) . ' <> ? OR ' .
338
+            implode(' IS NULL OR ', $queryParts) . ' IS NULL' .
339
+            ') AND `fileid` = ? ';
340
+        $this->connection->executeQuery($sql, $params);
341
+
342
+        $path = $this->getPathById($id);
343
+        // path can still be null if the file doesn't exist
344
+        if ($path !== null) {
345
+            $this->eventDispatcher->dispatch(CacheUpdateEvent::class, new CacheUpdateEvent($this->storage, $path, $id));
346
+        }
347
+    }
348
+
349
+    /**
350
+     * extract query parts and params array from data array
351
+     *
352
+     * @param array $data
353
+     * @return array [$queryParts, $params]
354
+     *        $queryParts: string[], the (escaped) column names to be set in the query
355
+     *        $params: mixed[], the new values for the columns, to be passed as params to the query
356
+     */
357
+    protected function buildParts(array $data) {
358
+        $fields = array(
359
+            'path', 'parent', 'name', 'mimetype', 'size', 'mtime', 'storage_mtime', 'encrypted',
360
+            'etag', 'permissions', 'checksum', 'storage');
361
+
362
+        $doNotCopyStorageMTime = false;
363
+        if (array_key_exists('mtime', $data) && $data['mtime'] === null) {
364
+            // this horrific magic tells it to not copy storage_mtime to mtime
365
+            unset($data['mtime']);
366
+            $doNotCopyStorageMTime = true;
367
+        }
368
+
369
+        $params = array();
370
+        $queryParts = array();
371
+        foreach ($data as $name => $value) {
372
+            if (array_search($name, $fields) !== false) {
373
+                if ($name === 'path') {
374
+                    $params[] = md5($value);
375
+                    $queryParts[] = '`path_hash`';
376
+                } elseif ($name === 'mimetype') {
377
+                    $params[] = $this->mimetypeLoader->getId(substr($value, 0, strpos($value, '/')));
378
+                    $queryParts[] = '`mimepart`';
379
+                    $value = $this->mimetypeLoader->getId($value);
380
+                } elseif ($name === 'storage_mtime') {
381
+                    if (!$doNotCopyStorageMTime && !isset($data['mtime'])) {
382
+                        $params[] = $value;
383
+                        $queryParts[] = '`mtime`';
384
+                    }
385
+                } elseif ($name === 'encrypted') {
386
+                    if (isset($data['encryptedVersion'])) {
387
+                        $value = $data['encryptedVersion'];
388
+                    } else {
389
+                        // Boolean to integer conversion
390
+                        $value = $value ? 1 : 0;
391
+                    }
392
+                }
393
+                $params[] = $value;
394
+                $queryParts[] = '`' . $name . '`';
395
+            }
396
+        }
397
+        return array($queryParts, $params);
398
+    }
399
+
400
+    /**
401
+     * get the file id for a file
402
+     *
403
+     * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file
404
+     *
405
+     * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing
406
+     *
407
+     * @param string $file
408
+     * @return int
409
+     */
410
+    public function getId($file) {
411
+        // normalize file
412
+        $file = $this->normalize($file);
413
+
414
+        $pathHash = md5($file);
415
+
416
+        $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?';
417
+        $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash));
418
+        if ($row = $result->fetch()) {
419
+            return $row['fileid'];
420
+        } else {
421
+            return -1;
422
+        }
423
+    }
424
+
425
+    /**
426
+     * get the id of the parent folder of a file
427
+     *
428
+     * @param string $file
429
+     * @return int
430
+     */
431
+    public function getParentId($file) {
432
+        if ($file === '') {
433
+            return -1;
434
+        } else {
435
+            $parent = $this->getParentPath($file);
436
+            return (int)$this->getId($parent);
437
+        }
438
+    }
439
+
440
+    private function getParentPath($path) {
441
+        $parent = dirname($path);
442
+        if ($parent === '.') {
443
+            $parent = '';
444
+        }
445
+        return $parent;
446
+    }
447
+
448
+    /**
449
+     * check if a file is available in the cache
450
+     *
451
+     * @param string $file
452
+     * @return bool
453
+     */
454
+    public function inCache($file) {
455
+        return $this->getId($file) != -1;
456
+    }
457
+
458
+    /**
459
+     * remove a file or folder from the cache
460
+     *
461
+     * when removing a folder from the cache all files and folders inside the folder will be removed as well
462
+     *
463
+     * @param string $file
464
+     */
465
+    public function remove($file) {
466
+        $entry = $this->get($file);
467
+        $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `fileid` = ?';
468
+        $this->connection->executeQuery($sql, array($entry['fileid']));
469
+        if ($entry['mimetype'] === 'httpd/unix-directory') {
470
+            $this->removeChildren($entry);
471
+        }
472
+    }
473
+
474
+    /**
475
+     * Get all sub folders of a folder
476
+     *
477
+     * @param array $entry the cache entry of the folder to get the subfolders for
478
+     * @return array[] the cache entries for the subfolders
479
+     */
480
+    private function getSubFolders($entry) {
481
+        $children = $this->getFolderContentsById($entry['fileid']);
482
+        return array_filter($children, function ($child) {
483
+            return $child['mimetype'] === 'httpd/unix-directory';
484
+        });
485
+    }
486
+
487
+    /**
488
+     * Recursively remove all children of a folder
489
+     *
490
+     * @param array $entry the cache entry of the folder to remove the children of
491
+     * @throws \OC\DatabaseException
492
+     */
493
+    private function removeChildren($entry) {
494
+        $subFolders = $this->getSubFolders($entry);
495
+        foreach ($subFolders as $folder) {
496
+            $this->removeChildren($folder);
497
+        }
498
+        $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `parent` = ?';
499
+        $this->connection->executeQuery($sql, array($entry['fileid']));
500
+    }
501
+
502
+    /**
503
+     * Move a file or folder in the cache
504
+     *
505
+     * @param string $source
506
+     * @param string $target
507
+     */
508
+    public function move($source, $target) {
509
+        $this->moveFromCache($this, $source, $target);
510
+    }
511
+
512
+    /**
513
+     * Get the storage id and path needed for a move
514
+     *
515
+     * @param string $path
516
+     * @return array [$storageId, $internalPath]
517
+     */
518
+    protected function getMoveInfo($path) {
519
+        return [$this->getNumericStorageId(), $path];
520
+    }
521
+
522
+    /**
523
+     * Move a file or folder in the cache
524
+     *
525
+     * @param \OCP\Files\Cache\ICache $sourceCache
526
+     * @param string $sourcePath
527
+     * @param string $targetPath
528
+     * @throws \OC\DatabaseException
529
+     * @throws \Exception if the given storages have an invalid id
530
+     * @suppress SqlInjectionChecker
531
+     */
532
+    public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
533
+        if ($sourceCache instanceof Cache) {
534
+            // normalize source and target
535
+            $sourcePath = $this->normalize($sourcePath);
536
+            $targetPath = $this->normalize($targetPath);
537
+
538
+            $sourceData = $sourceCache->get($sourcePath);
539
+            $sourceId = $sourceData['fileid'];
540
+            $newParentId = $this->getParentId($targetPath);
541
+
542
+            list($sourceStorageId, $sourcePath) = $sourceCache->getMoveInfo($sourcePath);
543
+            list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath);
544
+
545
+            if (is_null($sourceStorageId) || $sourceStorageId === false) {
546
+                throw new \Exception('Invalid source storage id: ' . $sourceStorageId);
547
+            }
548
+            if (is_null($targetStorageId) || $targetStorageId === false) {
549
+                throw new \Exception('Invalid target storage id: ' . $targetStorageId);
550
+            }
551
+
552
+            $this->connection->beginTransaction();
553
+            if ($sourceData['mimetype'] === 'httpd/unix-directory') {
554
+                //update all child entries
555
+                $sourceLength = mb_strlen($sourcePath);
556
+                $query = $this->connection->getQueryBuilder();
557
+
558
+                $fun = $query->func();
559
+                $newPathFunction = $fun->concat(
560
+                    $query->createNamedParameter($targetPath),
561
+                    $fun->substring('path', $query->createNamedParameter($sourceLength + 1, IQueryBuilder::PARAM_INT))// +1 for the leading slash
562
+                );
563
+                $query->update('filecache')
564
+                    ->set('storage', $query->createNamedParameter($targetStorageId, IQueryBuilder::PARAM_INT))
565
+                    ->set('path_hash', $fun->md5($newPathFunction))
566
+                    ->set('path', $newPathFunction)
567
+                    ->where($query->expr()->eq('storage', $query->createNamedParameter($sourceStorageId, IQueryBuilder::PARAM_INT)))
568
+                    ->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($sourcePath) . '/%')));
569
+
570
+                try {
571
+                    $query->execute();
572
+                } catch (\OC\DatabaseException $e) {
573
+                    $this->connection->rollBack();
574
+                    throw $e;
575
+                }
576
+            }
577
+
578
+            $sql = 'UPDATE `*PREFIX*filecache` SET `storage` = ?, `path` = ?, `path_hash` = ?, `name` = ?, `parent` = ? WHERE `fileid` = ?';
579
+            $this->connection->executeQuery($sql, array($targetStorageId, $targetPath, md5($targetPath), basename($targetPath), $newParentId, $sourceId));
580
+            $this->connection->commit();
581
+        } else {
582
+            $this->moveFromCacheFallback($sourceCache, $sourcePath, $targetPath);
583
+        }
584
+    }
585
+
586
+    /**
587
+     * remove all entries for files that are stored on the storage from the cache
588
+     */
589
+    public function clear() {
590
+        $sql = 'DELETE FROM `*PREFIX*filecache` WHERE `storage` = ?';
591
+        $this->connection->executeQuery($sql, array($this->getNumericStorageId()));
592
+
593
+        $sql = 'DELETE FROM `*PREFIX*storages` WHERE `id` = ?';
594
+        $this->connection->executeQuery($sql, array($this->storageId));
595
+    }
596
+
597
+    /**
598
+     * Get the scan status of a file
599
+     *
600
+     * - Cache::NOT_FOUND: File is not in the cache
601
+     * - Cache::PARTIAL: File is not stored in the cache but some incomplete data is known
602
+     * - Cache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned
603
+     * - Cache::COMPLETE: The file or folder, with all it's children) are fully scanned
604
+     *
605
+     * @param string $file
606
+     *
607
+     * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
608
+     */
609
+    public function getStatus($file) {
610
+        // normalize file
611
+        $file = $this->normalize($file);
612
+
613
+        $pathHash = md5($file);
614
+        $sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?';
615
+        $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash));
616
+        if ($row = $result->fetch()) {
617
+            if ((int)$row['size'] === -1) {
618
+                return self::SHALLOW;
619
+            } else {
620
+                return self::COMPLETE;
621
+            }
622
+        } else {
623
+            if (isset($this->partial[$file])) {
624
+                return self::PARTIAL;
625
+            } else {
626
+                return self::NOT_FOUND;
627
+            }
628
+        }
629
+    }
630
+
631
+    /**
632
+     * search for files matching $pattern
633
+     *
634
+     * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%')
635
+     * @return ICacheEntry[] an array of cache entries where the name matches the search pattern
636
+     */
637
+    public function search($pattern) {
638
+        // normalize pattern
639
+        $pattern = $this->normalize($pattern);
640
+
641
+        if ($pattern === '%%') {
642
+            return [];
643
+        }
644
+
645
+
646
+        $sql = '
647 647
 			SELECT `fileid`, `storage`, `path`, `parent`, `name`,
648 648
 				`mimetype`, `storage_mtime`, `mimepart`, `size`, `mtime`,
649 649
 				 `encrypted`, `etag`, `permissions`, `checksum`
650 650
 			FROM `*PREFIX*filecache`
651 651
 			WHERE `storage` = ? AND `name` ILIKE ?';
652
-		$result = $this->connection->executeQuery($sql,
653
-			[$this->getNumericStorageId(), $pattern]
654
-		);
655
-
656
-		return $this->searchResultToCacheEntries($result);
657
-	}
658
-
659
-	/**
660
-	 * @param Statement $result
661
-	 * @return CacheEntry[]
662
-	 */
663
-	private function searchResultToCacheEntries(Statement $result) {
664
-		$files = $result->fetchAll();
665
-
666
-		return array_map(function (array $data) {
667
-			return self::cacheEntryFromData($data, $this->mimetypeLoader);
668
-		}, $files);
669
-	}
670
-
671
-	/**
672
-	 * search for files by mimetype
673
-	 *
674
-	 * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image')
675
-	 *        where it will search for all mimetypes in the group ('image/*')
676
-	 * @return ICacheEntry[] an array of cache entries where the mimetype matches the search
677
-	 */
678
-	public function searchByMime($mimetype) {
679
-		if (strpos($mimetype, '/')) {
680
-			$where = '`mimetype` = ?';
681
-		} else {
682
-			$where = '`mimepart` = ?';
683
-		}
684
-		$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `storage_mtime`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum`
652
+        $result = $this->connection->executeQuery($sql,
653
+            [$this->getNumericStorageId(), $pattern]
654
+        );
655
+
656
+        return $this->searchResultToCacheEntries($result);
657
+    }
658
+
659
+    /**
660
+     * @param Statement $result
661
+     * @return CacheEntry[]
662
+     */
663
+    private function searchResultToCacheEntries(Statement $result) {
664
+        $files = $result->fetchAll();
665
+
666
+        return array_map(function (array $data) {
667
+            return self::cacheEntryFromData($data, $this->mimetypeLoader);
668
+        }, $files);
669
+    }
670
+
671
+    /**
672
+     * search for files by mimetype
673
+     *
674
+     * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image')
675
+     *        where it will search for all mimetypes in the group ('image/*')
676
+     * @return ICacheEntry[] an array of cache entries where the mimetype matches the search
677
+     */
678
+    public function searchByMime($mimetype) {
679
+        if (strpos($mimetype, '/')) {
680
+            $where = '`mimetype` = ?';
681
+        } else {
682
+            $where = '`mimepart` = ?';
683
+        }
684
+        $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `storage_mtime`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum`
685 685
 				FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?';
686
-		$mimetype = $this->mimetypeLoader->getId($mimetype);
687
-		$result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId()));
688
-
689
-		return $this->searchResultToCacheEntries($result);
690
-	}
691
-
692
-	public function searchQuery(ISearchQuery $searchQuery) {
693
-		$builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
694
-
695
-		$query = $builder->select(['fileid', 'storage', 'path', 'parent', 'name', 'mimetype', 'mimepart', 'size', 'mtime', 'storage_mtime', 'encrypted', 'etag', 'permissions', 'checksum'])
696
-			->from('filecache', 'file');
697
-
698
-		$query->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->getNumericStorageId())));
699
-
700
-		if ($this->querySearchHelper->shouldJoinTags($searchQuery->getSearchOperation())) {
701
-			$query
702
-				->innerJoin('file', 'vcategory_to_object', 'tagmap', $builder->expr()->eq('file.fileid', 'tagmap.objid'))
703
-				->innerJoin('tagmap', 'vcategory', 'tag', $builder->expr()->andX(
704
-					$builder->expr()->eq('tagmap.type', 'tag.type'),
705
-					$builder->expr()->eq('tagmap.categoryid', 'tag.id')
706
-				))
707
-				->andWhere($builder->expr()->eq('tag.type', $builder->createNamedParameter('files')))
708
-				->andWhere($builder->expr()->eq('tag.uid', $builder->createNamedParameter($searchQuery->getUser()->getUID())));
709
-		}
710
-
711
-		$query->andWhere($this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation()));
712
-
713
-		$this->querySearchHelper->addSearchOrdersToQuery($query, $searchQuery->getOrder());
714
-
715
-		if ($searchQuery->getLimit()) {
716
-			$query->setMaxResults($searchQuery->getLimit());
717
-		}
718
-		if ($searchQuery->getOffset()) {
719
-			$query->setFirstResult($searchQuery->getOffset());
720
-		}
721
-
722
-		$result = $query->execute();
723
-		return $this->searchResultToCacheEntries($result);
724
-	}
725
-
726
-	/**
727
-	 * Re-calculate the folder size and the size of all parent folders
728
-	 *
729
-	 * @param string|boolean $path
730
-	 * @param array $data (optional) meta data of the folder
731
-	 */
732
-	public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {
733
-		$this->calculateFolderSize($path, $data);
734
-		if ($path !== '') {
735
-			$parent = dirname($path);
736
-			if ($parent === '.' or $parent === '/') {
737
-				$parent = '';
738
-			}
739
-			if ($isBackgroundScan) {
740
-				$parentData = $this->get($parent);
741
-				if ($parentData['size'] !== -1 && $this->getIncompleteChildrenCount($parentData['fileid']) === 0) {
742
-					$this->correctFolderSize($parent, $parentData, $isBackgroundScan);
743
-				}
744
-			} else {
745
-				$this->correctFolderSize($parent);
746
-			}
747
-		}
748
-	}
749
-
750
-	/**
751
-	 * get the incomplete count that shares parent $folder
752
-	 *
753
-	 * @param int $fileId the file id of the folder
754
-	 * @return int
755
-	 */
756
-	public function getIncompleteChildrenCount($fileId) {
757
-		if ($fileId > -1) {
758
-			$sql = 'SELECT count(*)
686
+        $mimetype = $this->mimetypeLoader->getId($mimetype);
687
+        $result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId()));
688
+
689
+        return $this->searchResultToCacheEntries($result);
690
+    }
691
+
692
+    public function searchQuery(ISearchQuery $searchQuery) {
693
+        $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
694
+
695
+        $query = $builder->select(['fileid', 'storage', 'path', 'parent', 'name', 'mimetype', 'mimepart', 'size', 'mtime', 'storage_mtime', 'encrypted', 'etag', 'permissions', 'checksum'])
696
+            ->from('filecache', 'file');
697
+
698
+        $query->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->getNumericStorageId())));
699
+
700
+        if ($this->querySearchHelper->shouldJoinTags($searchQuery->getSearchOperation())) {
701
+            $query
702
+                ->innerJoin('file', 'vcategory_to_object', 'tagmap', $builder->expr()->eq('file.fileid', 'tagmap.objid'))
703
+                ->innerJoin('tagmap', 'vcategory', 'tag', $builder->expr()->andX(
704
+                    $builder->expr()->eq('tagmap.type', 'tag.type'),
705
+                    $builder->expr()->eq('tagmap.categoryid', 'tag.id')
706
+                ))
707
+                ->andWhere($builder->expr()->eq('tag.type', $builder->createNamedParameter('files')))
708
+                ->andWhere($builder->expr()->eq('tag.uid', $builder->createNamedParameter($searchQuery->getUser()->getUID())));
709
+        }
710
+
711
+        $query->andWhere($this->querySearchHelper->searchOperatorToDBExpr($builder, $searchQuery->getSearchOperation()));
712
+
713
+        $this->querySearchHelper->addSearchOrdersToQuery($query, $searchQuery->getOrder());
714
+
715
+        if ($searchQuery->getLimit()) {
716
+            $query->setMaxResults($searchQuery->getLimit());
717
+        }
718
+        if ($searchQuery->getOffset()) {
719
+            $query->setFirstResult($searchQuery->getOffset());
720
+        }
721
+
722
+        $result = $query->execute();
723
+        return $this->searchResultToCacheEntries($result);
724
+    }
725
+
726
+    /**
727
+     * Re-calculate the folder size and the size of all parent folders
728
+     *
729
+     * @param string|boolean $path
730
+     * @param array $data (optional) meta data of the folder
731
+     */
732
+    public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {
733
+        $this->calculateFolderSize($path, $data);
734
+        if ($path !== '') {
735
+            $parent = dirname($path);
736
+            if ($parent === '.' or $parent === '/') {
737
+                $parent = '';
738
+            }
739
+            if ($isBackgroundScan) {
740
+                $parentData = $this->get($parent);
741
+                if ($parentData['size'] !== -1 && $this->getIncompleteChildrenCount($parentData['fileid']) === 0) {
742
+                    $this->correctFolderSize($parent, $parentData, $isBackgroundScan);
743
+                }
744
+            } else {
745
+                $this->correctFolderSize($parent);
746
+            }
747
+        }
748
+    }
749
+
750
+    /**
751
+     * get the incomplete count that shares parent $folder
752
+     *
753
+     * @param int $fileId the file id of the folder
754
+     * @return int
755
+     */
756
+    public function getIncompleteChildrenCount($fileId) {
757
+        if ($fileId > -1) {
758
+            $sql = 'SELECT count(*)
759 759
 					FROM `*PREFIX*filecache` WHERE `parent` = ? AND size = -1';
760
-			$result = $this->connection->executeQuery($sql, [$fileId]);
761
-			return (int)$result->fetchColumn();
762
-		}
763
-		return -1;
764
-	}
765
-
766
-	/**
767
-	 * calculate the size of a folder and set it in the cache
768
-	 *
769
-	 * @param string $path
770
-	 * @param array $entry (optional) meta data of the folder
771
-	 * @return int
772
-	 */
773
-	public function calculateFolderSize($path, $entry = null) {
774
-		$totalSize = 0;
775
-		if (is_null($entry) or !isset($entry['fileid'])) {
776
-			$entry = $this->get($path);
777
-		}
778
-		if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') {
779
-			$id = $entry['fileid'];
780
-			$sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' .
781
-				'FROM `*PREFIX*filecache` ' .
782
-				'WHERE `parent` = ? AND `storage` = ?';
783
-			$result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId()));
784
-			if ($row = $result->fetch()) {
785
-				$result->closeCursor();
786
-				list($sum, $min) = array_values($row);
787
-				$sum = 0 + $sum;
788
-				$min = 0 + $min;
789
-				if ($min === -1) {
790
-					$totalSize = $min;
791
-				} else {
792
-					$totalSize = $sum;
793
-				}
794
-				$update = array();
795
-				if ($entry['size'] !== $totalSize) {
796
-					$update['size'] = $totalSize;
797
-				}
798
-				if (count($update) > 0) {
799
-					$this->update($id, $update);
800
-				}
801
-			} else {
802
-				$result->closeCursor();
803
-			}
804
-		}
805
-		return $totalSize;
806
-	}
807
-
808
-	/**
809
-	 * get all file ids on the files on the storage
810
-	 *
811
-	 * @return int[]
812
-	 */
813
-	public function getAll() {
814
-		$sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?';
815
-		$result = $this->connection->executeQuery($sql, array($this->getNumericStorageId()));
816
-		$ids = array();
817
-		while ($row = $result->fetch()) {
818
-			$ids[] = $row['fileid'];
819
-		}
820
-		return $ids;
821
-	}
822
-
823
-	/**
824
-	 * find a folder in the cache which has not been fully scanned
825
-	 *
826
-	 * If multiple incomplete folders are in the cache, the one with the highest id will be returned,
827
-	 * use the one with the highest id gives the best result with the background scanner, since that is most
828
-	 * likely the folder where we stopped scanning previously
829
-	 *
830
-	 * @return string|bool the path of the folder or false when no folder matched
831
-	 */
832
-	public function getIncomplete() {
833
-		$query = $this->connection->prepare('SELECT `path` FROM `*PREFIX*filecache`'
834
-			. ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC', 1);
835
-		$query->execute([$this->getNumericStorageId()]);
836
-		if ($row = $query->fetch()) {
837
-			return $row['path'];
838
-		} else {
839
-			return false;
840
-		}
841
-	}
842
-
843
-	/**
844
-	 * get the path of a file on this storage by it's file id
845
-	 *
846
-	 * @param int $id the file id of the file or folder to search
847
-	 * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache
848
-	 */
849
-	public function getPathById($id) {
850
-		$sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ? AND `storage` = ?';
851
-		$result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId()));
852
-		if ($row = $result->fetch()) {
853
-			// Oracle stores empty strings as null...
854
-			if ($row['path'] === null) {
855
-				return '';
856
-			}
857
-			return $row['path'];
858
-		} else {
859
-			return null;
860
-		}
861
-	}
862
-
863
-	/**
864
-	 * get the storage id of the storage for a file and the internal path of the file
865
-	 * unlike getPathById this does not limit the search to files on this storage and
866
-	 * instead does a global search in the cache table
867
-	 *
868
-	 * @param int $id
869
-	 * @deprecated use getPathById() instead
870
-	 * @return array first element holding the storage id, second the path
871
-	 */
872
-	static public function getById($id) {
873
-		$connection = \OC::$server->getDatabaseConnection();
874
-		$sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?';
875
-		$result = $connection->executeQuery($sql, array($id));
876
-		if ($row = $result->fetch()) {
877
-			$numericId = $row['storage'];
878
-			$path = $row['path'];
879
-		} else {
880
-			return null;
881
-		}
882
-
883
-		if ($id = Storage::getStorageId($numericId)) {
884
-			return array($id, $path);
885
-		} else {
886
-			return null;
887
-		}
888
-	}
889
-
890
-	/**
891
-	 * normalize the given path
892
-	 *
893
-	 * @param string $path
894
-	 * @return string
895
-	 */
896
-	public function normalize($path) {
897
-
898
-		return trim(\OC_Util::normalizeUnicode($path), '/');
899
-	}
760
+            $result = $this->connection->executeQuery($sql, [$fileId]);
761
+            return (int)$result->fetchColumn();
762
+        }
763
+        return -1;
764
+    }
765
+
766
+    /**
767
+     * calculate the size of a folder and set it in the cache
768
+     *
769
+     * @param string $path
770
+     * @param array $entry (optional) meta data of the folder
771
+     * @return int
772
+     */
773
+    public function calculateFolderSize($path, $entry = null) {
774
+        $totalSize = 0;
775
+        if (is_null($entry) or !isset($entry['fileid'])) {
776
+            $entry = $this->get($path);
777
+        }
778
+        if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') {
779
+            $id = $entry['fileid'];
780
+            $sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' .
781
+                'FROM `*PREFIX*filecache` ' .
782
+                'WHERE `parent` = ? AND `storage` = ?';
783
+            $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId()));
784
+            if ($row = $result->fetch()) {
785
+                $result->closeCursor();
786
+                list($sum, $min) = array_values($row);
787
+                $sum = 0 + $sum;
788
+                $min = 0 + $min;
789
+                if ($min === -1) {
790
+                    $totalSize = $min;
791
+                } else {
792
+                    $totalSize = $sum;
793
+                }
794
+                $update = array();
795
+                if ($entry['size'] !== $totalSize) {
796
+                    $update['size'] = $totalSize;
797
+                }
798
+                if (count($update) > 0) {
799
+                    $this->update($id, $update);
800
+                }
801
+            } else {
802
+                $result->closeCursor();
803
+            }
804
+        }
805
+        return $totalSize;
806
+    }
807
+
808
+    /**
809
+     * get all file ids on the files on the storage
810
+     *
811
+     * @return int[]
812
+     */
813
+    public function getAll() {
814
+        $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ?';
815
+        $result = $this->connection->executeQuery($sql, array($this->getNumericStorageId()));
816
+        $ids = array();
817
+        while ($row = $result->fetch()) {
818
+            $ids[] = $row['fileid'];
819
+        }
820
+        return $ids;
821
+    }
822
+
823
+    /**
824
+     * find a folder in the cache which has not been fully scanned
825
+     *
826
+     * If multiple incomplete folders are in the cache, the one with the highest id will be returned,
827
+     * use the one with the highest id gives the best result with the background scanner, since that is most
828
+     * likely the folder where we stopped scanning previously
829
+     *
830
+     * @return string|bool the path of the folder or false when no folder matched
831
+     */
832
+    public function getIncomplete() {
833
+        $query = $this->connection->prepare('SELECT `path` FROM `*PREFIX*filecache`'
834
+            . ' WHERE `storage` = ? AND `size` = -1 ORDER BY `fileid` DESC', 1);
835
+        $query->execute([$this->getNumericStorageId()]);
836
+        if ($row = $query->fetch()) {
837
+            return $row['path'];
838
+        } else {
839
+            return false;
840
+        }
841
+    }
842
+
843
+    /**
844
+     * get the path of a file on this storage by it's file id
845
+     *
846
+     * @param int $id the file id of the file or folder to search
847
+     * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache
848
+     */
849
+    public function getPathById($id) {
850
+        $sql = 'SELECT `path` FROM `*PREFIX*filecache` WHERE `fileid` = ? AND `storage` = ?';
851
+        $result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId()));
852
+        if ($row = $result->fetch()) {
853
+            // Oracle stores empty strings as null...
854
+            if ($row['path'] === null) {
855
+                return '';
856
+            }
857
+            return $row['path'];
858
+        } else {
859
+            return null;
860
+        }
861
+    }
862
+
863
+    /**
864
+     * get the storage id of the storage for a file and the internal path of the file
865
+     * unlike getPathById this does not limit the search to files on this storage and
866
+     * instead does a global search in the cache table
867
+     *
868
+     * @param int $id
869
+     * @deprecated use getPathById() instead
870
+     * @return array first element holding the storage id, second the path
871
+     */
872
+    static public function getById($id) {
873
+        $connection = \OC::$server->getDatabaseConnection();
874
+        $sql = 'SELECT `storage`, `path` FROM `*PREFIX*filecache` WHERE `fileid` = ?';
875
+        $result = $connection->executeQuery($sql, array($id));
876
+        if ($row = $result->fetch()) {
877
+            $numericId = $row['storage'];
878
+            $path = $row['path'];
879
+        } else {
880
+            return null;
881
+        }
882
+
883
+        if ($id = Storage::getStorageId($numericId)) {
884
+            return array($id, $path);
885
+        } else {
886
+            return null;
887
+        }
888
+    }
889
+
890
+    /**
891
+     * normalize the given path
892
+     *
893
+     * @param string $path
894
+     * @return string
895
+     */
896
+    public function normalize($path) {
897
+
898
+        return trim(\OC_Util::normalizeUnicode($path), '/');
899
+    }
900 900
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -172,21 +172,21 @@  discard block
 block discarded – undo
172 172
 	 */
173 173
 	public static function cacheEntryFromData($data, IMimeTypeLoader $mimetypeLoader) {
174 174
 		//fix types
175
-		$data['fileid'] = (int)$data['fileid'];
176
-		$data['parent'] = (int)$data['parent'];
175
+		$data['fileid'] = (int) $data['fileid'];
176
+		$data['parent'] = (int) $data['parent'];
177 177
 		$data['size'] = 0 + $data['size'];
178
-		$data['mtime'] = (int)$data['mtime'];
179
-		$data['storage_mtime'] = (int)$data['storage_mtime'];
180
-		$data['encryptedVersion'] = (int)$data['encrypted'];
181
-		$data['encrypted'] = (bool)$data['encrypted'];
178
+		$data['mtime'] = (int) $data['mtime'];
179
+		$data['storage_mtime'] = (int) $data['storage_mtime'];
180
+		$data['encryptedVersion'] = (int) $data['encrypted'];
181
+		$data['encrypted'] = (bool) $data['encrypted'];
182 182
 		$data['storage_id'] = $data['storage'];
183
-		$data['storage'] = (int)$data['storage'];
183
+		$data['storage'] = (int) $data['storage'];
184 184
 		$data['mimetype'] = $mimetypeLoader->getMimetypeById($data['mimetype']);
185 185
 		$data['mimepart'] = $mimetypeLoader->getMimetypeById($data['mimepart']);
186 186
 		if ($data['storage_mtime'] == 0) {
187 187
 			$data['storage_mtime'] = $data['mtime'];
188 188
 		}
189
-		$data['permissions'] = (int)$data['permissions'];
189
+		$data['permissions'] = (int) $data['permissions'];
190 190
 		return new CacheEntry($data);
191 191
 	}
192 192
 
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 					FROM `*PREFIX*filecache` WHERE `parent` = ? ORDER BY `name` ASC';
215 215
 			$result = $this->connection->executeQuery($sql, [$fileId]);
216 216
 			$files = $result->fetchAll();
217
-			return array_map(function (array $data) {
217
+			return array_map(function(array $data) {
218 218
 				return self::cacheEntryFromData($data, $this->mimetypeLoader);
219 219
 			}, $files);
220 220
 		}
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		$queryParts[] = '`storage`';
276 276
 		$params[] = $this->getNumericStorageId();
277 277
 
278
-		$queryParts = array_map(function ($item) {
278
+		$queryParts = array_map(function($item) {
279 279
 			return trim($item, "`");
280 280
 		}, $queryParts);
281 281
 		$values = array_combine($queryParts, $params);
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 			}
290 290
 
291 291
 			if ($builder->execute()) {
292
-				$fileId = (int)$this->connection->lastInsertId('*PREFIX*filecache');
292
+				$fileId = (int) $this->connection->lastInsertId('*PREFIX*filecache');
293 293
 				$this->eventDispatcher->dispatch(CacheInsertEvent::class, new CacheInsertEvent($this->storage, $file, $fileId));
294 294
 				return $fileId;
295 295
 			}
@@ -332,10 +332,10 @@  discard block
 block discarded – undo
332 332
 
333 333
 		// don't update if the data we try to set is the same as the one in the record
334 334
 		// some databases (Postgres) don't like superfluous updates
335
-		$sql = 'UPDATE `*PREFIX*filecache` SET ' . implode(' = ?, ', $queryParts) . '=? ' .
336
-			'WHERE (' .
337
-			implode(' <> ? OR ', $queryParts) . ' <> ? OR ' .
338
-			implode(' IS NULL OR ', $queryParts) . ' IS NULL' .
335
+		$sql = 'UPDATE `*PREFIX*filecache` SET '.implode(' = ?, ', $queryParts).'=? '.
336
+			'WHERE ('.
337
+			implode(' <> ? OR ', $queryParts).' <> ? OR '.
338
+			implode(' IS NULL OR ', $queryParts).' IS NULL'.
339 339
 			') AND `fileid` = ? ';
340 340
 		$this->connection->executeQuery($sql, $params);
341 341
 
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 					}
392 392
 				}
393 393
 				$params[] = $value;
394
-				$queryParts[] = '`' . $name . '`';
394
+				$queryParts[] = '`'.$name.'`';
395 395
 			}
396 396
 		}
397 397
 		return array($queryParts, $params);
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 			return -1;
434 434
 		} else {
435 435
 			$parent = $this->getParentPath($file);
436
-			return (int)$this->getId($parent);
436
+			return (int) $this->getId($parent);
437 437
 		}
438 438
 	}
439 439
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 	 */
480 480
 	private function getSubFolders($entry) {
481 481
 		$children = $this->getFolderContentsById($entry['fileid']);
482
-		return array_filter($children, function ($child) {
482
+		return array_filter($children, function($child) {
483 483
 			return $child['mimetype'] === 'httpd/unix-directory';
484 484
 		});
485 485
 	}
@@ -543,10 +543,10 @@  discard block
 block discarded – undo
543 543
 			list($targetStorageId, $targetPath) = $this->getMoveInfo($targetPath);
544 544
 
545 545
 			if (is_null($sourceStorageId) || $sourceStorageId === false) {
546
-				throw new \Exception('Invalid source storage id: ' . $sourceStorageId);
546
+				throw new \Exception('Invalid source storage id: '.$sourceStorageId);
547 547
 			}
548 548
 			if (is_null($targetStorageId) || $targetStorageId === false) {
549
-				throw new \Exception('Invalid target storage id: ' . $targetStorageId);
549
+				throw new \Exception('Invalid target storage id: '.$targetStorageId);
550 550
 			}
551 551
 
552 552
 			$this->connection->beginTransaction();
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 					->set('path_hash', $fun->md5($newPathFunction))
566 566
 					->set('path', $newPathFunction)
567 567
 					->where($query->expr()->eq('storage', $query->createNamedParameter($sourceStorageId, IQueryBuilder::PARAM_INT)))
568
-					->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($sourcePath) . '/%')));
568
+					->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($sourcePath).'/%')));
569 569
 
570 570
 				try {
571 571
 					$query->execute();
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 		$sql = 'SELECT `size` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` = ?';
615 615
 		$result = $this->connection->executeQuery($sql, array($this->getNumericStorageId(), $pathHash));
616 616
 		if ($row = $result->fetch()) {
617
-			if ((int)$row['size'] === -1) {
617
+			if ((int) $row['size'] === -1) {
618 618
 				return self::SHALLOW;
619 619
 			} else {
620 620
 				return self::COMPLETE;
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 	private function searchResultToCacheEntries(Statement $result) {
664 664
 		$files = $result->fetchAll();
665 665
 
666
-		return array_map(function (array $data) {
666
+		return array_map(function(array $data) {
667 667
 			return self::cacheEntryFromData($data, $this->mimetypeLoader);
668 668
 		}, $files);
669 669
 	}
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 			$where = '`mimepart` = ?';
683 683
 		}
684 684
 		$sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `storage_mtime`, `mtime`, `encrypted`, `etag`, `permissions`, `checksum`
685
-				FROM `*PREFIX*filecache` WHERE ' . $where . ' AND `storage` = ?';
685
+				FROM `*PREFIX*filecache` WHERE ' . $where.' AND `storage` = ?';
686 686
 		$mimetype = $this->mimetypeLoader->getId($mimetype);
687 687
 		$result = $this->connection->executeQuery($sql, array($mimetype, $this->getNumericStorageId()));
688 688
 
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
 			$sql = 'SELECT count(*)
759 759
 					FROM `*PREFIX*filecache` WHERE `parent` = ? AND size = -1';
760 760
 			$result = $this->connection->executeQuery($sql, [$fileId]);
761
-			return (int)$result->fetchColumn();
761
+			return (int) $result->fetchColumn();
762 762
 		}
763 763
 		return -1;
764 764
 	}
@@ -777,8 +777,8 @@  discard block
 block discarded – undo
777 777
 		}
778 778
 		if (isset($entry['mimetype']) && $entry['mimetype'] === 'httpd/unix-directory') {
779 779
 			$id = $entry['fileid'];
780
-			$sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 ' .
781
-				'FROM `*PREFIX*filecache` ' .
780
+			$sql = 'SELECT SUM(`size`) AS f1, MIN(`size`) AS f2 '.
781
+				'FROM `*PREFIX*filecache` '.
782 782
 				'WHERE `parent` = ? AND `storage` = ?';
783 783
 			$result = $this->connection->executeQuery($sql, array($id, $this->getNumericStorageId()));
784 784
 			if ($row = $result->fetch()) {
Please login to merge, or discard this patch.
lib/private/Files/Cache/Wrapper/CacheJail.php 1 patch
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -37,296 +37,296 @@
 block discarded – undo
37 37
  * Jail to a subdirectory of the wrapped cache
38 38
  */
39 39
 class CacheJail extends CacheWrapper {
40
-	/**
41
-	 * @var string
42
-	 */
43
-	protected $root;
44
-
45
-	/**
46
-	 * @param \OCP\Files\Cache\ICache $cache
47
-	 * @param string $root
48
-	 */
49
-	public function __construct($cache, $root) {
50
-		parent::__construct($cache);
51
-		$this->root = $root;
52
-	}
53
-
54
-	protected function getRoot() {
55
-		return $this->root;
56
-	}
57
-
58
-	protected function getSourcePath($path) {
59
-		if ($path === '') {
60
-			return $this->getRoot();
61
-		} else {
62
-			return $this->getRoot() . '/' . ltrim($path, '/');
63
-		}
64
-	}
65
-
66
-	/**
67
-	 * @param string $path
68
-	 * @return null|string the jailed path or null if the path is outside the jail
69
-	 */
70
-	protected function getJailedPath($path) {
71
-		if ($this->getRoot() === '') {
72
-			return $path;
73
-		}
74
-		$rootLength = strlen($this->getRoot()) + 1;
75
-		if ($path === $this->getRoot()) {
76
-			return '';
77
-		} else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') {
78
-			return substr($path, $rootLength);
79
-		} else {
80
-			return null;
81
-		}
82
-	}
83
-
84
-	/**
85
-	 * @param ICacheEntry|array $entry
86
-	 * @return array
87
-	 */
88
-	protected function formatCacheEntry($entry) {
89
-		if (isset($entry['path'])) {
90
-			$entry['path'] = $this->getJailedPath($entry['path']);
91
-		}
92
-		return $entry;
93
-	}
94
-
95
-	protected function filterCacheEntry($entry) {
96
-		$rootLength = strlen($this->getRoot()) + 1;
97
-		return $rootLength === 1 || ($entry['path'] === $this->getRoot()) || (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/');
98
-	}
99
-
100
-	/**
101
-	 * get the stored metadata of a file or folder
102
-	 *
103
-	 * @param string /int $file
104
-	 * @return ICacheEntry|false
105
-	 */
106
-	public function get($file) {
107
-		if (is_string($file) or $file == '') {
108
-			$file = $this->getSourcePath($file);
109
-		}
110
-		return parent::get($file);
111
-	}
112
-
113
-	/**
114
-	 * insert meta data for a new file or folder
115
-	 *
116
-	 * @param string $file
117
-	 * @param array $data
118
-	 *
119
-	 * @return int file id
120
-	 * @throws \RuntimeException
121
-	 */
122
-	public function insert($file, array $data) {
123
-		return $this->getCache()->insert($this->getSourcePath($file), $data);
124
-	}
125
-
126
-	/**
127
-	 * update the metadata in the cache
128
-	 *
129
-	 * @param int $id
130
-	 * @param array $data
131
-	 */
132
-	public function update($id, array $data) {
133
-		$this->getCache()->update($id, $data);
134
-	}
135
-
136
-	/**
137
-	 * get the file id for a file
138
-	 *
139
-	 * @param string $file
140
-	 * @return int
141
-	 */
142
-	public function getId($file) {
143
-		return $this->getCache()->getId($this->getSourcePath($file));
144
-	}
145
-
146
-	/**
147
-	 * get the id of the parent folder of a file
148
-	 *
149
-	 * @param string $file
150
-	 * @return int
151
-	 */
152
-	public function getParentId($file) {
153
-		return $this->getCache()->getParentId($this->getSourcePath($file));
154
-	}
155
-
156
-	/**
157
-	 * check if a file is available in the cache
158
-	 *
159
-	 * @param string $file
160
-	 * @return bool
161
-	 */
162
-	public function inCache($file) {
163
-		return $this->getCache()->inCache($this->getSourcePath($file));
164
-	}
165
-
166
-	/**
167
-	 * remove a file or folder from the cache
168
-	 *
169
-	 * @param string $file
170
-	 */
171
-	public function remove($file) {
172
-		$this->getCache()->remove($this->getSourcePath($file));
173
-	}
174
-
175
-	/**
176
-	 * Move a file or folder in the cache
177
-	 *
178
-	 * @param string $source
179
-	 * @param string $target
180
-	 */
181
-	public function move($source, $target) {
182
-		$this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
183
-	}
184
-
185
-	/**
186
-	 * Get the storage id and path needed for a move
187
-	 *
188
-	 * @param string $path
189
-	 * @return array [$storageId, $internalPath]
190
-	 */
191
-	protected function getMoveInfo($path) {
192
-		return [$this->getNumericStorageId(), $this->getSourcePath($path)];
193
-	}
194
-
195
-	/**
196
-	 * remove all entries for files that are stored on the storage from the cache
197
-	 */
198
-	public function clear() {
199
-		$this->getCache()->remove($this->getRoot());
200
-	}
201
-
202
-	/**
203
-	 * @param string $file
204
-	 *
205
-	 * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
206
-	 */
207
-	public function getStatus($file) {
208
-		return $this->getCache()->getStatus($this->getSourcePath($file));
209
-	}
210
-
211
-	private function formatSearchResults($results) {
212
-		$results = array_filter($results, array($this, 'filterCacheEntry'));
213
-		$results = array_values($results);
214
-		return array_map(array($this, 'formatCacheEntry'), $results);
215
-	}
216
-
217
-	/**
218
-	 * search for files matching $pattern
219
-	 *
220
-	 * @param string $pattern
221
-	 * @return array an array of file data
222
-	 */
223
-	public function search($pattern) {
224
-		$results = $this->getCache()->search($pattern);
225
-		return $this->formatSearchResults($results);
226
-	}
227
-
228
-	/**
229
-	 * search for files by mimetype
230
-	 *
231
-	 * @param string $mimetype
232
-	 * @return array
233
-	 */
234
-	public function searchByMime($mimetype) {
235
-		$results = $this->getCache()->searchByMime($mimetype);
236
-		return $this->formatSearchResults($results);
237
-	}
238
-
239
-	public function searchQuery(ISearchQuery $query) {
240
-		$simpleQuery = new SearchQuery($query->getSearchOperation(), 0, 0, $query->getOrder(), $query->getUser());
241
-		$results = $this->getCache()->searchQuery($simpleQuery);
242
-		$results = $this->formatSearchResults($results);
243
-
244
-		$limit = $query->getLimit() === 0 ? NULL : $query->getLimit();
245
-		$results = array_slice($results, $query->getOffset(), $limit);
246
-
247
-		return $results;
248
-	}
249
-
250
-	/**
251
-	 * update the folder size and the size of all parent folders
252
-	 *
253
-	 * @param string|boolean $path
254
-	 * @param array $data (optional) meta data of the folder
255
-	 */
256
-	public function correctFolderSize($path, $data = null, $isBackgroundSize = false) {
257
-		if ($this->getCache() instanceof Cache) {
258
-			$this->getCache()->correctFolderSize($this->getSourcePath($path), $data, $isBackgroundSize);
259
-		}
260
-	}
261
-
262
-	/**
263
-	 * get the size of a folder and set it in the cache
264
-	 *
265
-	 * @param string $path
266
-	 * @param array $entry (optional) meta data of the folder
267
-	 * @return int
268
-	 */
269
-	public function calculateFolderSize($path, $entry = null) {
270
-		if ($this->getCache() instanceof Cache) {
271
-			return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry);
272
-		} else {
273
-			return 0;
274
-		}
275
-
276
-	}
277
-
278
-	/**
279
-	 * get all file ids on the files on the storage
280
-	 *
281
-	 * @return int[]
282
-	 */
283
-	public function getAll() {
284
-		// not supported
285
-		return array();
286
-	}
287
-
288
-	/**
289
-	 * find a folder in the cache which has not been fully scanned
290
-	 *
291
-	 * If multiply incomplete folders are in the cache, the one with the highest id will be returned,
292
-	 * use the one with the highest id gives the best result with the background scanner, since that is most
293
-	 * likely the folder where we stopped scanning previously
294
-	 *
295
-	 * @return string|bool the path of the folder or false when no folder matched
296
-	 */
297
-	public function getIncomplete() {
298
-		// not supported
299
-		return false;
300
-	}
301
-
302
-	/**
303
-	 * get the path of a file on this storage by it's id
304
-	 *
305
-	 * @param int $id
306
-	 * @return string|null
307
-	 */
308
-	public function getPathById($id) {
309
-		$path = $this->getCache()->getPathById($id);
310
-		if ($path === null) {
311
-			return null;
312
-		}
313
-
314
-		return $this->getJailedPath($path);
315
-	}
316
-
317
-	/**
318
-	 * Move a file or folder in the cache
319
-	 *
320
-	 * Note that this should make sure the entries are removed from the source cache
321
-	 *
322
-	 * @param \OCP\Files\Cache\ICache $sourceCache
323
-	 * @param string $sourcePath
324
-	 * @param string $targetPath
325
-	 */
326
-	public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
327
-		if ($sourceCache === $this) {
328
-			return $this->move($sourcePath, $targetPath);
329
-		}
330
-		return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath));
331
-	}
40
+    /**
41
+     * @var string
42
+     */
43
+    protected $root;
44
+
45
+    /**
46
+     * @param \OCP\Files\Cache\ICache $cache
47
+     * @param string $root
48
+     */
49
+    public function __construct($cache, $root) {
50
+        parent::__construct($cache);
51
+        $this->root = $root;
52
+    }
53
+
54
+    protected function getRoot() {
55
+        return $this->root;
56
+    }
57
+
58
+    protected function getSourcePath($path) {
59
+        if ($path === '') {
60
+            return $this->getRoot();
61
+        } else {
62
+            return $this->getRoot() . '/' . ltrim($path, '/');
63
+        }
64
+    }
65
+
66
+    /**
67
+     * @param string $path
68
+     * @return null|string the jailed path or null if the path is outside the jail
69
+     */
70
+    protected function getJailedPath($path) {
71
+        if ($this->getRoot() === '') {
72
+            return $path;
73
+        }
74
+        $rootLength = strlen($this->getRoot()) + 1;
75
+        if ($path === $this->getRoot()) {
76
+            return '';
77
+        } else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') {
78
+            return substr($path, $rootLength);
79
+        } else {
80
+            return null;
81
+        }
82
+    }
83
+
84
+    /**
85
+     * @param ICacheEntry|array $entry
86
+     * @return array
87
+     */
88
+    protected function formatCacheEntry($entry) {
89
+        if (isset($entry['path'])) {
90
+            $entry['path'] = $this->getJailedPath($entry['path']);
91
+        }
92
+        return $entry;
93
+    }
94
+
95
+    protected function filterCacheEntry($entry) {
96
+        $rootLength = strlen($this->getRoot()) + 1;
97
+        return $rootLength === 1 || ($entry['path'] === $this->getRoot()) || (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/');
98
+    }
99
+
100
+    /**
101
+     * get the stored metadata of a file or folder
102
+     *
103
+     * @param string /int $file
104
+     * @return ICacheEntry|false
105
+     */
106
+    public function get($file) {
107
+        if (is_string($file) or $file == '') {
108
+            $file = $this->getSourcePath($file);
109
+        }
110
+        return parent::get($file);
111
+    }
112
+
113
+    /**
114
+     * insert meta data for a new file or folder
115
+     *
116
+     * @param string $file
117
+     * @param array $data
118
+     *
119
+     * @return int file id
120
+     * @throws \RuntimeException
121
+     */
122
+    public function insert($file, array $data) {
123
+        return $this->getCache()->insert($this->getSourcePath($file), $data);
124
+    }
125
+
126
+    /**
127
+     * update the metadata in the cache
128
+     *
129
+     * @param int $id
130
+     * @param array $data
131
+     */
132
+    public function update($id, array $data) {
133
+        $this->getCache()->update($id, $data);
134
+    }
135
+
136
+    /**
137
+     * get the file id for a file
138
+     *
139
+     * @param string $file
140
+     * @return int
141
+     */
142
+    public function getId($file) {
143
+        return $this->getCache()->getId($this->getSourcePath($file));
144
+    }
145
+
146
+    /**
147
+     * get the id of the parent folder of a file
148
+     *
149
+     * @param string $file
150
+     * @return int
151
+     */
152
+    public function getParentId($file) {
153
+        return $this->getCache()->getParentId($this->getSourcePath($file));
154
+    }
155
+
156
+    /**
157
+     * check if a file is available in the cache
158
+     *
159
+     * @param string $file
160
+     * @return bool
161
+     */
162
+    public function inCache($file) {
163
+        return $this->getCache()->inCache($this->getSourcePath($file));
164
+    }
165
+
166
+    /**
167
+     * remove a file or folder from the cache
168
+     *
169
+     * @param string $file
170
+     */
171
+    public function remove($file) {
172
+        $this->getCache()->remove($this->getSourcePath($file));
173
+    }
174
+
175
+    /**
176
+     * Move a file or folder in the cache
177
+     *
178
+     * @param string $source
179
+     * @param string $target
180
+     */
181
+    public function move($source, $target) {
182
+        $this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
183
+    }
184
+
185
+    /**
186
+     * Get the storage id and path needed for a move
187
+     *
188
+     * @param string $path
189
+     * @return array [$storageId, $internalPath]
190
+     */
191
+    protected function getMoveInfo($path) {
192
+        return [$this->getNumericStorageId(), $this->getSourcePath($path)];
193
+    }
194
+
195
+    /**
196
+     * remove all entries for files that are stored on the storage from the cache
197
+     */
198
+    public function clear() {
199
+        $this->getCache()->remove($this->getRoot());
200
+    }
201
+
202
+    /**
203
+     * @param string $file
204
+     *
205
+     * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
206
+     */
207
+    public function getStatus($file) {
208
+        return $this->getCache()->getStatus($this->getSourcePath($file));
209
+    }
210
+
211
+    private function formatSearchResults($results) {
212
+        $results = array_filter($results, array($this, 'filterCacheEntry'));
213
+        $results = array_values($results);
214
+        return array_map(array($this, 'formatCacheEntry'), $results);
215
+    }
216
+
217
+    /**
218
+     * search for files matching $pattern
219
+     *
220
+     * @param string $pattern
221
+     * @return array an array of file data
222
+     */
223
+    public function search($pattern) {
224
+        $results = $this->getCache()->search($pattern);
225
+        return $this->formatSearchResults($results);
226
+    }
227
+
228
+    /**
229
+     * search for files by mimetype
230
+     *
231
+     * @param string $mimetype
232
+     * @return array
233
+     */
234
+    public function searchByMime($mimetype) {
235
+        $results = $this->getCache()->searchByMime($mimetype);
236
+        return $this->formatSearchResults($results);
237
+    }
238
+
239
+    public function searchQuery(ISearchQuery $query) {
240
+        $simpleQuery = new SearchQuery($query->getSearchOperation(), 0, 0, $query->getOrder(), $query->getUser());
241
+        $results = $this->getCache()->searchQuery($simpleQuery);
242
+        $results = $this->formatSearchResults($results);
243
+
244
+        $limit = $query->getLimit() === 0 ? NULL : $query->getLimit();
245
+        $results = array_slice($results, $query->getOffset(), $limit);
246
+
247
+        return $results;
248
+    }
249
+
250
+    /**
251
+     * update the folder size and the size of all parent folders
252
+     *
253
+     * @param string|boolean $path
254
+     * @param array $data (optional) meta data of the folder
255
+     */
256
+    public function correctFolderSize($path, $data = null, $isBackgroundSize = false) {
257
+        if ($this->getCache() instanceof Cache) {
258
+            $this->getCache()->correctFolderSize($this->getSourcePath($path), $data, $isBackgroundSize);
259
+        }
260
+    }
261
+
262
+    /**
263
+     * get the size of a folder and set it in the cache
264
+     *
265
+     * @param string $path
266
+     * @param array $entry (optional) meta data of the folder
267
+     * @return int
268
+     */
269
+    public function calculateFolderSize($path, $entry = null) {
270
+        if ($this->getCache() instanceof Cache) {
271
+            return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry);
272
+        } else {
273
+            return 0;
274
+        }
275
+
276
+    }
277
+
278
+    /**
279
+     * get all file ids on the files on the storage
280
+     *
281
+     * @return int[]
282
+     */
283
+    public function getAll() {
284
+        // not supported
285
+        return array();
286
+    }
287
+
288
+    /**
289
+     * find a folder in the cache which has not been fully scanned
290
+     *
291
+     * If multiply incomplete folders are in the cache, the one with the highest id will be returned,
292
+     * use the one with the highest id gives the best result with the background scanner, since that is most
293
+     * likely the folder where we stopped scanning previously
294
+     *
295
+     * @return string|bool the path of the folder or false when no folder matched
296
+     */
297
+    public function getIncomplete() {
298
+        // not supported
299
+        return false;
300
+    }
301
+
302
+    /**
303
+     * get the path of a file on this storage by it's id
304
+     *
305
+     * @param int $id
306
+     * @return string|null
307
+     */
308
+    public function getPathById($id) {
309
+        $path = $this->getCache()->getPathById($id);
310
+        if ($path === null) {
311
+            return null;
312
+        }
313
+
314
+        return $this->getJailedPath($path);
315
+    }
316
+
317
+    /**
318
+     * Move a file or folder in the cache
319
+     *
320
+     * Note that this should make sure the entries are removed from the source cache
321
+     *
322
+     * @param \OCP\Files\Cache\ICache $sourceCache
323
+     * @param string $sourcePath
324
+     * @param string $targetPath
325
+     */
326
+    public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
327
+        if ($sourceCache === $this) {
328
+            return $this->move($sourcePath, $targetPath);
329
+        }
330
+        return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath));
331
+    }
332 332
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/Wrapper/CacheWrapper.php 1 patch
Indentation   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -33,290 +33,290 @@
 block discarded – undo
33 33
 use OCP\Files\Search\ISearchQuery;
34 34
 
35 35
 class CacheWrapper extends Cache {
36
-	/**
37
-	 * @var \OCP\Files\Cache\ICache
38
-	 */
39
-	protected $cache;
36
+    /**
37
+     * @var \OCP\Files\Cache\ICache
38
+     */
39
+    protected $cache;
40 40
 
41
-	/**
42
-	 * @param \OCP\Files\Cache\ICache $cache
43
-	 */
44
-	public function __construct($cache) {
45
-		$this->cache = $cache;
46
-	}
41
+    /**
42
+     * @param \OCP\Files\Cache\ICache $cache
43
+     */
44
+    public function __construct($cache) {
45
+        $this->cache = $cache;
46
+    }
47 47
 
48
-	protected function getCache() {
49
-		return $this->cache;
50
-	}
48
+    protected function getCache() {
49
+        return $this->cache;
50
+    }
51 51
 
52
-	/**
53
-	 * Make it easy for wrappers to modify every returned cache entry
54
-	 *
55
-	 * @param ICacheEntry $entry
56
-	 * @return ICacheEntry
57
-	 */
58
-	protected function formatCacheEntry($entry) {
59
-		return $entry;
60
-	}
52
+    /**
53
+     * Make it easy for wrappers to modify every returned cache entry
54
+     *
55
+     * @param ICacheEntry $entry
56
+     * @return ICacheEntry
57
+     */
58
+    protected function formatCacheEntry($entry) {
59
+        return $entry;
60
+    }
61 61
 
62
-	/**
63
-	 * get the stored metadata of a file or folder
64
-	 *
65
-	 * @param string|int $file
66
-	 * @return ICacheEntry|false
67
-	 */
68
-	public function get($file) {
69
-		$result = $this->getCache()->get($file);
70
-		if ($result) {
71
-			$result = $this->formatCacheEntry($result);
72
-		}
73
-		return $result;
74
-	}
62
+    /**
63
+     * get the stored metadata of a file or folder
64
+     *
65
+     * @param string|int $file
66
+     * @return ICacheEntry|false
67
+     */
68
+    public function get($file) {
69
+        $result = $this->getCache()->get($file);
70
+        if ($result) {
71
+            $result = $this->formatCacheEntry($result);
72
+        }
73
+        return $result;
74
+    }
75 75
 
76
-	/**
77
-	 * get the metadata of all files stored in $folder
78
-	 *
79
-	 * @param string $folder
80
-	 * @return ICacheEntry[]
81
-	 */
82
-	public function getFolderContents($folder) {
83
-		// can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this
84
-		// and not the wrapped cache
85
-		$fileId = $this->getId($folder);
86
-		return $this->getFolderContentsById($fileId);
87
-	}
76
+    /**
77
+     * get the metadata of all files stored in $folder
78
+     *
79
+     * @param string $folder
80
+     * @return ICacheEntry[]
81
+     */
82
+    public function getFolderContents($folder) {
83
+        // can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this
84
+        // and not the wrapped cache
85
+        $fileId = $this->getId($folder);
86
+        return $this->getFolderContentsById($fileId);
87
+    }
88 88
 
89
-	/**
90
-	 * get the metadata of all files stored in $folder
91
-	 *
92
-	 * @param int $fileId the file id of the folder
93
-	 * @return array
94
-	 */
95
-	public function getFolderContentsById($fileId) {
96
-		$results = $this->getCache()->getFolderContentsById($fileId);
97
-		return array_map(array($this, 'formatCacheEntry'), $results);
98
-	}
89
+    /**
90
+     * get the metadata of all files stored in $folder
91
+     *
92
+     * @param int $fileId the file id of the folder
93
+     * @return array
94
+     */
95
+    public function getFolderContentsById($fileId) {
96
+        $results = $this->getCache()->getFolderContentsById($fileId);
97
+        return array_map(array($this, 'formatCacheEntry'), $results);
98
+    }
99 99
 
100
-	/**
101
-	 * insert or update meta data for a file or folder
102
-	 *
103
-	 * @param string $file
104
-	 * @param array $data
105
-	 *
106
-	 * @return int file id
107
-	 * @throws \RuntimeException
108
-	 */
109
-	public function put($file, array $data) {
110
-		if (($id = $this->getId($file)) > -1) {
111
-			$this->update($id, $data);
112
-			return $id;
113
-		} else {
114
-			return $this->insert($file, $data);
115
-		}
116
-	}
100
+    /**
101
+     * insert or update meta data for a file or folder
102
+     *
103
+     * @param string $file
104
+     * @param array $data
105
+     *
106
+     * @return int file id
107
+     * @throws \RuntimeException
108
+     */
109
+    public function put($file, array $data) {
110
+        if (($id = $this->getId($file)) > -1) {
111
+            $this->update($id, $data);
112
+            return $id;
113
+        } else {
114
+            return $this->insert($file, $data);
115
+        }
116
+    }
117 117
 
118
-	/**
119
-	 * insert meta data for a new file or folder
120
-	 *
121
-	 * @param string $file
122
-	 * @param array $data
123
-	 *
124
-	 * @return int file id
125
-	 * @throws \RuntimeException
126
-	 */
127
-	public function insert($file, array $data) {
128
-		return $this->getCache()->insert($file, $data);
129
-	}
118
+    /**
119
+     * insert meta data for a new file or folder
120
+     *
121
+     * @param string $file
122
+     * @param array $data
123
+     *
124
+     * @return int file id
125
+     * @throws \RuntimeException
126
+     */
127
+    public function insert($file, array $data) {
128
+        return $this->getCache()->insert($file, $data);
129
+    }
130 130
 
131
-	/**
132
-	 * update the metadata in the cache
133
-	 *
134
-	 * @param int $id
135
-	 * @param array $data
136
-	 */
137
-	public function update($id, array $data) {
138
-		$this->getCache()->update($id, $data);
139
-	}
131
+    /**
132
+     * update the metadata in the cache
133
+     *
134
+     * @param int $id
135
+     * @param array $data
136
+     */
137
+    public function update($id, array $data) {
138
+        $this->getCache()->update($id, $data);
139
+    }
140 140
 
141
-	/**
142
-	 * get the file id for a file
143
-	 *
144
-	 * @param string $file
145
-	 * @return int
146
-	 */
147
-	public function getId($file) {
148
-		return $this->getCache()->getId($file);
149
-	}
141
+    /**
142
+     * get the file id for a file
143
+     *
144
+     * @param string $file
145
+     * @return int
146
+     */
147
+    public function getId($file) {
148
+        return $this->getCache()->getId($file);
149
+    }
150 150
 
151
-	/**
152
-	 * get the id of the parent folder of a file
153
-	 *
154
-	 * @param string $file
155
-	 * @return int
156
-	 */
157
-	public function getParentId($file) {
158
-		return $this->getCache()->getParentId($file);
159
-	}
151
+    /**
152
+     * get the id of the parent folder of a file
153
+     *
154
+     * @param string $file
155
+     * @return int
156
+     */
157
+    public function getParentId($file) {
158
+        return $this->getCache()->getParentId($file);
159
+    }
160 160
 
161
-	/**
162
-	 * check if a file is available in the cache
163
-	 *
164
-	 * @param string $file
165
-	 * @return bool
166
-	 */
167
-	public function inCache($file) {
168
-		return $this->getCache()->inCache($file);
169
-	}
161
+    /**
162
+     * check if a file is available in the cache
163
+     *
164
+     * @param string $file
165
+     * @return bool
166
+     */
167
+    public function inCache($file) {
168
+        return $this->getCache()->inCache($file);
169
+    }
170 170
 
171
-	/**
172
-	 * remove a file or folder from the cache
173
-	 *
174
-	 * @param string $file
175
-	 */
176
-	public function remove($file) {
177
-		$this->getCache()->remove($file);
178
-	}
171
+    /**
172
+     * remove a file or folder from the cache
173
+     *
174
+     * @param string $file
175
+     */
176
+    public function remove($file) {
177
+        $this->getCache()->remove($file);
178
+    }
179 179
 
180
-	/**
181
-	 * Move a file or folder in the cache
182
-	 *
183
-	 * @param string $source
184
-	 * @param string $target
185
-	 */
186
-	public function move($source, $target) {
187
-		$this->getCache()->move($source, $target);
188
-	}
180
+    /**
181
+     * Move a file or folder in the cache
182
+     *
183
+     * @param string $source
184
+     * @param string $target
185
+     */
186
+    public function move($source, $target) {
187
+        $this->getCache()->move($source, $target);
188
+    }
189 189
 
190
-	protected function getMoveInfo($path) {
191
-		/** @var Cache $cache */
192
-		$cache = $this->getCache();
193
-		return $cache->getMoveInfo($path);
194
-	}
190
+    protected function getMoveInfo($path) {
191
+        /** @var Cache $cache */
192
+        $cache = $this->getCache();
193
+        return $cache->getMoveInfo($path);
194
+    }
195 195
 
196
-	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
197
-		$this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath);
198
-	}
196
+    public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
197
+        $this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath);
198
+    }
199 199
 
200
-	/**
201
-	 * remove all entries for files that are stored on the storage from the cache
202
-	 */
203
-	public function clear() {
204
-		$this->getCache()->clear();
205
-	}
200
+    /**
201
+     * remove all entries for files that are stored on the storage from the cache
202
+     */
203
+    public function clear() {
204
+        $this->getCache()->clear();
205
+    }
206 206
 
207
-	/**
208
-	 * @param string $file
209
-	 *
210
-	 * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
211
-	 */
212
-	public function getStatus($file) {
213
-		return $this->getCache()->getStatus($file);
214
-	}
207
+    /**
208
+     * @param string $file
209
+     *
210
+     * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
211
+     */
212
+    public function getStatus($file) {
213
+        return $this->getCache()->getStatus($file);
214
+    }
215 215
 
216
-	/**
217
-	 * search for files matching $pattern
218
-	 *
219
-	 * @param string $pattern
220
-	 * @return ICacheEntry[] an array of file data
221
-	 */
222
-	public function search($pattern) {
223
-		$results = $this->getCache()->search($pattern);
224
-		return array_map(array($this, 'formatCacheEntry'), $results);
225
-	}
216
+    /**
217
+     * search for files matching $pattern
218
+     *
219
+     * @param string $pattern
220
+     * @return ICacheEntry[] an array of file data
221
+     */
222
+    public function search($pattern) {
223
+        $results = $this->getCache()->search($pattern);
224
+        return array_map(array($this, 'formatCacheEntry'), $results);
225
+    }
226 226
 
227
-	/**
228
-	 * search for files by mimetype
229
-	 *
230
-	 * @param string $mimetype
231
-	 * @return ICacheEntry[]
232
-	 */
233
-	public function searchByMime($mimetype) {
234
-		$results = $this->getCache()->searchByMime($mimetype);
235
-		return array_map(array($this, 'formatCacheEntry'), $results);
236
-	}
227
+    /**
228
+     * search for files by mimetype
229
+     *
230
+     * @param string $mimetype
231
+     * @return ICacheEntry[]
232
+     */
233
+    public function searchByMime($mimetype) {
234
+        $results = $this->getCache()->searchByMime($mimetype);
235
+        return array_map(array($this, 'formatCacheEntry'), $results);
236
+    }
237 237
 
238
-	public function searchQuery(ISearchQuery $query) {
239
-		$results = $this->getCache()->searchQuery($query);
240
-		return array_map(array($this, 'formatCacheEntry'), $results);
241
-	}
238
+    public function searchQuery(ISearchQuery $query) {
239
+        $results = $this->getCache()->searchQuery($query);
240
+        return array_map(array($this, 'formatCacheEntry'), $results);
241
+    }
242 242
 
243
-	/**
244
-	 * update the folder size and the size of all parent folders
245
-	 *
246
-	 * @param string|boolean $path
247
-	 * @param array $data (optional) meta data of the folder
248
-	 */
249
-	public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {
250
-		if ($this->getCache() instanceof Cache) {
251
-			$this->getCache()->correctFolderSize($path, $data, $isBackgroundScan);
252
-		}
253
-	}
243
+    /**
244
+     * update the folder size and the size of all parent folders
245
+     *
246
+     * @param string|boolean $path
247
+     * @param array $data (optional) meta data of the folder
248
+     */
249
+    public function correctFolderSize($path, $data = null, $isBackgroundScan = false) {
250
+        if ($this->getCache() instanceof Cache) {
251
+            $this->getCache()->correctFolderSize($path, $data, $isBackgroundScan);
252
+        }
253
+    }
254 254
 
255
-	/**
256
-	 * get the size of a folder and set it in the cache
257
-	 *
258
-	 * @param string $path
259
-	 * @param array $entry (optional) meta data of the folder
260
-	 * @return int
261
-	 */
262
-	public function calculateFolderSize($path, $entry = null) {
263
-		if ($this->getCache() instanceof Cache) {
264
-			return $this->getCache()->calculateFolderSize($path, $entry);
265
-		} else {
266
-			return 0;
267
-		}
268
-	}
255
+    /**
256
+     * get the size of a folder and set it in the cache
257
+     *
258
+     * @param string $path
259
+     * @param array $entry (optional) meta data of the folder
260
+     * @return int
261
+     */
262
+    public function calculateFolderSize($path, $entry = null) {
263
+        if ($this->getCache() instanceof Cache) {
264
+            return $this->getCache()->calculateFolderSize($path, $entry);
265
+        } else {
266
+            return 0;
267
+        }
268
+    }
269 269
 
270
-	/**
271
-	 * get all file ids on the files on the storage
272
-	 *
273
-	 * @return int[]
274
-	 */
275
-	public function getAll() {
276
-		return $this->getCache()->getAll();
277
-	}
270
+    /**
271
+     * get all file ids on the files on the storage
272
+     *
273
+     * @return int[]
274
+     */
275
+    public function getAll() {
276
+        return $this->getCache()->getAll();
277
+    }
278 278
 
279
-	/**
280
-	 * find a folder in the cache which has not been fully scanned
281
-	 *
282
-	 * If multiple incomplete folders are in the cache, the one with the highest id will be returned,
283
-	 * use the one with the highest id gives the best result with the background scanner, since that is most
284
-	 * likely the folder where we stopped scanning previously
285
-	 *
286
-	 * @return string|bool the path of the folder or false when no folder matched
287
-	 */
288
-	public function getIncomplete() {
289
-		return $this->getCache()->getIncomplete();
290
-	}
279
+    /**
280
+     * find a folder in the cache which has not been fully scanned
281
+     *
282
+     * If multiple incomplete folders are in the cache, the one with the highest id will be returned,
283
+     * use the one with the highest id gives the best result with the background scanner, since that is most
284
+     * likely the folder where we stopped scanning previously
285
+     *
286
+     * @return string|bool the path of the folder or false when no folder matched
287
+     */
288
+    public function getIncomplete() {
289
+        return $this->getCache()->getIncomplete();
290
+    }
291 291
 
292
-	/**
293
-	 * get the path of a file on this storage by it's id
294
-	 *
295
-	 * @param int $id
296
-	 * @return string|null
297
-	 */
298
-	public function getPathById($id) {
299
-		return $this->getCache()->getPathById($id);
300
-	}
292
+    /**
293
+     * get the path of a file on this storage by it's id
294
+     *
295
+     * @param int $id
296
+     * @return string|null
297
+     */
298
+    public function getPathById($id) {
299
+        return $this->getCache()->getPathById($id);
300
+    }
301 301
 
302
-	/**
303
-	 * Returns the numeric storage id
304
-	 *
305
-	 * @return int
306
-	 */
307
-	public function getNumericStorageId() {
308
-		return $this->getCache()->getNumericStorageId();
309
-	}
302
+    /**
303
+     * Returns the numeric storage id
304
+     *
305
+     * @return int
306
+     */
307
+    public function getNumericStorageId() {
308
+        return $this->getCache()->getNumericStorageId();
309
+    }
310 310
 
311
-	/**
312
-	 * get the storage id of the storage for a file and the internal path of the file
313
-	 * unlike getPathById this does not limit the search to files on this storage and
314
-	 * instead does a global search in the cache table
315
-	 *
316
-	 * @param int $id
317
-	 * @return array first element holding the storage id, second the path
318
-	 */
319
-	static public function getById($id) {
320
-		return parent::getById($id);
321
-	}
311
+    /**
312
+     * get the storage id of the storage for a file and the internal path of the file
313
+     * unlike getPathById this does not limit the search to files on this storage and
314
+     * instead does a global search in the cache table
315
+     *
316
+     * @param int $id
317
+     * @return array first element holding the storage id, second the path
318
+     */
319
+    static public function getById($id) {
320
+        return parent::getById($id);
321
+    }
322 322
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/FailedCache.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -30,108 +30,108 @@
 block discarded – undo
30 30
  * Storage placeholder to represent a missing precondition, storage unavailable
31 31
  */
32 32
 class FailedCache implements ICache {
33
-	/** @var bool whether to show the failed storage in the ui */
34
-	private $visible;
35
-
36
-	/**
37
-	 * FailedCache constructor.
38
-	 *
39
-	 * @param bool $visible
40
-	 */
41
-	public function __construct($visible = true) {
42
-		$this->visible = $visible;
43
-	}
44
-
45
-
46
-	public function getNumericStorageId() {
47
-		return -1;
48
-	}
49
-
50
-	public function get($file) {
51
-		if ($file === '') {
52
-			return new CacheEntry([
53
-				'fileid' => -1,
54
-				'size' => 0,
55
-				'mimetype' => 'httpd/unix-directory',
56
-				'mimepart' => 'httpd',
57
-				'permissions' => $this->visible ? Constants::PERMISSION_READ : 0,
58
-				'mtime' => time()
59
-			]);
60
-		} else {
61
-			return false;
62
-		}
63
-	}
64
-
65
-	public function getFolderContents($folder) {
66
-		return [];
67
-	}
68
-
69
-	public function getFolderContentsById($fileId) {
70
-		return [];
71
-	}
72
-
73
-	public function put($file, array $data) {
74
-	}
75
-
76
-	public function insert($file, array $data) {
77
-	}
78
-
79
-	public function update($id, array $data) {
80
-	}
81
-
82
-	public function getId($file) {
83
-		return -1;
84
-	}
85
-
86
-	public function getParentId($file) {
87
-		return -1;
88
-	}
89
-
90
-	public function inCache($file) {
91
-		return false;
92
-	}
93
-
94
-	public function remove($file) {
95
-	}
96
-
97
-	public function move($source, $target) {
98
-	}
99
-
100
-	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
101
-	}
102
-
103
-	public function clear() {
104
-	}
105
-
106
-	public function getStatus($file) {
107
-		return ICache::NOT_FOUND;
108
-	}
109
-
110
-	public function search($pattern) {
111
-		return [];
112
-	}
113
-
114
-	public function searchByMime($mimetype) {
115
-		return [];
116
-	}
117
-
118
-	public function searchQuery(ISearchQuery $query) {
119
-		return [];
120
-	}
121
-
122
-	public function getAll() {
123
-		return [];
124
-	}
125
-
126
-	public function getIncomplete() {
127
-		return [];
128
-	}
129
-
130
-	public function getPathById($id) {
131
-		return null;
132
-	}
133
-
134
-	public function normalize($path) {
135
-		return $path;
136
-	}
33
+    /** @var bool whether to show the failed storage in the ui */
34
+    private $visible;
35
+
36
+    /**
37
+     * FailedCache constructor.
38
+     *
39
+     * @param bool $visible
40
+     */
41
+    public function __construct($visible = true) {
42
+        $this->visible = $visible;
43
+    }
44
+
45
+
46
+    public function getNumericStorageId() {
47
+        return -1;
48
+    }
49
+
50
+    public function get($file) {
51
+        if ($file === '') {
52
+            return new CacheEntry([
53
+                'fileid' => -1,
54
+                'size' => 0,
55
+                'mimetype' => 'httpd/unix-directory',
56
+                'mimepart' => 'httpd',
57
+                'permissions' => $this->visible ? Constants::PERMISSION_READ : 0,
58
+                'mtime' => time()
59
+            ]);
60
+        } else {
61
+            return false;
62
+        }
63
+    }
64
+
65
+    public function getFolderContents($folder) {
66
+        return [];
67
+    }
68
+
69
+    public function getFolderContentsById($fileId) {
70
+        return [];
71
+    }
72
+
73
+    public function put($file, array $data) {
74
+    }
75
+
76
+    public function insert($file, array $data) {
77
+    }
78
+
79
+    public function update($id, array $data) {
80
+    }
81
+
82
+    public function getId($file) {
83
+        return -1;
84
+    }
85
+
86
+    public function getParentId($file) {
87
+        return -1;
88
+    }
89
+
90
+    public function inCache($file) {
91
+        return false;
92
+    }
93
+
94
+    public function remove($file) {
95
+    }
96
+
97
+    public function move($source, $target) {
98
+    }
99
+
100
+    public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) {
101
+    }
102
+
103
+    public function clear() {
104
+    }
105
+
106
+    public function getStatus($file) {
107
+        return ICache::NOT_FOUND;
108
+    }
109
+
110
+    public function search($pattern) {
111
+        return [];
112
+    }
113
+
114
+    public function searchByMime($mimetype) {
115
+        return [];
116
+    }
117
+
118
+    public function searchQuery(ISearchQuery $query) {
119
+        return [];
120
+    }
121
+
122
+    public function getAll() {
123
+        return [];
124
+    }
125
+
126
+    public function getIncomplete() {
127
+        return [];
128
+    }
129
+
130
+    public function getPathById($id) {
131
+        return null;
132
+    }
133
+
134
+    public function normalize($path) {
135
+        return $path;
136
+    }
137 137
 }
Please login to merge, or discard this patch.
lib/public/Files/Cache/ICache.php 1 patch
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -36,220 +36,220 @@
 block discarded – undo
36 36
  * @since 9.0.0
37 37
  */
38 38
 interface ICache {
39
-	const NOT_FOUND = 0;
40
-	const PARTIAL = 1; //only partial data available, file not cached in the database
41
-	const SHALLOW = 2; //folder in cache, but not all child files are completely scanned
42
-	const COMPLETE = 3;
43
-
44
-	/**
45
-	 * Get the numeric storage id for this cache's storage
46
-	 *
47
-	 * @return int
48
-	 * @since 9.0.0
49
-	 */
50
-	public function getNumericStorageId();
51
-
52
-	/**
53
-	 * get the stored metadata of a file or folder
54
-	 *
55
-	 * @param string | int $file either the path of a file or folder or the file id for a file or folder
56
-	 * @return ICacheEntry|false the cache entry or false if the file is not found in the cache
57
-	 * @since 9.0.0
58
-	 */
59
-	public function get($file);
60
-
61
-	/**
62
-	 * get the metadata of all files stored in $folder
63
-	 *
64
-	 * Only returns files one level deep, no recursion
65
-	 *
66
-	 * @param string $folder
67
-	 * @return ICacheEntry[]
68
-	 * @since 9.0.0
69
-	 */
70
-	public function getFolderContents($folder);
71
-
72
-	/**
73
-	 * get the metadata of all files stored in $folder
74
-	 *
75
-	 * Only returns files one level deep, no recursion
76
-	 *
77
-	 * @param int $fileId the file id of the folder
78
-	 * @return ICacheEntry[]
79
-	 * @since 9.0.0
80
-	 */
81
-	public function getFolderContentsById($fileId);
82
-
83
-	/**
84
-	 * store meta data for a file or folder
85
-	 * This will automatically call either insert or update depending on if the file exists
86
-	 *
87
-	 * @param string $file
88
-	 * @param array $data
89
-	 *
90
-	 * @return int file id
91
-	 * @throws \RuntimeException
92
-	 * @since 9.0.0
93
-	 */
94
-	public function put($file, array $data);
95
-
96
-	/**
97
-	 * insert meta data for a new file or folder
98
-	 *
99
-	 * @param string $file
100
-	 * @param array $data
101
-	 *
102
-	 * @return int file id
103
-	 * @throws \RuntimeException
104
-	 * @since 9.0.0
105
-	 */
106
-	public function insert($file, array $data);
107
-
108
-	/**
109
-	 * update the metadata of an existing file or folder in the cache
110
-	 *
111
-	 * @param int $id the fileid of the existing file or folder
112
-	 * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged
113
-	 * @since 9.0.0
114
-	 */
115
-	public function update($id, array $data);
116
-
117
-	/**
118
-	 * get the file id for a file
119
-	 *
120
-	 * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file
121
-	 *
122
-	 * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing
123
-	 *
124
-	 * @param string $file
125
-	 * @return int
126
-	 * @since 9.0.0
127
-	 */
128
-	public function getId($file);
129
-
130
-	/**
131
-	 * get the id of the parent folder of a file
132
-	 *
133
-	 * @param string $file
134
-	 * @return int
135
-	 * @since 9.0.0
136
-	 */
137
-	public function getParentId($file);
138
-
139
-	/**
140
-	 * check if a file is available in the cache
141
-	 *
142
-	 * @param string $file
143
-	 * @return bool
144
-	 * @since 9.0.0
145
-	 */
146
-	public function inCache($file);
147
-
148
-	/**
149
-	 * remove a file or folder from the cache
150
-	 *
151
-	 * when removing a folder from the cache all files and folders inside the folder will be removed as well
152
-	 *
153
-	 * @param string $file
154
-	 * @since 9.0.0
155
-	 */
156
-	public function remove($file);
157
-
158
-	/**
159
-	 * Move a file or folder in the cache
160
-	 *
161
-	 * @param string $source
162
-	 * @param string $target
163
-	 * @since 9.0.0
164
-	 */
165
-	public function move($source, $target);
166
-
167
-	/**
168
-	 * Move a file or folder in the cache
169
-	 *
170
-	 * Note that this should make sure the entries are removed from the source cache
171
-	 *
172
-	 * @param \OCP\Files\Cache\ICache $sourceCache
173
-	 * @param string $sourcePath
174
-	 * @param string $targetPath
175
-	 * @throws \OC\DatabaseException
176
-	 * @since 9.0.0
177
-	 */
178
-	public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath);
179
-
180
-	/**
181
-	 * Get the scan status of a file
182
-	 *
183
-	 * - ICache::NOT_FOUND: File is not in the cache
184
-	 * - ICache::PARTIAL: File is not stored in the cache but some incomplete data is known
185
-	 * - ICache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned
186
-	 * - ICache::COMPLETE: The file or folder, with all it's children) are fully scanned
187
-	 *
188
-	 * @param string $file
189
-	 *
190
-	 * @return int ICache::NOT_FOUND, ICache::PARTIAL, ICache::SHALLOW or ICache::COMPLETE
191
-	 * @since 9.0.0
192
-	 */
193
-	public function getStatus($file);
194
-
195
-	/**
196
-	 * search for files matching $pattern, files are matched if their filename matches the search pattern
197
-	 *
198
-	 * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%')
199
-	 * @return ICacheEntry[] an array of cache entries where the name matches the search pattern
200
-	 * @since 9.0.0
201
-	 * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this
202
-	 */
203
-	public function search($pattern);
204
-
205
-	/**
206
-	 * search for files by mimetype
207
-	 *
208
-	 * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image')
209
-	 *        where it will search for all mimetypes in the group ('image/*')
210
-	 * @return ICacheEntry[] an array of cache entries where the mimetype matches the search
211
-	 * @since 9.0.0
212
-	 * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this
213
-	 */
214
-	public function searchByMime($mimetype);
215
-
216
-	/**
217
-	 * Search for files with a flexible query
218
-	 *
219
-	 * @param ISearchQuery $query
220
-	 * @return ICacheEntry[]
221
-	 * @throw \InvalidArgumentException if the cache is unable to perform the query
222
-	 * @since 12.0.0
223
-	 */
224
-	public function searchQuery(ISearchQuery $query);
225
-
226
-	/**
227
-	 * find a folder in the cache which has not been fully scanned
228
-	 *
229
-	 * If multiple incomplete folders are in the cache, the one with the highest id will be returned,
230
-	 * use the one with the highest id gives the best result with the background scanner, since that is most
231
-	 * likely the folder where we stopped scanning previously
232
-	 *
233
-	 * @return string|bool the path of the folder or false when no folder matched
234
-	 * @since 9.0.0
235
-	 */
236
-	public function getIncomplete();
237
-
238
-	/**
239
-	 * get the path of a file on this storage by it's file id
240
-	 *
241
-	 * @param int $id the file id of the file or folder to search
242
-	 * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache
243
-	 * @since 9.0.0
244
-	 */
245
-	public function getPathById($id);
246
-
247
-	/**
248
-	 * normalize the given path for usage in the cache
249
-	 *
250
-	 * @param string $path
251
-	 * @return string
252
-	 * @since 9.0.0
253
-	 */
254
-	public function normalize($path);
39
+    const NOT_FOUND = 0;
40
+    const PARTIAL = 1; //only partial data available, file not cached in the database
41
+    const SHALLOW = 2; //folder in cache, but not all child files are completely scanned
42
+    const COMPLETE = 3;
43
+
44
+    /**
45
+     * Get the numeric storage id for this cache's storage
46
+     *
47
+     * @return int
48
+     * @since 9.0.0
49
+     */
50
+    public function getNumericStorageId();
51
+
52
+    /**
53
+     * get the stored metadata of a file or folder
54
+     *
55
+     * @param string | int $file either the path of a file or folder or the file id for a file or folder
56
+     * @return ICacheEntry|false the cache entry or false if the file is not found in the cache
57
+     * @since 9.0.0
58
+     */
59
+    public function get($file);
60
+
61
+    /**
62
+     * get the metadata of all files stored in $folder
63
+     *
64
+     * Only returns files one level deep, no recursion
65
+     *
66
+     * @param string $folder
67
+     * @return ICacheEntry[]
68
+     * @since 9.0.0
69
+     */
70
+    public function getFolderContents($folder);
71
+
72
+    /**
73
+     * get the metadata of all files stored in $folder
74
+     *
75
+     * Only returns files one level deep, no recursion
76
+     *
77
+     * @param int $fileId the file id of the folder
78
+     * @return ICacheEntry[]
79
+     * @since 9.0.0
80
+     */
81
+    public function getFolderContentsById($fileId);
82
+
83
+    /**
84
+     * store meta data for a file or folder
85
+     * This will automatically call either insert or update depending on if the file exists
86
+     *
87
+     * @param string $file
88
+     * @param array $data
89
+     *
90
+     * @return int file id
91
+     * @throws \RuntimeException
92
+     * @since 9.0.0
93
+     */
94
+    public function put($file, array $data);
95
+
96
+    /**
97
+     * insert meta data for a new file or folder
98
+     *
99
+     * @param string $file
100
+     * @param array $data
101
+     *
102
+     * @return int file id
103
+     * @throws \RuntimeException
104
+     * @since 9.0.0
105
+     */
106
+    public function insert($file, array $data);
107
+
108
+    /**
109
+     * update the metadata of an existing file or folder in the cache
110
+     *
111
+     * @param int $id the fileid of the existing file or folder
112
+     * @param array $data [$key => $value] the metadata to update, only the fields provided in the array will be updated, non-provided values will remain unchanged
113
+     * @since 9.0.0
114
+     */
115
+    public function update($id, array $data);
116
+
117
+    /**
118
+     * get the file id for a file
119
+     *
120
+     * A file id is a numeric id for a file or folder that's unique within an owncloud instance which stays the same for the lifetime of a file
121
+     *
122
+     * File ids are easiest way for apps to store references to a file since unlike paths they are not affected by renames or sharing
123
+     *
124
+     * @param string $file
125
+     * @return int
126
+     * @since 9.0.0
127
+     */
128
+    public function getId($file);
129
+
130
+    /**
131
+     * get the id of the parent folder of a file
132
+     *
133
+     * @param string $file
134
+     * @return int
135
+     * @since 9.0.0
136
+     */
137
+    public function getParentId($file);
138
+
139
+    /**
140
+     * check if a file is available in the cache
141
+     *
142
+     * @param string $file
143
+     * @return bool
144
+     * @since 9.0.0
145
+     */
146
+    public function inCache($file);
147
+
148
+    /**
149
+     * remove a file or folder from the cache
150
+     *
151
+     * when removing a folder from the cache all files and folders inside the folder will be removed as well
152
+     *
153
+     * @param string $file
154
+     * @since 9.0.0
155
+     */
156
+    public function remove($file);
157
+
158
+    /**
159
+     * Move a file or folder in the cache
160
+     *
161
+     * @param string $source
162
+     * @param string $target
163
+     * @since 9.0.0
164
+     */
165
+    public function move($source, $target);
166
+
167
+    /**
168
+     * Move a file or folder in the cache
169
+     *
170
+     * Note that this should make sure the entries are removed from the source cache
171
+     *
172
+     * @param \OCP\Files\Cache\ICache $sourceCache
173
+     * @param string $sourcePath
174
+     * @param string $targetPath
175
+     * @throws \OC\DatabaseException
176
+     * @since 9.0.0
177
+     */
178
+    public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath);
179
+
180
+    /**
181
+     * Get the scan status of a file
182
+     *
183
+     * - ICache::NOT_FOUND: File is not in the cache
184
+     * - ICache::PARTIAL: File is not stored in the cache but some incomplete data is known
185
+     * - ICache::SHALLOW: The folder and it's direct children are in the cache but not all sub folders are fully scanned
186
+     * - ICache::COMPLETE: The file or folder, with all it's children) are fully scanned
187
+     *
188
+     * @param string $file
189
+     *
190
+     * @return int ICache::NOT_FOUND, ICache::PARTIAL, ICache::SHALLOW or ICache::COMPLETE
191
+     * @since 9.0.0
192
+     */
193
+    public function getStatus($file);
194
+
195
+    /**
196
+     * search for files matching $pattern, files are matched if their filename matches the search pattern
197
+     *
198
+     * @param string $pattern the search pattern using SQL search syntax (e.g. '%searchstring%')
199
+     * @return ICacheEntry[] an array of cache entries where the name matches the search pattern
200
+     * @since 9.0.0
201
+     * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this
202
+     */
203
+    public function search($pattern);
204
+
205
+    /**
206
+     * search for files by mimetype
207
+     *
208
+     * @param string $mimetype either a full mimetype to search ('text/plain') or only the first part of a mimetype ('image')
209
+     *        where it will search for all mimetypes in the group ('image/*')
210
+     * @return ICacheEntry[] an array of cache entries where the mimetype matches the search
211
+     * @since 9.0.0
212
+     * @deprecated 9.0.0 due to lack of pagination, not all backends might implement this
213
+     */
214
+    public function searchByMime($mimetype);
215
+
216
+    /**
217
+     * Search for files with a flexible query
218
+     *
219
+     * @param ISearchQuery $query
220
+     * @return ICacheEntry[]
221
+     * @throw \InvalidArgumentException if the cache is unable to perform the query
222
+     * @since 12.0.0
223
+     */
224
+    public function searchQuery(ISearchQuery $query);
225
+
226
+    /**
227
+     * find a folder in the cache which has not been fully scanned
228
+     *
229
+     * If multiple incomplete folders are in the cache, the one with the highest id will be returned,
230
+     * use the one with the highest id gives the best result with the background scanner, since that is most
231
+     * likely the folder where we stopped scanning previously
232
+     *
233
+     * @return string|bool the path of the folder or false when no folder matched
234
+     * @since 9.0.0
235
+     */
236
+    public function getIncomplete();
237
+
238
+    /**
239
+     * get the path of a file on this storage by it's file id
240
+     *
241
+     * @param int $id the file id of the file or folder to search
242
+     * @return string|null the path of the file (relative to the storage) or null if a file with the given id does not exists within this cache
243
+     * @since 9.0.0
244
+     */
245
+    public function getPathById($id);
246
+
247
+    /**
248
+     * normalize the given path for usage in the cache
249
+     *
250
+     * @param string $path
251
+     * @return string
252
+     * @since 9.0.0
253
+     */
254
+    public function normalize($path);
255 255
 }
Please login to merge, or discard this patch.