Completed
Pull Request — master (#7385)
by Robin
17:13
created
apps/files_sharing/lib/Cache.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -135,6 +135,10 @@
 block discarded – undo
135 135
 		return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
136 136
 	}
137 137
 
138
+	/**
139
+	 * @param ICacheEntry $entry
140
+	 * @param string $path
141
+	 */
138 142
 	protected function formatCacheEntry($entry, $path = null) {
139 143
 		if (is_null($path)) {
140 144
 			$path = isset($entry['path']) ? $entry['path'] : '';
Please login to merge, or discard this patch.
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -39,134 +39,134 @@
 block discarded – undo
39 39
  * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead
40 40
  */
41 41
 class Cache extends CacheJail {
42
-	/**
43
-	 * @var \OCA\Files_Sharing\SharedStorage
44
-	 */
45
-	private $storage;
46
-
47
-	/**
48
-	 * @var ICacheEntry
49
-	 */
50
-	private $sourceRootInfo;
51
-
52
-	private $rootUnchanged = true;
53
-
54
-	private $ownerDisplayName;
55
-
56
-	private $numericId;
57
-
58
-	/**
59
-	 * @param \OCA\Files_Sharing\SharedStorage $storage
60
-	 * @param ICacheEntry $sourceRootInfo
61
-	 */
62
-	public function __construct($storage, ICacheEntry $sourceRootInfo) {
63
-		$this->storage = $storage;
64
-		$this->sourceRootInfo = $sourceRootInfo;
65
-		$this->numericId = $sourceRootInfo->getStorageId();
66
-
67
-		parent::__construct(
68
-			null,
69
-			null
70
-		);
71
-	}
72
-
73
-	protected function getRoot() {
74
-		if (is_null($this->root)) {
75
-			$absoluteRoot = $this->sourceRootInfo->getPath();
76
-
77
-			// the sourceRootInfo path is the absolute path of the folder in the "real" storage
78
-			// in the case where a folder is shared from a Jail we need to ensure that the share Jail
79
-			// has it's root set relative to the source Jail
80
-			$currentStorage = $this->storage->getSourceStorage();
81
-			if ($currentStorage->instanceOfStorage(Jail::class)) {
82
-				/** @var Jail $currentStorage */
83
-				$absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
84
-			}
85
-			$this->root = $absoluteRoot;
86
-		}
87
-		return $this->root;
88
-	}
89
-
90
-	public function getCache() {
91
-		if (is_null($this->cache)) {
92
-			$sourceStorage = $this->storage->getSourceStorage();
93
-			if ($sourceStorage) {
94
-				$this->cache = $sourceStorage->getCache();
95
-			} else {
96
-				// don't set $this->cache here since sourceStorage will be set later
97
-				return new FailedCache();
98
-			}
99
-		}
100
-		return $this->cache;
101
-	}
102
-
103
-	public function getNumericStorageId() {
104
-		if (isset($this->numericId)) {
105
-			return $this->numericId;
106
-		} else {
107
-			return false;
108
-		}
109
-	}
110
-
111
-	public function get($file) {
112
-		if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
113
-			return $this->formatCacheEntry(clone $this->sourceRootInfo, '');
114
-		}
115
-		return parent::get($file);
116
-	}
117
-
118
-	public function update($id, array $data) {
119
-		$this->rootUnchanged = false;
120
-		parent::update($id, $data);
121
-	}
122
-
123
-	public function insert($file, array $data) {
124
-		$this->rootUnchanged = false;
125
-		return parent::insert($file, $data);
126
-	}
127
-
128
-	public function remove($file) {
129
-		$this->rootUnchanged = false;
130
-		parent::remove($file);
131
-	}
132
-
133
-	public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
134
-		$this->rootUnchanged = false;
135
-		return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
136
-	}
137
-
138
-	protected function formatCacheEntry($entry, $path = null) {
139
-		if (is_null($path)) {
140
-			$path = isset($entry['path']) ? $entry['path'] : '';
141
-			$entry['path'] = $this->getJailedPath($path);
142
-		} else {
143
-			$entry['path'] = $path;
144
-		}
145
-		$sharePermissions = $this->storage->getPermissions($path);
146
-		if (isset($entry['permissions'])) {
147
-			$entry['permissions'] &= $sharePermissions;
148
-		} else {
149
-			$entry['permissions'] = $sharePermissions;
150
-		}
151
-		$entry['uid_owner'] = $this->storage->getOwner('');
152
-		$entry['displayname_owner'] = $this->getOwnerDisplayName();
153
-		if ($path === '') {
154
-			$entry['is_share_mount_point'] = true;
155
-		}
156
-		return $entry;
157
-	}
158
-
159
-	private function getOwnerDisplayName() {
160
-		if (!$this->ownerDisplayName) {
161
-			$this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner(''));
162
-		}
163
-		return $this->ownerDisplayName;
164
-	}
165
-
166
-	/**
167
-	 * remove all entries for files that are stored on the storage from the cache
168
-	 */
169
-	public function clear() {
170
-		// Not a valid action for Shared Cache
171
-	}
42
+    /**
43
+     * @var \OCA\Files_Sharing\SharedStorage
44
+     */
45
+    private $storage;
46
+
47
+    /**
48
+     * @var ICacheEntry
49
+     */
50
+    private $sourceRootInfo;
51
+
52
+    private $rootUnchanged = true;
53
+
54
+    private $ownerDisplayName;
55
+
56
+    private $numericId;
57
+
58
+    /**
59
+     * @param \OCA\Files_Sharing\SharedStorage $storage
60
+     * @param ICacheEntry $sourceRootInfo
61
+     */
62
+    public function __construct($storage, ICacheEntry $sourceRootInfo) {
63
+        $this->storage = $storage;
64
+        $this->sourceRootInfo = $sourceRootInfo;
65
+        $this->numericId = $sourceRootInfo->getStorageId();
66
+
67
+        parent::__construct(
68
+            null,
69
+            null
70
+        );
71
+    }
72
+
73
+    protected function getRoot() {
74
+        if (is_null($this->root)) {
75
+            $absoluteRoot = $this->sourceRootInfo->getPath();
76
+
77
+            // the sourceRootInfo path is the absolute path of the folder in the "real" storage
78
+            // in the case where a folder is shared from a Jail we need to ensure that the share Jail
79
+            // has it's root set relative to the source Jail
80
+            $currentStorage = $this->storage->getSourceStorage();
81
+            if ($currentStorage->instanceOfStorage(Jail::class)) {
82
+                /** @var Jail $currentStorage */
83
+                $absoluteRoot = $currentStorage->getJailedPath($absoluteRoot);
84
+            }
85
+            $this->root = $absoluteRoot;
86
+        }
87
+        return $this->root;
88
+    }
89
+
90
+    public function getCache() {
91
+        if (is_null($this->cache)) {
92
+            $sourceStorage = $this->storage->getSourceStorage();
93
+            if ($sourceStorage) {
94
+                $this->cache = $sourceStorage->getCache();
95
+            } else {
96
+                // don't set $this->cache here since sourceStorage will be set later
97
+                return new FailedCache();
98
+            }
99
+        }
100
+        return $this->cache;
101
+    }
102
+
103
+    public function getNumericStorageId() {
104
+        if (isset($this->numericId)) {
105
+            return $this->numericId;
106
+        } else {
107
+            return false;
108
+        }
109
+    }
110
+
111
+    public function get($file) {
112
+        if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) {
113
+            return $this->formatCacheEntry(clone $this->sourceRootInfo, '');
114
+        }
115
+        return parent::get($file);
116
+    }
117
+
118
+    public function update($id, array $data) {
119
+        $this->rootUnchanged = false;
120
+        parent::update($id, $data);
121
+    }
122
+
123
+    public function insert($file, array $data) {
124
+        $this->rootUnchanged = false;
125
+        return parent::insert($file, $data);
126
+    }
127
+
128
+    public function remove($file) {
129
+        $this->rootUnchanged = false;
130
+        parent::remove($file);
131
+    }
132
+
133
+    public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
134
+        $this->rootUnchanged = false;
135
+        return parent::moveFromCache($sourceCache, $sourcePath, $targetPath);
136
+    }
137
+
138
+    protected function formatCacheEntry($entry, $path = null) {
139
+        if (is_null($path)) {
140
+            $path = isset($entry['path']) ? $entry['path'] : '';
141
+            $entry['path'] = $this->getJailedPath($path);
142
+        } else {
143
+            $entry['path'] = $path;
144
+        }
145
+        $sharePermissions = $this->storage->getPermissions($path);
146
+        if (isset($entry['permissions'])) {
147
+            $entry['permissions'] &= $sharePermissions;
148
+        } else {
149
+            $entry['permissions'] = $sharePermissions;
150
+        }
151
+        $entry['uid_owner'] = $this->storage->getOwner('');
152
+        $entry['displayname_owner'] = $this->getOwnerDisplayName();
153
+        if ($path === '') {
154
+            $entry['is_share_mount_point'] = true;
155
+        }
156
+        return $entry;
157
+    }
158
+
159
+    private function getOwnerDisplayName() {
160
+        if (!$this->ownerDisplayName) {
161
+            $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner(''));
162
+        }
163
+        return $this->ownerDisplayName;
164
+    }
165
+
166
+    /**
167
+     * remove all entries for files that are stored on the storage from the cache
168
+     */
169
+    public function clear() {
170
+        // Not a valid action for Shared Cache
171
+    }
172 172
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/Wrapper/CacheJail.php 2 patches
Indentation   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -36,298 +36,298 @@
 block discarded – undo
