Completed
Pull Request — master (#4001)
by Joas
25:04 queued 11:45
created
lib/public/Files/FileInfo.php 1 patch
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -33,229 +33,229 @@
 block discarded – undo
33 33
  * @since 7.0.0
34 34
  */
35 35
 interface FileInfo {
36
-	/**
37
-	 * @since 7.0.0
38
-	 */
39
-	const TYPE_FILE = 'file';
40
-	/**
41
-	 * @since 7.0.0
42
-	 */
43
-	const TYPE_FOLDER = 'dir';
36
+    /**
37
+     * @since 7.0.0
38
+     */
39
+    const TYPE_FILE = 'file';
40
+    /**
41
+     * @since 7.0.0
42
+     */
43
+    const TYPE_FOLDER = 'dir';
44 44
 
45
-	/**
46
-	 * @const \OCP\Files\FileInfo::SPACE_NOT_COMPUTED Return value for a not computed space value
47
-	 * @since 8.0.0
48
-	 */
49
-	const SPACE_NOT_COMPUTED = -1;
50
-	/**
51
-	 * @const \OCP\Files\FileInfo::SPACE_UNKNOWN Return value for unknown space value
52
-	 * @since 8.0.0
53
-	 */
54
-	const SPACE_UNKNOWN = -2;
55
-	/**
56
-	 * @const \OCP\Files\FileInfo::SPACE_UNLIMITED Return value for unlimited space
57
-	 * @since 8.0.0
58
-	 */
59
-	const SPACE_UNLIMITED = -3;
45
+    /**
46
+     * @const \OCP\Files\FileInfo::SPACE_NOT_COMPUTED Return value for a not computed space value
47
+     * @since 8.0.0
48
+     */
49
+    const SPACE_NOT_COMPUTED = -1;
50
+    /**
51
+     * @const \OCP\Files\FileInfo::SPACE_UNKNOWN Return value for unknown space value
52
+     * @since 8.0.0
53
+     */
54
+    const SPACE_UNKNOWN = -2;
55
+    /**
56
+     * @const \OCP\Files\FileInfo::SPACE_UNLIMITED Return value for unlimited space
57
+     * @since 8.0.0
58
+     */
59
+    const SPACE_UNLIMITED = -3;
60 60
 
61
-	/**
62
-	 * @since 9.1.0
63
-	 */
64
-	const MIMETYPE_FOLDER = 'httpd/unix-directory';
61
+    /**
62
+     * @since 9.1.0
63
+     */
64
+    const MIMETYPE_FOLDER = 'httpd/unix-directory';
65 65
 
66
-	/**
67
-	 * @const \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX Return regular expression to test filenames against (blacklisting)
68
-	 * @since 12.0.0
69
-	 */
70
-	const BLACKLIST_FILES_REGEX = '\.(part|filepart)$';
66
+    /**
67
+     * @const \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX Return regular expression to test filenames against (blacklisting)
68
+     * @since 12.0.0
69
+     */
70
+    const BLACKLIST_FILES_REGEX = '\.(part|filepart)$';
71 71
 
72
-	/**
73
-	 * Get the Etag of the file or folder
74
-	 *
75
-	 * @return string
76
-	 * @since 7.0.0
77
-	 */
78
-	public function getEtag();
72
+    /**
73
+     * Get the Etag of the file or folder
74
+     *
75
+     * @return string
76
+     * @since 7.0.0
77
+     */
78
+    public function getEtag();
79 79
 
80
-	/**
81
-	 * Get the size in bytes for the file or folder
82
-	 *
83
-	 * @return int
84
-	 * @since 7.0.0
85
-	 */
86
-	public function getSize();
80
+    /**
81
+     * Get the size in bytes for the file or folder
82
+     *
83
+     * @return int
84
+     * @since 7.0.0
85
+     */
86
+    public function getSize();
87 87
 
88
-	/**
89
-	 * Get the last modified date as timestamp for the file or folder
90
-	 *
91
-	 * @return int
92
-	 * @since 7.0.0
93
-	 */
94
-	public function getMtime();
88
+    /**
89
+     * Get the last modified date as timestamp for the file or folder
90
+     *
91
+     * @return int
92
+     * @since 7.0.0
93
+     */
94
+    public function getMtime();
95 95
 
96
-	/**
97
-	 * Get the name of the file or folder
98
-	 *
99
-	 * @return string
100
-	 * @since 7.0.0
101
-	 */
102
-	public function getName();
96
+    /**
97
+     * Get the name of the file or folder
98
+     *
99
+     * @return string
100
+     * @since 7.0.0
101
+     */
102
+    public function getName();
103 103
 
104
-	/**
105
-	 * Get the path relative to the storage
106
-	 *
107
-	 * @return string
108
-	 * @since 7.0.0
109
-	 */
110
-	public function getInternalPath();
104
+    /**
105
+     * Get the path relative to the storage
106
+     *
107
+     * @return string
108
+     * @since 7.0.0
109
+     */
110
+    public function getInternalPath();
111 111
 
112
-	/**
113
-	 * Get the absolute path
114
-	 *
115
-	 * @return string
116
-	 * @since 7.0.0
117
-	 */
118
-	public function getPath();
112
+    /**
113
+     * Get the absolute path
114
+     *
115
+     * @return string
116
+     * @since 7.0.0
117
+     */
118
+    public function getPath();
119 119
 
120
-	/**
121
-	 * Get the full mimetype of the file or folder i.e. 'image/png'
122
-	 *
123
-	 * @return string
124
-	 * @since 7.0.0
125
-	 */
126
-	public function getMimetype();
120
+    /**
121
+     * Get the full mimetype of the file or folder i.e. 'image/png'
122
+     *
123
+     * @return string
124
+     * @since 7.0.0
125
+     */
126
+    public function getMimetype();
127 127
 
128
-	/**
129
-	 * Get the first part of the mimetype of the file or folder i.e. 'image'
130
-	 *
131
-	 * @return string
132
-	 * @since 7.0.0
133
-	 */
134
-	public function getMimePart();
128
+    /**
129
+     * Get the first part of the mimetype of the file or folder i.e. 'image'
130
+     *
131
+     * @return string
132
+     * @since 7.0.0
133
+     */
134
+    public function getMimePart();
135 135
 
136
-	/**
137
-	 * Get the storage the file or folder is storage on
138
-	 *
139
-	 * @return \OCP\Files\Storage
140
-	 * @since 7.0.0
141
-	 */
142
-	public function getStorage();
136
+    /**
137
+     * Get the storage the file or folder is storage on
138
+     *
139
+     * @return \OCP\Files\Storage
140
+     * @since 7.0.0
141
+     */
142
+    public function getStorage();
143 143
 
144
-	/**
145
-	 * Get the file id of the file or folder
146
-	 *
147
-	 * @return int|null
148
-	 * @since 7.0.0
149
-	 */
150
-	public function getId();
144
+    /**
145
+     * Get the file id of the file or folder
146
+     *
147
+     * @return int|null
148
+     * @since 7.0.0
149
+     */
150
+    public function getId();
151 151
 
152
-	/**
153
-	 * Check whether the file is encrypted
154
-	 *
155
-	 * @return bool
156
-	 * @since 7.0.0
157
-	 */
158
-	public function isEncrypted();
152
+    /**
153
+     * Check whether the file is encrypted
154
+     *
155
+     * @return bool
156
+     * @since 7.0.0
157
+     */
158
+    public function isEncrypted();
159 159
 
160
-	/**
161
-	 * Get the permissions of the file or folder as bitmasked combination of the following constants
162
-	 * \OCP\Constants::PERMISSION_CREATE
163
-	 * \OCP\Constants::PERMISSION_READ
164
-	 * \OCP\Constants::PERMISSION_UPDATE
165
-	 * \OCP\Constants::PERMISSION_DELETE
166
-	 * \OCP\Constants::PERMISSION_SHARE
167
-	 * \OCP\Constants::PERMISSION_ALL
168
-	 *
169
-	 * @return int
170
-	 * @since 7.0.0 - namespace of constants has changed in 8.0.0
171
-	 */
172
-	public function getPermissions();
160
+    /**
161
+     * Get the permissions of the file or folder as bitmasked combination of the following constants
162
+     * \OCP\Constants::PERMISSION_CREATE
163
+     * \OCP\Constants::PERMISSION_READ
164
+     * \OCP\Constants::PERMISSION_UPDATE
165
+     * \OCP\Constants::PERMISSION_DELETE
166
+     * \OCP\Constants::PERMISSION_SHARE
167
+     * \OCP\Constants::PERMISSION_ALL
168
+     *
169
+     * @return int
170
+     * @since 7.0.0 - namespace of constants has changed in 8.0.0
171
+     */
172
+    public function getPermissions();
173 173
 
174
-	/**
175
-	 * Check whether this is a file or a folder
176
-	 *
177
-	 * @return \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
178
-	 * @since 7.0.0
179
-	 */
180
-	public function getType();
174
+    /**
175
+     * Check whether this is a file or a folder
176
+     *
177
+     * @return \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
178
+     * @since 7.0.0
179
+     */
180
+    public function getType();
181 181
 
182
-	/**
183
-	 * Check if the file or folder is readable
184
-	 *
185
-	 * @return bool
186
-	 * @since 7.0.0
187
-	 */
188
-	public function isReadable();
182
+    /**
183
+     * Check if the file or folder is readable
184
+     *
185
+     * @return bool
186
+     * @since 7.0.0
187
+     */
188
+    public function isReadable();
189 189
 
190
-	/**
191
-	 * Check if a file is writable
192
-	 *
193
-	 * @return bool
194
-	 * @since 7.0.0
195
-	 */
196
-	public function isUpdateable();
190
+    /**
191
+     * Check if a file is writable
192
+     *
193
+     * @return bool
194
+     * @since 7.0.0
195
+     */
196
+    public function isUpdateable();
197 197
 
198
-	/**
199
-	 * Check whether new files or folders can be created inside this folder
200
-	 *
201
-	 * @return bool
202
-	 * @since 8.0.0
203
-	 */
204
-	public function isCreatable();
198
+    /**
199
+     * Check whether new files or folders can be created inside this folder
200
+     *
201
+     * @return bool
202
+     * @since 8.0.0
203
+     */
204
+    public function isCreatable();
205 205
 
206
-	/**
207
-	 * Check if a file or folder can be deleted
208
-	 *
209
-	 * @return bool
210
-	 * @since 7.0.0
211
-	 */
212
-	public function isDeletable();
206
+    /**
207
+     * Check if a file or folder can be deleted
208
+     *
209
+     * @return bool
210
+     * @since 7.0.0
211
+     */
212
+    public function isDeletable();
213 213
 
214
-	/**
215
-	 * Check if a file or folder can be shared
216
-	 *
217
-	 * @return bool
218
-	 * @since 7.0.0
219
-	 */
220
-	public function isShareable();
214
+    /**
215
+     * Check if a file or folder can be shared
216
+     *
217
+     * @return bool
218
+     * @since 7.0.0
219
+     */
220
+    public function isShareable();
221 221
 
222
-	/**
223
-	 * Check if a file or folder is shared
224
-	 *
225
-	 * @return bool
226
-	 * @since 7.0.0
227
-	 */
228
-	public function isShared();
222
+    /**
223
+     * Check if a file or folder is shared
224
+     *
225
+     * @return bool
226
+     * @since 7.0.0
227
+     */
228
+    public function isShared();
229 229
 
230
-	/**
231
-	 * Check if a file or folder is mounted
232
-	 *
233
-	 * @return bool
234
-	 * @since 7.0.0
235
-	 */
236
-	public function isMounted();
230
+    /**
231
+     * Check if a file or folder is mounted
232
+     *
233
+     * @return bool
234
+     * @since 7.0.0
235
+     */
236
+    public function isMounted();
237 237
 
238
-	/**
239
-	 * Get the mountpoint the file belongs to
240
-	 *
241
-	 * @return \OCP\Files\Mount\IMountPoint
242
-	 * @since 8.0.0
243
-	 */
244
-	public function getMountPoint();
238
+    /**
239
+     * Get the mountpoint the file belongs to
240
+     *
241
+     * @return \OCP\Files\Mount\IMountPoint
242
+     * @since 8.0.0
243
+     */
244
+    public function getMountPoint();
245 245
 
246
-	/**
247
-	 * Get the owner of the file
248
-	 *
249
-	 * @return \OCP\IUser
250
-	 * @since 9.0.0
251
-	 */
252
-	public function getOwner();
246
+    /**
247
+     * Get the owner of the file
248
+     *
249
+     * @return \OCP\IUser
250
+     * @since 9.0.0
251
+     */
252
+    public function getOwner();
253 253
 
254
-	/**
255
-	 * Get the stored checksum for this file
256
-	 *
257
-	 * @return string
258
-	 * @since 9.0.0
259
-	 */
260
-	public function getChecksum();
254
+    /**
255
+     * Get the stored checksum for this file
256
+     *
257
+     * @return string
258
+     * @since 9.0.0
259
+     */
260
+    public function getChecksum();
261 261
 }
Please login to merge, or discard this patch.
lib/private/Files/FileInfo.php 2 patches
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -37,356 +37,356 @@
 block discarded – undo
37 37
 use OCP\IUser;
38 38
 
39 39
 class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
40
-	/**
41
-	 * @var array $data
42
-	 */
43
-	private $data;
44
-
45
-	/**
46
-	 * @var string $path
47
-	 */
48
-	private $path;
49
-
50
-	/**
51
-	 * @var \OC\Files\Storage\Storage $storage
52
-	 */
53
-	private $storage;
54
-
55
-	/**
56
-	 * @var string $internalPath
57
-	 */
58
-	private $internalPath;
59
-
60
-	/**
61
-	 * @var \OCP\Files\Mount\IMountPoint
62
-	 */
63
-	private $mount;
64
-
65
-	/**
66
-	 * @var IUser
67
-	 */
68
-	private $owner;
69
-
70
-	/**
71
-	 * @var string[]
72
-	 */
73
-	private $childEtags = [];
74
-
75
-	/**
76
-	 * @var IMountPoint[]
77
-	 */
78
-	private $subMounts = [];
79
-
80
-	private $subMountsUsed = false;
81
-
82
-	/**
83
-	 * @param string|boolean $path
84
-	 * @param Storage\Storage $storage
85
-	 * @param string $internalPath
86
-	 * @param array|ICacheEntry $data
87
-	 * @param \OCP\Files\Mount\IMountPoint $mount
88
-	 * @param \OCP\IUser|null $owner
89
-	 */
90
-	public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) {
91
-		$this->path = $path;
92
-		$this->storage = $storage;
93
-		$this->internalPath = $internalPath;
94
-		$this->data = $data;
95
-		$this->mount = $mount;
96
-		$this->owner = $owner;
97
-	}
98
-
99
-	public function offsetSet($offset, $value) {
100
-		$this->data[$offset] = $value;
101
-	}
102
-
103
-	public function offsetExists($offset) {
104
-		return isset($this->data[$offset]);
105
-	}
106
-
107
-	public function offsetUnset($offset) {
108
-		unset($this->data[$offset]);
109
-	}
110
-
111
-	public function offsetGet($offset) {
112
-		if ($offset === 'type') {
113
-			return $this->getType();
114
-		} else if ($offset === 'etag') {
115
-			return $this->getEtag();
116
-		} else if ($offset === 'size') {
117
-			return $this->getSize();
118
-		} else if ($offset === 'mtime') {
119
-			return $this->getMTime();
120
-		} elseif ($offset === 'permissions') {
121
-			return $this->getPermissions();
122
-		} elseif (isset($this->data[$offset])) {
123
-			return $this->data[$offset];
124
-		} else {
125
-			return null;
126
-		}
127
-	}
128
-
129
-	/**
130
-	 * @return string
131
-	 */
132
-	public function getPath() {
133
-		return $this->path;
134
-	}
135
-
136
-	/**
137
-	 * @return \OCP\Files\Storage
138
-	 */
139
-	public function getStorage() {
140
-		return $this->storage;
141
-	}
142
-
143
-	/**
144
-	 * @return string
145
-	 */
146
-	public function getInternalPath() {
147
-		return $this->internalPath;
148
-	}
149
-
150
-	/**
151
-	 * Get FileInfo ID or null in case of part file
152
-	 *
153
-	 * @return int|null
154
-	 */
155
-	public function getId() {
156
-		return isset($this->data['fileid']) ? (int)  $this->data['fileid'] : null;
157
-	}
158
-
159
-	/**
160
-	 * @return string
161
-	 */
162
-	public function getMimetype() {
163
-		return $this->data['mimetype'];
164
-	}
165
-
166
-	/**
167
-	 * @return string
168
-	 */
169
-	public function getMimePart() {
170
-		return $this->data['mimepart'];
171
-	}
172
-
173
-	/**
174
-	 * @return string
175
-	 */
176
-	public function getName() {
177
-		return basename($this->getPath());
178
-	}
179
-
180
-	/**
181
-	 * @return string
182
-	 */
183
-	public function getEtag() {
184
-		$this->updateEntryfromSubMounts();
185
-		if (count($this->childEtags) > 0) {
186
-			$combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
187
-			return md5($combinedEtag);
188
-		} else {
189
-			return $this->data['etag'];
190
-		}
191
-	}
192
-
193
-	/**
194
-	 * @return int
195
-	 */
196
-	public function getSize() {
197
-		$this->updateEntryfromSubMounts();
198
-		return isset($this->data['size']) ? (int) $this->data['size'] : 0;
199
-	}
200
-
201
-	/**
202
-	 * @return int
203
-	 */
204
-	public function getMTime() {
205
-		$this->updateEntryfromSubMounts();
206
-		return (int) $this->data['mtime'];
207
-	}
208
-
209
-	/**
210
-	 * @return bool
211
-	 */
212
-	public function isEncrypted() {
213
-		return $this->data['encrypted'];
214
-	}
215
-
216
-	/**
217
-	 * Return the currently version used for the HMAC in the encryption app
218
-	 *
219
-	 * @return int
220
-	 */
221
-	public function getEncryptedVersion() {
222
-		return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1;
223
-	}
224
-
225
-	/**
226
-	 * @return int
227
-	 */
228
-	public function getPermissions() {
229
-		$perms = (int) $this->data['permissions'];
230
-		if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) {
231
-			$perms = $perms & ~\OCP\Constants::PERMISSION_SHARE;
232
-		}
233
-		return (int) $perms;
234
-	}
235
-
236
-	/**
237
-	 * @return \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
238
-	 */
239
-	public function getType() {
240
-		if (!isset($this->data['type'])) {
241
-			$this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE;
242
-		}
243
-		return $this->data['type'];
244
-	}
245
-
246
-	public function getData() {
247
-		return $this->data;
248
-	}
249
-
250
-	/**
251
-	 * @param int $permissions
252
-	 * @return bool
253
-	 */
254
-	protected function checkPermissions($permissions) {
255
-		return ($this->getPermissions() & $permissions) === $permissions;
256
-	}
257
-
258
-	/**
259
-	 * @return bool
260
-	 */
261
-	public function isReadable() {
262
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_READ);
263
-	}
264
-
265
-	/**
266
-	 * @return bool
267
-	 */
268
-	public function isUpdateable() {
269
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE);
270
-	}
271
-
272
-	/**
273
-	 * Check whether new files or folders can be created inside this folder
274
-	 *
275
-	 * @return bool
276
-	 */
277
-	public function isCreatable() {
278
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE);
279
-	}
280
-
281
-	/**
282
-	 * @return bool
283
-	 */
284
-	public function isDeletable() {
285
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE);
286
-	}
287
-
288
-	/**
289
-	 * @return bool
290
-	 */
291
-	public function isShareable() {
292
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE);
293
-	}
294
-
295
-	/**
296
-	 * Check if a file or folder is shared
297
-	 *
298
-	 * @return bool
299
-	 */
300
-	public function isShared() {
301
-		$sid = $this->getStorage()->getId();
302
-		if (!is_null($sid)) {
303
-			$sid = explode(':', $sid);
304
-			return ($sid[0] === 'shared');
305
-		}
306
-
307
-		return false;
308
-	}
309
-
310
-	public function isMounted() {
311
-		$storage = $this->getStorage();
312
-		if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
313
-			return false;
314
-		}
315
-		$sid = $storage->getId();
316
-		if (!is_null($sid)) {
317
-			$sid = explode(':', $sid);
318
-			return ($sid[0] !== 'home' and $sid[0] !== 'shared');
319
-		}
320
-
321
-		return false;
322
-	}
323
-
324
-	/**
325
-	 * Get the mountpoint the file belongs to
326
-	 *
327
-	 * @return \OCP\Files\Mount\IMountPoint
328
-	 */
329
-	public function getMountPoint() {
330
-		return $this->mount;
331
-	}
332
-
333
-	/**
334
-	 * Get the owner of the file
335
-	 *
336
-	 * @return \OCP\IUser
337
-	 */
338
-	public function getOwner() {
339
-		return $this->owner;
340
-	}
341
-
342
-	/**
343
-	 * @param IMountPoint[] $mounts
344
-	 */
345
-	public function setSubMounts(array $mounts) {
346
-		$this->subMounts = $mounts;
347
-	}
348
-
349
-	private function updateEntryfromSubMounts() {
350
-		if ($this->subMountsUsed) {
351
-			return;
352
-		}
353
-		$this->subMountsUsed = true;
354
-		foreach ($this->subMounts as $mount) {
355
-			$subStorage = $mount->getStorage();
356
-			if ($subStorage) {
357
-				$subCache = $subStorage->getCache('');
358
-				$rootEntry = $subCache->get('');
359
-				$this->addSubEntry($rootEntry, $mount->getMountPoint());
360
-			}
361
-		}
362
-	}
363
-
364
-	/**
365
-	 * Add a cache entry which is the child of this folder
366
-	 *
367
-	 * Sets the size, etag and size to for cross-storage childs
368
-	 *
369
-	 * @param array|ICacheEntry $data cache entry for the child
370
-	 * @param string $entryPath full path of the child entry
371
-	 */
372
-	public function addSubEntry($data, $entryPath) {
373
-		$this->data['size'] += isset($data['size']) ? $data['size'] : 0;
374
-		if (isset($data['mtime'])) {
375
-			$this->data['mtime'] = max($this->data['mtime'], $data['mtime']);
376
-		}
377
-		if (isset($data['etag'])) {
378
-			// prefix the etag with the relative path of the subentry to propagate etag on mount moves
379
-			$relativeEntryPath = substr($entryPath, strlen($this->getPath()));
380
-			// attach the permissions to propagate etag on permision changes of submounts
381
-			$permissions = isset($data['permissions']) ? $data['permissions'] : 0;
382
-			$this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
383
-		}
384
-	}
385
-
386
-	/**
387
-	 * @inheritdoc
388
-	 */
389
-	public function getChecksum() {
390
-		return $this->data['checksum'];
391
-	}
40
+    /**
41
+     * @var array $data
42
+     */
43
+    private $data;
44
+
45
+    /**
46
+     * @var string $path
47
+     */
48
+    private $path;
49
+
50
+    /**
51
+     * @var \OC\Files\Storage\Storage $storage
52
+     */
53
+    private $storage;
54
+
55
+    /**
56
+     * @var string $internalPath
57
+     */
58
+    private $internalPath;
59
+
60
+    /**
61
+     * @var \OCP\Files\Mount\IMountPoint
62
+     */
63
+    private $mount;
64
+
65
+    /**
66
+     * @var IUser
67
+     */
68
+    private $owner;
69
+
70
+    /**
71
+     * @var string[]
72
+     */
73
+    private $childEtags = [];
74
+
75
+    /**
76
+     * @var IMountPoint[]
77
+     */
78
+    private $subMounts = [];
79
+
80
+    private $subMountsUsed = false;
81
+
82
+    /**
83
+     * @param string|boolean $path
84
+     * @param Storage\Storage $storage
85
+     * @param string $internalPath
86
+     * @param array|ICacheEntry $data
87
+     * @param \OCP\Files\Mount\IMountPoint $mount
88
+     * @param \OCP\IUser|null $owner
89
+     */
90
+    public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) {
91
+        $this->path = $path;
92
+        $this->storage = $storage;
93
+        $this->internalPath = $internalPath;
94
+        $this->data = $data;
95
+        $this->mount = $mount;
96
+        $this->owner = $owner;
97
+    }
98
+
99
+    public function offsetSet($offset, $value) {
100
+        $this->data[$offset] = $value;
101
+    }
102
+
103
+    public function offsetExists($offset) {
104
+        return isset($this->data[$offset]);
105
+    }
106
+
107
+    public function offsetUnset($offset) {
108
+        unset($this->data[$offset]);
109
+    }
110
+
111
+    public function offsetGet($offset) {
112
+        if ($offset === 'type') {
113
+            return $this->getType();
114
+        } else if ($offset === 'etag') {
115
+            return $this->getEtag();
116
+        } else if ($offset === 'size') {
117
+            return $this->getSize();
118
+        } else if ($offset === 'mtime') {
119
+            return $this->getMTime();
120
+        } elseif ($offset === 'permissions') {
121
+            return $this->getPermissions();
122
+        } elseif (isset($this->data[$offset])) {
123
+            return $this->data[$offset];
124
+        } else {
125
+            return null;
126
+        }
127
+    }
128
+
129
+    /**
130
+     * @return string
131
+     */
132
+    public function getPath() {
133
+        return $this->path;
134
+    }
135
+
136
+    /**
137
+     * @return \OCP\Files\Storage
138
+     */
139
+    public function getStorage() {
140
+        return $this->storage;
141
+    }
142
+
143
+    /**
144
+     * @return string
145
+     */
146
+    public function getInternalPath() {
147
+        return $this->internalPath;
148
+    }
149
+
150
+    /**
151
+     * Get FileInfo ID or null in case of part file
152
+     *
153
+     * @return int|null
154
+     */
155
+    public function getId() {
156
+        return isset($this->data['fileid']) ? (int)  $this->data['fileid'] : null;
157
+    }
158
+
159
+    /**
160
+     * @return string
161
+     */
162
+    public function getMimetype() {
163
+        return $this->data['mimetype'];
164
+    }
165
+
166
+    /**
167
+     * @return string
168
+     */
169
+    public function getMimePart() {
170
+        return $this->data['mimepart'];
171
+    }
172
+
173
+    /**
174
+     * @return string
175
+     */
176
+    public function getName() {
177
+        return basename($this->getPath());
178
+    }
179
+
180
+    /**
181
+     * @return string
182
+     */
183
+    public function getEtag() {
184
+        $this->updateEntryfromSubMounts();
185
+        if (count($this->childEtags) > 0) {
186
+            $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
187
+            return md5($combinedEtag);
188
+        } else {
189
+            return $this->data['etag'];
190
+        }
191
+    }
192
+
193
+    /**
194
+     * @return int
195
+     */
196
+    public function getSize() {
197
+        $this->updateEntryfromSubMounts();
198
+        return isset($this->data['size']) ? (int) $this->data['size'] : 0;
199
+    }
200
+
201
+    /**
202
+     * @return int
203
+     */
204
+    public function getMTime() {
205
+        $this->updateEntryfromSubMounts();
206
+        return (int) $this->data['mtime'];
207
+    }
208
+
209
+    /**
210
+     * @return bool
211
+     */
212
+    public function isEncrypted() {
213
+        return $this->data['encrypted'];
214
+    }
215
+
216
+    /**
217
+     * Return the currently version used for the HMAC in the encryption app
218
+     *
219
+     * @return int
220
+     */
221
+    public function getEncryptedVersion() {
222
+        return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1;
223
+    }
224
+
225
+    /**
226
+     * @return int
227
+     */
228
+    public function getPermissions() {
229
+        $perms = (int) $this->data['permissions'];
230
+        if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) {
231
+            $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE;
232
+        }
233
+        return (int) $perms;
234
+    }
235
+
236
+    /**
237
+     * @return \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
238
+     */
239
+    public function getType() {
240
+        if (!isset($this->data['type'])) {
241
+            $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE;
242
+        }
243
+        return $this->data['type'];
244
+    }
245
+
246
+    public function getData() {
247
+        return $this->data;
248
+    }
249
+
250
+    /**
251
+     * @param int $permissions
252
+     * @return bool
253
+     */
254
+    protected function checkPermissions($permissions) {
255
+        return ($this->getPermissions() & $permissions) === $permissions;
256
+    }
257
+
258
+    /**
259
+     * @return bool
260
+     */
261
+    public function isReadable() {
262
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_READ);
263
+    }
264
+
265
+    /**
266
+     * @return bool
267
+     */
268
+    public function isUpdateable() {
269
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE);
270
+    }
271
+
272
+    /**
273
+     * Check whether new files or folders can be created inside this folder
274
+     *
275
+     * @return bool
276
+     */
277
+    public function isCreatable() {
278
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE);
279
+    }
280
+
281
+    /**
282
+     * @return bool
283
+     */
284
+    public function isDeletable() {
285
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE);
286
+    }
287
+
288
+    /**
289
+     * @return bool
290
+     */
291
+    public function isShareable() {
292
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE);
293
+    }
294
+
295
+    /**
296
+     * Check if a file or folder is shared
297
+     *
298
+     * @return bool
299
+     */
300
+    public function isShared() {
301
+        $sid = $this->getStorage()->getId();
302
+        if (!is_null($sid)) {
303
+            $sid = explode(':', $sid);
304
+            return ($sid[0] === 'shared');
305
+        }
306
+
307
+        return false;
308
+    }
309
+
310
+    public function isMounted() {
311
+        $storage = $this->getStorage();
312
+        if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
313
+            return false;
314
+        }
315
+        $sid = $storage->getId();
316
+        if (!is_null($sid)) {
317
+            $sid = explode(':', $sid);
318
+            return ($sid[0] !== 'home' and $sid[0] !== 'shared');
319
+        }
320
+
321
+        return false;
322
+    }
323
+
324
+    /**
325
+     * Get the mountpoint the file belongs to
326
+     *
327
+     * @return \OCP\Files\Mount\IMountPoint
328
+     */
329
+    public function getMountPoint() {
330
+        return $this->mount;
331
+    }
332
+
333
+    /**
334
+     * Get the owner of the file
335
+     *
336
+     * @return \OCP\IUser
337
+     */
338
+    public function getOwner() {
339
+        return $this->owner;
340
+    }
341
+
342
+    /**
343
+     * @param IMountPoint[] $mounts
344
+     */
345
+    public function setSubMounts(array $mounts) {
346
+        $this->subMounts = $mounts;
347
+    }
348
+
349
+    private function updateEntryfromSubMounts() {
350
+        if ($this->subMountsUsed) {
351
+            return;
352
+        }
353
+        $this->subMountsUsed = true;
354
+        foreach ($this->subMounts as $mount) {
355
+            $subStorage = $mount->getStorage();
356
+            if ($subStorage) {
357
+                $subCache = $subStorage->getCache('');
358
+                $rootEntry = $subCache->get('');
359
+                $this->addSubEntry($rootEntry, $mount->getMountPoint());
360
+            }
361
+        }
362
+    }
363
+
364
+    /**
365
+     * Add a cache entry which is the child of this folder
366
+     *
367
+     * Sets the size, etag and size to for cross-storage childs
368
+     *
369
+     * @param array|ICacheEntry $data cache entry for the child
370
+     * @param string $entryPath full path of the child entry
371
+     */
372
+    public function addSubEntry($data, $entryPath) {
373
+        $this->data['size'] += isset($data['size']) ? $data['size'] : 0;
374
+        if (isset($data['mtime'])) {
375
+            $this->data['mtime'] = max($this->data['mtime'], $data['mtime']);
376
+        }
377
+        if (isset($data['etag'])) {
378
+            // prefix the etag with the relative path of the subentry to propagate etag on mount moves
379
+            $relativeEntryPath = substr($entryPath, strlen($this->getPath()));
380
+            // attach the permissions to propagate etag on permision changes of submounts
381
+            $permissions = isset($data['permissions']) ? $data['permissions'] : 0;
382
+            $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
383
+        }
384
+    }
385
+
386
+    /**
387
+     * @inheritdoc
388
+     */
389
+    public function getChecksum() {
390
+        return $this->data['checksum'];
391
+    }
392 392
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @param \OCP\Files\Mount\IMountPoint $mount
88 88
 	 * @param \OCP\IUser|null $owner
89 89
 	 */
90
-	public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) {
90
+	public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) {
91 91
 		$this->path = $path;
92 92
 		$this->storage = $storage;
93 93
 		$this->internalPath = $internalPath;
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @return int|null
154 154
 	 */
155 155
 	public function getId() {
156
-		return isset($this->data['fileid']) ? (int)  $this->data['fileid'] : null;
156
+		return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null;
157 157
 	}
158 158
 
159 159
 	/**
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	public function getEtag() {
184 184
 		$this->updateEntryfromSubMounts();
185 185
 		if (count($this->childEtags) > 0) {
186
-			$combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
186
+			$combinedEtag = $this->data['etag'].'::'.implode('::', $this->childEtags);
187 187
 			return md5($combinedEtag);
188 188
 		} else {
189 189
 			return $this->data['etag'];
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 			$relativeEntryPath = substr($entryPath, strlen($this->getPath()));
380 380
 			// attach the permissions to propagate etag on permision changes of submounts
381 381
 			$permissions = isset($data['permissions']) ? $data['permissions'] : 0;
382
-			$this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
382
+			$this->childEtags[] = $relativeEntryPath.'/'.$data['etag'].$permissions;
383 383
 		}
384 384
 	}
385 385
 
Please login to merge, or discard this patch.