36 36
  * Jail to a subdirectory of the wrapped cache
37 37
  */
38 38
 class CacheJail extends CacheWrapper {
39
-	/**
40
-	 * @var string
41
-	 */
42
-	protected $root;
43
-
44
-	/**
45
-	 * @param \OCP\Files\Cache\ICache $cache
46
-	 * @param string $root
47
-	 */
48
-	public function __construct($cache, $root) {
49
-		parent::__construct($cache);
50
-		$this->root = $root;
51
-	}
52
-
53
-	protected function getRoot() {
54
-		return $this->root;
55
-	}
56
-
57
-	protected function getSourcePath($path) {
58
-		if ($path === '') {
59
-			return $this->getRoot();
60
-		} else {
61
-			return $this->getRoot() . '/' . ltrim($path, '/');
62
-		}
63
-	}
64
-
65
-	/**
66
-	 * @param string $path
67
-	 * @return null|string the jailed path or null if the path is outside the jail
68
-	 */
69
-	protected function getJailedPath($path) {
70
-		if ($this->getRoot() === '') {
71
-			return $path;
72
-		}
73
-		$rootLength = strlen($this->getRoot()) + 1;
74
-		if ($path === $this->getRoot()) {
75
-			return '';
76
-		} else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') {
77
-			return substr($path, $rootLength);
78
-		} else {
79
-			return null;
80
-		}
81
-	}
82
-
83
-	/**
84
-	 * @param ICacheEntry|array $entry
85
-	 * @return array
86
-	 */
87
-	protected function formatCacheEntry($entry) {
88
-		if (isset($entry['path'])) {
89
-			$entry['path'] = $this->getJailedPath($entry['path']);
90
-		}
91
-		return $entry;
92
-	}
93
-
94
-	protected function filterCacheEntry($entry) {
95
-		$rootLength = strlen($this->getRoot()) + 1;
96
-		return ($entry['path'] === $this->getRoot()) or (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/');
97
-	}
98
-
99
-	/**
100
-	 * get the stored metadata of a file or folder
101
-	 *
102
-	 * @param string /int $file
103
-	 * @return ICacheEntry|false
104
-	 */
105
-	public function get($file) {
106
-		if (is_string($file) or $file == '') {
107
-			$file = $this->getSourcePath($file);
108
-		}
109
-		return parent::get($file);
110
-	}
111
-
112
-	/**
113
-	 * insert meta data for a new file or folder
114
-	 *
115
-	 * @param string $file
116
-	 * @param array $data
117
-	 *
118
-	 * @return int file id
119
-	 * @throws \RuntimeException
120
-	 */
121
-	public function insert($file, array $data) {
122
-		return $this->getCache()->insert($this->getSourcePath($file), $data);
123
-	}
124
-
125
-	/**
126
-	 * update the metadata in the cache
127
-	 *
128
-	 * @param int $id
129
-	 * @param array $data
130
-	 */
131
-	public function update($id, array $data) {
132
-		$this->getCache()->update($id, $data);
133
-	}
134
-
135
-	/**
136
-	 * get the file id for a file
137
-	 *
138
-	 * @param string $file
139
-	 * @return int
140
-	 */
141
-	public function getId($file) {
142
-		return $this->getCache()->getId($this->getSourcePath($file));
143
-	}
144
-
145
-	/**
146
-	 * get the id of the parent folder of a file
147
-	 *
148
-	 * @param string $file
149
-	 * @return int
150
-	 */
151
-	public function getParentId($file) {
152
-		return $this->getCache()->getParentId($this->getSourcePath($file));
153
-	}
154
-
155
-	/**
156
-	 * check if a file is available in the cache
157
-	 *
158
-	 * @param string $file
159
-	 * @return bool
160
-	 */
161
-	public function inCache($file) {
162
-		return $this->getCache()->inCache($this->getSourcePath($file));
163
-	}
164
-
165
-	/**
166
-	 * remove a file or folder from the cache
167
-	 *
168
-	 * @param string $file
169
-	 */
170
-	public function remove($file) {
171
-		$this->getCache()->remove($this->getSourcePath($file));
172
-	}
173
-
174
-	/**
175
-	 * Move a file or folder in the cache
176
-	 *
177
-	 * @param string $source
178
-	 * @param string $target
179
-	 */
180
-	public function move($source, $target) {
181
-		$this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
182
-	}
183
-
184
-	/**
185
-	 * Get the storage id and path needed for a move
186
-	 *
187
-	 * @param string $path
188
-	 * @return array [$storageId, $internalPath]
189
-	 */
190
-	protected function getMoveInfo($path) {
191
-		return [$this->getNumericStorageId(), $this->getSourcePath($path)];
192
-	}
193
-
194
-	/**
195
-	 * remove all entries for files that are stored on the storage from the cache
196
-	 */
197
-	public function clear() {
198
-		$this->getCache()->remove($this->getRoot());
199
-	}
200
-
201
-	/**
202
-	 * @param string $file
203
-	 *
204
-	 * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
205
-	 */
206
-	public function getStatus($file) {
207
-		return $this->getCache()->getStatus($this->getSourcePath($file));
208
-	}
209
-
210
-	private function formatSearchResults($results) {
211
-		$results = array_filter($results, array($this, 'filterCacheEntry'));
212
-		$results = array_values($results);
213
-		return array_map(array($this, 'formatCacheEntry'), $results);
214
-	}
215
-
216
-	/**
217
-	 * search for files matching $pattern
218
-	 *
219
-	 * @param string $pattern
220
-	 * @return array an array of file data
221
-	 */
222
-	public function search($pattern) {
223
-		$results = $this->getCache()->search($pattern);
224
-		return $this->formatSearchResults($results);
225
-	}
226
-
227
-	/**
228
-	 * search for files by mimetype
229
-	 *
230
-	 * @param string $mimetype
231
-	 * @return array
232
-	 */
233
-	public function searchByMime($mimetype) {
234
-		$results = $this->getCache()->searchByMime($mimetype);
235
-		return $this->formatSearchResults($results);
236
-	}
237
-
238
-	public function searchQuery(ISearchQuery $query) {
239
-		$results = $this->getCache()->searchQuery($query);
240
-		return $this->formatSearchResults($results);
241
-	}
242
-
243
-	/**
244
-	 * search for files by mimetype
245
-	 *
246
-	 * @param string|int $tag name or tag id
247
-	 * @param string $userId owner of the tags
248
-	 * @return array
249
-	 */
250
-	public function searchByTag($tag, $userId) {
251
-		$results = $this->getCache()->searchByTag($tag, $userId);
252
-		return $this->formatSearchResults($results);
253
-	}
254
-
255
-	/**
256
-	 * update the folder size and the size of all parent folders
257
-	 *
258
-	 * @param string|boolean $path
259
-	 * @param array $data (optional) meta data of the folder
260
-	 */
261
-	public function correctFolderSize($path, $data = null) {
262
-		if ($this->getCache() instanceof Cache) {
263
-			$this->getCache()->correctFolderSize($this->getSourcePath($path), $data);
264
-		}
265
-	}
266
-
267
-	/**
268
-	 * get the size of a folder and set it in the cache
269
-	 *
270
-	 * @param string $path
271
-	 * @param array $entry (optional) meta data of the folder
272
-	 * @return int
273
-	 */
274
-	public function calculateFolderSize($path, $entry = null) {
275
-		if ($this->getCache() instanceof Cache) {
276
-			return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry);
277
-		} else {
278
-			return 0;
279
-		}
280
-
281
-	}
282
-
283
-	/**
284
-	 * get all file ids on the files on the storage
285
-	 *
286
-	 * @return int[]
287
-	 */
288
-	public function getAll() {
289
-		// not supported
290
-		return array();
291
-	}
292
-
293
-	/**
294
-	 * find a folder in the cache which has not been fully scanned
295
-	 *
296
-	 * If multiply incomplete folders are in the cache, the one with the highest id will be returned,
297
-	 * use the one with the highest id gives the best result with the background scanner, since that is most
298
-	 * likely the folder where we stopped scanning previously
299
-	 *
300
-	 * @return string|bool the path of the folder or false when no folder matched
301
-	 */
302
-	public function getIncomplete() {
303
-		// not supported
304
-		return false;
305
-	}
306
-
307
-	/**
308
-	 * get the path of a file on this storage by it's id
309
-	 *
310
-	 * @param int $id
311
-	 * @return string|null
312
-	 */
313
-	public function getPathById($id) {
314
-		$path = $this->getCache()->getPathById($id);
315
-		return $this->getJailedPath($path);
316
-	}
317
-
318
-	/**
319
-	 * Move a file or folder in the cache
320
-	 *
321
-	 * Note that this should make sure the entries are removed from the source cache
322
-	 *
323
-	 * @param \OCP\Files\Cache\ICache $sourceCache
324
-	 * @param string $sourcePath
325
-	 * @param string $targetPath
326
-	 */
327
-	public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
328
-		if ($sourceCache === $this) {
329
-			return $this->move($sourcePath, $targetPath);
330
-		}
331
-		return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath));
332
-	}
39
+    /**
40
+     * @var string
41
+     */
42
+    protected $root;
43
+
44
+    /**
45
+     * @param \OCP\Files\Cache\ICache $cache
46
+     * @param string $root
47
+     */
48
+    public function __construct($cache, $root) {
49
+        parent::__construct($cache);
50
+        $this->root = $root;
51
+    }
52
+
53
+    protected function getRoot() {
54
+        return $this->root;
55
+    }
56
+
57
+    protected function getSourcePath($path) {
58
+        if ($path === '') {
59
+            return $this->getRoot();
60
+        } else {
61
+            return $this->getRoot() . '/' . ltrim($path, '/');
62
+        }
63
+    }
64
+
65
+    /**
66
+     * @param string $path
67
+     * @return null|string the jailed path or null if the path is outside the jail
68
+     */
69
+    protected function getJailedPath($path) {
70
+        if ($this->getRoot() === '') {
71
+            return $path;
72
+        }
73
+        $rootLength = strlen($this->getRoot()) + 1;
74
+        if ($path === $this->getRoot()) {
75
+            return '';
76
+        } else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') {
77
+            return substr($path, $rootLength);
78
+        } else {
79
+            return null;
80
+        }
81
+    }
82
+
83
+    /**
84
+     * @param ICacheEntry|array $entry
85
+     * @return array
86
+     */
87
+    protected function formatCacheEntry($entry) {
88
+        if (isset($entry['path'])) {
89
+            $entry['path'] = $this->getJailedPath($entry['path']);
90
+        }
91
+        return $entry;
92
+    }
93
+
94
+    protected function filterCacheEntry($entry) {
95
+        $rootLength = strlen($this->getRoot()) + 1;
96
+        return ($entry['path'] === $this->getRoot()) or (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/');
97
+    }
98
+
99
+    /**
100
+     * get the stored metadata of a file or folder
101
+     *
102
+     * @param string /int $file
103
+     * @return ICacheEntry|false
104
+     */
105
+    public function get($file) {
106
+        if (is_string($file) or $file == '') {
107
+            $file = $this->getSourcePath($file);
108
+        }
109
+        return parent::get($file);
110
+    }
111
+
112
+    /**
113
+     * insert meta data for a new file or folder
114
+     *
115
+     * @param string $file
116
+     * @param array $data
117
+     *
118
+     * @return int file id
119
+     * @throws \RuntimeException
120
+     */
121
+    public function insert($file, array $data) {
122
+        return $this->getCache()->insert($this->getSourcePath($file), $data);
123
+    }
124
+
125
+    /**
126
+     * update the metadata in the cache
127
+     *
128
+     * @param int $id
129
+     * @param array $data
130
+     */
131
+    public function update($id, array $data) {
132
+        $this->getCache()->update($id, $data);
133
+    }
134
+
135
+    /**
136
+     * get the file id for a file
137
+     *
138
+     * @param string $file
139
+     * @return int
140
+     */
141
+    public function getId($file) {
142
+        return $this->getCache()->getId($this->getSourcePath($file));
143
+    }
144
+
145
+    /**
146
+     * get the id of the parent folder of a file
147
+     *
148
+     * @param string $file
149
+     * @return int
150
+     */
151
+    public function getParentId($file) {
152
+        return $this->getCache()->getParentId($this->getSourcePath($file));
153
+    }
154
+
155
+    /**
156
+     * check if a file is available in the cache
157
+     *
158
+     * @param string $file
159
+     * @return bool
160
+     */
161
+    public function inCache($file) {
162
+        return $this->getCache()->inCache($this->getSourcePath($file));
163
+    }
164
+
165
+    /**
166
+     * remove a file or folder from the cache
167
+     *
168
+     * @param string $file
169
+     */
170
+    public function remove($file) {
171
+        $this->getCache()->remove($this->getSourcePath($file));
172
+    }
173
+
174
+    /**
175
+     * Move a file or folder in the cache
176
+     *
177
+     * @param string $source
178
+     * @param string $target
179
+     */
180
+    public function move($source, $target) {
181
+        $this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
182
+    }
183
+
184
+    /**
185
+     * Get the storage id and path needed for a move
186
+     *
187
+     * @param string $path
188
+     * @return array [$storageId, $internalPath]
189
+     */
190
+    protected function getMoveInfo($path) {
191
+        return [$this->getNumericStorageId(), $this->getSourcePath($path)];
192
+    }
193
+
194
+    /**
195
+     * remove all entries for files that are stored on the storage from the cache
196
+     */
197
+    public function clear() {
198
+        $this->getCache()->remove($this->getRoot());
199
+    }
200
+
201
+    /**
202
+     * @param string $file
203
+     *
204
+     * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
205
+     */
206
+    public function getStatus($file) {
207
+        return $this->getCache()->getStatus($this->getSourcePath($file));
208
+    }
209
+
210
+    private function formatSearchResults($results) {
211
+        $results = array_filter($results, array($this, 'filterCacheEntry'));
212
+        $results = array_values($results);
213
+        return array_map(array($this, 'formatCacheEntry'), $results);
214
+    }
215
+
216
+    /**
217
+     * search for files matching $pattern
218
+     *
219
+     * @param string $pattern
220
+     * @return array an array of file data
221
+     */
222
+    public function search($pattern) {
223
+        $results = $this->getCache()->search($pattern);
224
+        return $this->formatSearchResults($results);
225
+    }
226
+
227
+    /**
228
+     * search for files by mimetype
229
+     *
230
+     * @param string $mimetype
231
+     * @return array
232
+     */
233
+    public function searchByMime($mimetype) {
234
+        $results = $this->getCache()->searchByMime($mimetype);
235
+        return $this->formatSearchResults($results);
236
+    }
237
+
238
+    public function searchQuery(ISearchQuery $query) {
239
+        $results = $this->getCache()->searchQuery($query);
240
+        return $this->formatSearchResults($results);
241
+    }
242
+
243
+    /**
244
+     * search for files by mimetype
245
+     *
246
+     * @param string|int $tag name or tag id
247
+     * @param string $userId owner of the tags
248
+     * @return array
249
+     */
250
+    public function searchByTag($tag, $userId) {
251
+        $results = $this->getCache()->searchByTag($tag, $userId);
252
+        return $this->formatSearchResults($results);
253
+    }
254
+
255
+    /**
256
+     * update the folder size and the size of all parent folders
257
+     *
258
+     * @param string|boolean $path
259
+     * @param array $data (optional) meta data of the folder
260
+     */
261
+    public function correctFolderSize($path, $data = null) {
262
+        if ($this->getCache() instanceof Cache) {
263
+            $this->getCache()->correctFolderSize($this->getSourcePath($path), $data);
264
+        }
265
+    }
266
+
267
+    /**
268
+     * get the size of a folder and set it in the cache
269
+     *
270
+     * @param string $path
271
+     * @param array $entry (optional) meta data of the folder
272
+     * @return int
273
+     */
274
+    public function calculateFolderSize($path, $entry = null) {
275
+        if ($this->getCache() instanceof Cache) {
276
+            return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry);
277
+        } else {
278
+            return 0;
279
+        }
280
+
281
+    }
282
+
283
+    /**
284
+     * get all file ids on the files on the storage
285
+     *
286
+     * @return int[]
287
+     */
288
+    public function getAll() {
289
+        // not supported
290
+        return array();
291
+    }
292
+
293
+    /**
294
+     * find a folder in the cache which has not been fully scanned
295
+     *
296
+     * If multiply incomplete folders are in the cache, the one with the highest id will be returned,
297
+     * use the one with the highest id gives the best result with the background scanner, since that is most
298
+     * likely the folder where we stopped scanning previously
299
+     *
300
+     * @return string|bool the path of the folder or false when no folder matched
301
+     */
302
+    public function getIncomplete() {
303
+        // not supported
304
+        return false;
305
+    }
306
+
307
+    /**
308
+     * get the path of a file on this storage by it's id
309
+     *
310
+     * @param int $id
311
+     * @return string|null
312
+     */
313
+    public function getPathById($id) {
314
+        $path = $this->getCache()->getPathById($id);
315
+        return $this->getJailedPath($path);
316
+    }
317
+
318
+    /**
319
+     * Move a file or folder in the cache
320
+     *
321
+     * Note that this should make sure the entries are removed from the source cache
322
+     *
323
+     * @param \OCP\Files\Cache\ICache $sourceCache
324
+     * @param string $sourcePath
325
+     * @param string $targetPath
326
+     */
327
+    public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
328
+        if ($sourceCache === $this) {
329
+            return $this->move($sourcePath, $targetPath);
330
+        }
331
+        return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath));
332
+    }
333 333
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 		if ($path === '') {
59 59
 			return $this->getRoot();
60 60
 		} else {
61
-			return $this->getRoot() . '/' . ltrim($path, '/');
61
+			return $this->getRoot().'/'.ltrim($path, '/');
62 62
 		}
63 63
 	}
64 64
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		$rootLength = strlen($this->getRoot()) + 1;
74 74
 		if ($path === $this->getRoot()) {
75 75
 			return '';
76
-		} else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') {
76
+		} else if (substr($path, 0, $rootLength) === $this->getRoot().'/') {
77 77
 			return substr($path, $rootLength);
78 78
 		} else {
79 79
 			return null;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
 	protected function filterCacheEntry($entry) {
95 95
 		$rootLength = strlen($this->getRoot()) + 1;
96
-		return ($entry['path'] === $this->getRoot()) or (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/');
96
+		return ($entry['path'] === $this->getRoot()) or (substr($entry['path'], 0, $rootLength) === $this->getRoot().'/');
97 97
 	}
98 98
 
99 99
 	/**
Please login to merge, or discard this patch.