Completed
Push — master ( dc7681...057c0d )
by
unknown
28:08
created
lib/public/Files/FileInfo.php 1 patch
Indentation   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -17,285 +17,285 @@
 block discarded – undo
17 17
  */
18 18
 #[Consumable(since: '7.0.0')]
19 19
 interface FileInfo {
20
-	/**
21
-	 * @since 7.0.0
22
-	 */
23
-	public const TYPE_FILE = 'file';
24
-	/**
25
-	 * @since 7.0.0
26
-	 */
27
-	public const TYPE_FOLDER = 'dir';
28
-
29
-	/**
30
-	 * @const \OCP\Files\FileInfo::SPACE_NOT_COMPUTED Return value for a not computed space value
31
-	 * @since 8.0.0
32
-	 */
33
-	public const SPACE_NOT_COMPUTED = -1;
34
-	/**
35
-	 * @const \OCP\Files\FileInfo::SPACE_UNKNOWN Return value for unknown space value
36
-	 * @since 8.0.0
37
-	 */
38
-	public const SPACE_UNKNOWN = -2;
39
-	/**
40
-	 * @const \OCP\Files\FileInfo::SPACE_UNLIMITED Return value for unlimited space
41
-	 * @since 8.0.0
42
-	 */
43
-	public const SPACE_UNLIMITED = -3;
44
-
45
-	/**
46
-	 * @since 9.1.0
47
-	 */
48
-	public const MIMETYPE_FOLDER = 'httpd/unix-directory';
49
-
50
-	/**
51
-	 * @const \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX Return regular expression to test filenames against (blacklisting)
52
-	 * @since 12.0.0
53
-	 */
54
-	public const BLACKLIST_FILES_REGEX = '\.(part|filepart)$';
55
-
56
-	/**
57
-	 * Get the Etag of the file or folder
58
-	 *
59
-	 * @return string
60
-	 * @since 7.0.0
61
-	 */
62
-	public function getEtag();
63
-
64
-	/**
65
-	 * Get the size in bytes for the file or folder
66
-	 *
67
-	 * @param bool $includeMounts whether or not to include the size of any sub mounts, since 16.0.0
68
-	 * @return int|float
69
-	 * @since 7.0.0
70
-	 */
71
-	public function getSize($includeMounts = true);
72
-
73
-	/**
74
-	 * Get the last modified date as timestamp for the file or folder
75
-	 *
76
-	 * @return int
77
-	 * @since 7.0.0
78
-	 */
79
-	public function getMtime();
80
-
81
-	/**
82
-	 * Get the name of the file or folder
83
-	 *
84
-	 * @return string
85
-	 * @since 7.0.0
86
-	 */
87
-	public function getName();
88
-
89
-	/**
90
-	 * Get the path relative to the storage
91
-	 *
92
-	 * @return string
93
-	 * @since 7.0.0
94
-	 */
95
-	public function getInternalPath();
96
-
97
-	/**
98
-	 * Get the absolute path
99
-	 *
100
-	 * @return string
101
-	 * @since 7.0.0
102
-	 */
103
-	public function getPath();
104
-
105
-	/**
106
-	 * Get the full mimetype of the file or folder i.e. 'image/png'
107
-	 *
108
-	 * @since 7.0.0
109
-	 */
110
-	public function getMimetype(): string;
111
-
112
-	/**
113
-	 * Get the first part of the mimetype of the file or folder i.e. 'image'
114
-	 *
115
-	 * @return string
116
-	 * @since 7.0.0
117
-	 */
118
-	public function getMimePart();
119
-
120
-	/**
121
-	 * Get the storage the file or folder is storage on
122
-	 *
123
-	 * @return IStorage
124
-	 * @since 7.0.0
125
-	 */
126
-	public function getStorage();
127
-
128
-	/**
129
-	 * Get the file id of the file or folder
130
-	 *
131
-	 * @return int|null
132
-	 * @since 7.0.0
133
-	 */
134
-	public function getId();
135
-
136
-	/**
137
-	 * Check whether the node is encrypted.
138
-	 * If it is a file, then it is server side encrypted.
139
-	 * If it is a folder, then it is end-to-end encrypted.
140
-	 *
141
-	 * @return bool
142
-	 * @since 7.0.0
143
-	 */
144
-	public function isEncrypted();
145
-
146
-	/**
147
-	 * Get the permissions of the file or folder as bitmasked combination of the following constants
148
-	 * \OCP\Constants::PERMISSION_CREATE
149
-	 * \OCP\Constants::PERMISSION_READ
150
-	 * \OCP\Constants::PERMISSION_UPDATE
151
-	 * \OCP\Constants::PERMISSION_DELETE
152
-	 * \OCP\Constants::PERMISSION_SHARE
153
-	 * \OCP\Constants::PERMISSION_ALL
154
-	 *
155
-	 * @return int
156
-	 * @since 7.0.0 - namespace of constants has changed in 8.0.0
157
-	 */
158
-	public function getPermissions();
159
-
160
-	/**
161
-	 * Check whether this is a file or a folder
162
-	 *
163
-	 * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
164
-	 * @since 7.0.0
165
-	 */
166
-	public function getType();
167
-
168
-	/**
169
-	 * Check if the file or folder is readable
170
-	 *
171
-	 * @return bool
172
-	 * @since 7.0.0
173
-	 */
174
-	public function isReadable();
175
-
176
-	/**
177
-	 * Check if a file is writable
178
-	 *
179
-	 * @return bool
180
-	 * @since 7.0.0
181
-	 */
182
-	public function isUpdateable();
183
-
184
-	/**
185
-	 * Check whether new files or folders can be created inside this folder
186
-	 *
187
-	 * @return bool
188
-	 * @since 8.0.0
189
-	 */
190
-	public function isCreatable();
191
-
192
-	/**
193
-	 * Check if a file or folder can be deleted
194
-	 *
195
-	 * @return bool
196
-	 * @since 7.0.0
197
-	 */
198
-	public function isDeletable();
199
-
200
-	/**
201
-	 * Check if a file or folder can be shared
202
-	 *
203
-	 * @return bool
204
-	 * @since 7.0.0
205
-	 */
206
-	public function isShareable();
207
-
208
-	/**
209
-	 * Check if a file or folder is shared
210
-	 *
211
-	 * @return bool
212
-	 * @since 7.0.0
213
-	 */
214
-	public function isShared();
215
-
216
-	/**
217
-	 * Check if a file or folder is mounted
218
-	 *
219
-	 * @return bool
220
-	 * @since 7.0.0
221
-	 */
222
-	public function isMounted();
223
-
224
-	/**
225
-	 * Get the mountpoint the file belongs to
226
-	 *
227
-	 * @return \OCP\Files\Mount\IMountPoint
228
-	 * @since 8.0.0
229
-	 */
230
-	public function getMountPoint();
231
-
232
-	/**
233
-	 * Get the owner of the file
234
-	 *
235
-	 * @return ?\OCP\IUser
236
-	 * @since 9.0.0
237
-	 */
238
-	public function getOwner();
239
-
240
-	/**
241
-	 * Get the stored checksum(s) for this file
242
-	 *
243
-	 * Checksums are stored in the format TYPE:CHECKSUM, here may be multiple checksums separated by a single space
244
-	 * e.g. MD5:d3b07384d113edec49eaa6238ad5ff00 SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15
245
-	 *
246
-	 * @return string
247
-	 * @since 9.0.0
248
-	 */
249
-	public function getChecksum();
250
-
251
-	/**
252
-	 * Get the extension of the file
253
-	 *
254
-	 * @return string
255
-	 * @since 15.0.0
256
-	 */
257
-	public function getExtension(): string;
258
-
259
-	/**
260
-	 * Get the creation date as unix timestamp
261
-	 *
262
-	 * If the creation time is not known, 0 will be returned
263
-	 *
264
-	 * creation time is not set automatically by the server and is generally only available
265
-	 * for files uploaded by the sync clients
266
-	 *
267
-	 * @return int
268
-	 * @since 18.0.0
269
-	 */
270
-	public function getCreationTime(): int;
271
-
272
-	/**
273
-	 * Get the upload date as unix timestamp
274
-	 *
275
-	 * If the upload time is not known, 0 will be returned
276
-	 *
277
-	 * Upload time will be set automatically by the server for files uploaded over DAV
278
-	 * files created by Nextcloud apps generally do not have an the upload time set
279
-	 *
280
-	 * @return int
281
-	 * @since 18.0.0
282
-	 */
283
-	public function getUploadTime(): int;
284
-
285
-	/**
286
-	 * Get the fileid or the parent folder
287
-	 * or -1 if this item has no parent folder (because it is the root)
288
-	 *
289
-	 * @return int
290
-	 * @since 28.0.0
291
-	 */
292
-	public function getParentId(): int;
293
-
294
-	/**
295
-	 * Get the metadata, if available
296
-	 *
297
-	 * @return array<string, int|string|bool|float|string[]|int[]>
298
-	 * @since 28.0.0
299
-	 */
300
-	public function getMetadata(): array;
20
+    /**
21
+     * @since 7.0.0
22
+     */
23
+    public const TYPE_FILE = 'file';
24
+    /**
25
+     * @since 7.0.0
26
+     */
27
+    public const TYPE_FOLDER = 'dir';
28
+
29
+    /**
30
+     * @const \OCP\Files\FileInfo::SPACE_NOT_COMPUTED Return value for a not computed space value
31
+     * @since 8.0.0
32
+     */
33
+    public const SPACE_NOT_COMPUTED = -1;
34
+    /**
35
+     * @const \OCP\Files\FileInfo::SPACE_UNKNOWN Return value for unknown space value
36
+     * @since 8.0.0
37
+     */
38
+    public const SPACE_UNKNOWN = -2;
39
+    /**
40
+     * @const \OCP\Files\FileInfo::SPACE_UNLIMITED Return value for unlimited space
41
+     * @since 8.0.0
42
+     */
43
+    public const SPACE_UNLIMITED = -3;
44
+
45
+    /**
46
+     * @since 9.1.0
47
+     */
48
+    public const MIMETYPE_FOLDER = 'httpd/unix-directory';
49
+
50
+    /**
51
+     * @const \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX Return regular expression to test filenames against (blacklisting)
52
+     * @since 12.0.0
53
+     */
54
+    public const BLACKLIST_FILES_REGEX = '\.(part|filepart)$';
55
+
56
+    /**
57
+     * Get the Etag of the file or folder
58
+     *
59
+     * @return string
60
+     * @since 7.0.0
61
+     */
62
+    public function getEtag();
63
+
64
+    /**
65
+     * Get the size in bytes for the file or folder
66
+     *
67
+     * @param bool $includeMounts whether or not to include the size of any sub mounts, since 16.0.0
68
+     * @return int|float
69
+     * @since 7.0.0
70
+     */
71
+    public function getSize($includeMounts = true);
72
+
73
+    /**
74
+     * Get the last modified date as timestamp for the file or folder
75
+     *
76
+     * @return int
77
+     * @since 7.0.0
78
+     */
79
+    public function getMtime();
80
+
81
+    /**
82
+     * Get the name of the file or folder
83
+     *
84
+     * @return string
85
+     * @since 7.0.0
86
+     */
87
+    public function getName();
88
+
89
+    /**
90
+     * Get the path relative to the storage
91
+     *
92
+     * @return string
93
+     * @since 7.0.0
94
+     */
95
+    public function getInternalPath();
96
+
97
+    /**
98
+     * Get the absolute path
99
+     *
100
+     * @return string
101
+     * @since 7.0.0
102
+     */
103
+    public function getPath();
104
+
105
+    /**
106
+     * Get the full mimetype of the file or folder i.e. 'image/png'
107
+     *
108
+     * @since 7.0.0
109
+     */
110
+    public function getMimetype(): string;
111
+
112
+    /**
113
+     * Get the first part of the mimetype of the file or folder i.e. 'image'
114
+     *
115
+     * @return string
116
+     * @since 7.0.0
117
+     */
118
+    public function getMimePart();
119
+
120
+    /**
121
+     * Get the storage the file or folder is storage on
122
+     *
123
+     * @return IStorage
124
+     * @since 7.0.0
125
+     */
126
+    public function getStorage();
127
+
128
+    /**
129
+     * Get the file id of the file or folder
130
+     *
131
+     * @return int|null
132
+     * @since 7.0.0
133
+     */
134
+    public function getId();
135
+
136
+    /**
137
+     * Check whether the node is encrypted.
138
+     * If it is a file, then it is server side encrypted.
139
+     * If it is a folder, then it is end-to-end encrypted.
140
+     *
141
+     * @return bool
142
+     * @since 7.0.0
143
+     */
144
+    public function isEncrypted();
145
+
146
+    /**
147
+     * Get the permissions of the file or folder as bitmasked combination of the following constants
148
+     * \OCP\Constants::PERMISSION_CREATE
149
+     * \OCP\Constants::PERMISSION_READ
150
+     * \OCP\Constants::PERMISSION_UPDATE
151
+     * \OCP\Constants::PERMISSION_DELETE
152
+     * \OCP\Constants::PERMISSION_SHARE
153
+     * \OCP\Constants::PERMISSION_ALL
154
+     *
155
+     * @return int
156
+     * @since 7.0.0 - namespace of constants has changed in 8.0.0
157
+     */
158
+    public function getPermissions();
159
+
160
+    /**
161
+     * Check whether this is a file or a folder
162
+     *
163
+     * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
164
+     * @since 7.0.0
165
+     */
166
+    public function getType();
167
+
168
+    /**
169
+     * Check if the file or folder is readable
170
+     *
171
+     * @return bool
172
+     * @since 7.0.0
173
+     */
174
+    public function isReadable();
175
+
176
+    /**
177
+     * Check if a file is writable
178
+     *
179
+     * @return bool
180
+     * @since 7.0.0
181
+     */
182
+    public function isUpdateable();
183
+
184
+    /**
185
+     * Check whether new files or folders can be created inside this folder
186
+     *
187
+     * @return bool
188
+     * @since 8.0.0
189
+     */
190
+    public function isCreatable();
191
+
192
+    /**
193
+     * Check if a file or folder can be deleted
194
+     *
195
+     * @return bool
196
+     * @since 7.0.0
197
+     */
198
+    public function isDeletable();
199
+
200
+    /**
201
+     * Check if a file or folder can be shared
202
+     *
203
+     * @return bool
204
+     * @since 7.0.0
205
+     */
206
+    public function isShareable();
207
+
208
+    /**
209
+     * Check if a file or folder is shared
210
+     *
211
+     * @return bool
212
+     * @since 7.0.0
213
+     */
214
+    public function isShared();
215
+
216
+    /**
217
+     * Check if a file or folder is mounted
218
+     *
219
+     * @return bool
220
+     * @since 7.0.0
221
+     */
222
+    public function isMounted();
223
+
224
+    /**
225
+     * Get the mountpoint the file belongs to
226
+     *
227
+     * @return \OCP\Files\Mount\IMountPoint
228
+     * @since 8.0.0
229
+     */
230
+    public function getMountPoint();
231
+
232
+    /**
233
+     * Get the owner of the file
234
+     *
235
+     * @return ?\OCP\IUser
236
+     * @since 9.0.0
237
+     */
238
+    public function getOwner();
239
+
240
+    /**
241
+     * Get the stored checksum(s) for this file
242
+     *
243
+     * Checksums are stored in the format TYPE:CHECKSUM, here may be multiple checksums separated by a single space
244
+     * e.g. MD5:d3b07384d113edec49eaa6238ad5ff00 SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15
245
+     *
246
+     * @return string
247
+     * @since 9.0.0
248
+     */
249
+    public function getChecksum();
250
+
251
+    /**
252
+     * Get the extension of the file
253
+     *
254
+     * @return string
255
+     * @since 15.0.0
256
+     */
257
+    public function getExtension(): string;
258
+
259
+    /**
260
+     * Get the creation date as unix timestamp
261
+     *
262
+     * If the creation time is not known, 0 will be returned
263
+     *
264
+     * creation time is not set automatically by the server and is generally only available
265
+     * for files uploaded by the sync clients
266
+     *
267
+     * @return int
268
+     * @since 18.0.0
269
+     */
270
+    public function getCreationTime(): int;
271
+
272
+    /**
273
+     * Get the upload date as unix timestamp
274
+     *
275
+     * If the upload time is not known, 0 will be returned
276
+     *
277
+     * Upload time will be set automatically by the server for files uploaded over DAV
278
+     * files created by Nextcloud apps generally do not have an the upload time set
279
+     *
280
+     * @return int
281
+     * @since 18.0.0
282
+     */
283
+    public function getUploadTime(): int;
284
+
285
+    /**
286
+     * Get the fileid or the parent folder
287
+     * or -1 if this item has no parent folder (because it is the root)
288
+     *
289
+     * @return int
290
+     * @since 28.0.0
291
+     */
292
+    public function getParentId(): int;
293
+
294
+    /**
295
+     * Get the metadata, if available
296
+     *
297
+     * @return array<string, int|string|bool|float|string[]|int[]>
298
+     * @since 28.0.0
299
+     */
300
+    public function getMetadata(): array;
301 301
 }
Please login to merge, or discard this patch.
lib/public/Files/File.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -20,72 +20,72 @@
 block discarded – undo
20 20
  */
21 21
 #[Consumable(since: '6.0.0')]
22 22
 interface File extends Node {
23
-	/**
24
-	 * Get the content of the file as string
25
-	 *
26
-	 * @return string
27
-	 * @throws NotPermittedException
28
-	 * @throws GenericFileException
29
-	 * @throws LockedException
30
-	 * @since 6.0.0
31
-	 */
32
-	public function getContent();
23
+    /**
24
+     * Get the content of the file as string
25
+     *
26
+     * @return string
27
+     * @throws NotPermittedException
28
+     * @throws GenericFileException
29
+     * @throws LockedException
30
+     * @since 6.0.0
31
+     */
32
+    public function getContent();
33 33
 
34
-	/**
35
-	 * Write to the file from string data
36
-	 *
37
-	 * @param string|resource $data
38
-	 * @throws NotPermittedException
39
-	 * @throws GenericFileException
40
-	 * @throws LockedException
41
-	 * @since 6.0.0
42
-	 */
43
-	public function putContent($data);
34
+    /**
35
+     * Write to the file from string data
36
+     *
37
+     * @param string|resource $data
38
+     * @throws NotPermittedException
39
+     * @throws GenericFileException
40
+     * @throws LockedException
41
+     * @since 6.0.0
42
+     */
43
+    public function putContent($data);
44 44
 
45
-	/**
46
-	 * Get the mimetype of the file
47
-	 *
48
-	 * @since 6.0.0
49
-	 */
50
-	public function getMimeType(): string;
45
+    /**
46
+     * Get the mimetype of the file
47
+     *
48
+     * @since 6.0.0
49
+     */
50
+    public function getMimeType(): string;
51 51
 
52
-	/**
53
-	 * Open the file as stream, resulting resource can be operated as stream like the result from php's own fopen
54
-	 *
55
-	 * @param string $mode
56
-	 * @return resource|false
57
-	 * @throws NotPermittedException
58
-	 * @throws LockedException
59
-	 * @since 6.0.0
60
-	 */
61
-	public function fopen($mode);
52
+    /**
53
+     * Open the file as stream, resulting resource can be operated as stream like the result from php's own fopen
54
+     *
55
+     * @param string $mode
56
+     * @return resource|false
57
+     * @throws NotPermittedException
58
+     * @throws LockedException
59
+     * @since 6.0.0
60
+     */
61
+    public function fopen($mode);
62 62
 
63
-	/**
64
-	 * Compute the hash of the file
65
-	 * Type of hash is set with $type and can be anything supported by php's hash_file
66
-	 *
67
-	 * @param string $type
68
-	 * @param bool $raw
69
-	 * @return string
70
-	 * @since 6.0.0
71
-	 */
72
-	public function hash($type, $raw = false);
63
+    /**
64
+     * Compute the hash of the file
65
+     * Type of hash is set with $type and can be anything supported by php's hash_file
66
+     *
67
+     * @param string $type
68
+     * @param bool $raw
69
+     * @return string
70
+     * @since 6.0.0
71
+     */
72
+    public function hash($type, $raw = false);
73 73
 
74
-	/**
75
-	 * Get the stored checksum for this file
76
-	 *
77
-	 * @return string
78
-	 * @since 9.0.0
79
-	 * @throws InvalidPathException
80
-	 * @throws NotFoundException
81
-	 */
82
-	public function getChecksum();
74
+    /**
75
+     * Get the stored checksum for this file
76
+     *
77
+     * @return string
78
+     * @since 9.0.0
79
+     * @throws InvalidPathException
80
+     * @throws NotFoundException
81
+     */
82
+    public function getChecksum();
83 83
 
84
-	/**
85
-	 * Get the extension of this file
86
-	 *
87
-	 * @return string
88
-	 * @since 15.0.0
89
-	 */
90
-	public function getExtension(): string;
84
+    /**
85
+     * Get the extension of this file
86
+     *
87
+     * @return string
88
+     * @since 15.0.0
89
+     */
90
+    public function getExtension(): string;
91 91
 }
Please login to merge, or discard this patch.
lib/public/Files/Cache/ICacheEntry.php 1 patch
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -22,152 +22,152 @@
 block discarded – undo
22 22
  */
23 23
 #[Consumable(since: '9.0.0')]
24 24
 interface ICacheEntry extends ArrayAccess {
25
-	/**
26
-	 * @since 9.0.0
27
-	 */
28
-	public const DIRECTORY_MIMETYPE = 'httpd/unix-directory';
29
-
30
-	/**
31
-	 * Get the numeric id of a file
32
-	 *
33
-	 * @return int
34
-	 * @since 9.0.0
35
-	 */
36
-	public function getId();
37
-
38
-	/**
39
-	 * Get the numeric id for the storage
40
-	 *
41
-	 * @return int
42
-	 * @since 9.0.0
43
-	 */
44
-	public function getStorageId();
45
-
46
-	/**
47
-	 * Get the path of the file relative to the storage root
48
-	 *
49
-	 * @return string
50
-	 * @since 9.0.0
51
-	 */
52
-	public function getPath();
53
-
54
-	/**
55
-	 * Get the file name
56
-	 *
57
-	 * @return string
58
-	 * @since 9.0.0
59
-	 */
60
-	public function getName();
61
-
62
-	/**
63
-	 * Get the full mimetype
64
-	 *
65
-	 * @since 9.0.0
66
-	 */
67
-	public function getMimeType(): string;
68
-
69
-	/**
70
-	 * Get the first part of the mimetype
71
-	 *
72
-	 * @return string
73
-	 * @since 9.0.0
74
-	 */
75
-	public function getMimePart();
76
-
77
-	/**
78
-	 * Get the file size in bytes
79
-	 *
80
-	 * @return int
81
-	 * @since 9.0.0
82
-	 */
83
-	public function getSize();
84
-
85
-	/**
86
-	 * Get the last modified date as unix timestamp
87
-	 *
88
-	 * @return int
89
-	 * @since 9.0.0
90
-	 */
91
-	public function getMTime();
92
-
93
-	/**
94
-	 * Get the last modified date on the storage as unix timestamp
95
-	 *
96
-	 * Note that when a file is updated we also update the mtime of all parent folders to make it visible to the user which folder has had updates most recently
97
-	 * This can differ from the mtime on the underlying storage which usually only changes when a direct child is added, removed or renamed
98
-	 *
99
-	 * @return int
100
-	 * @since 9.0.0
101
-	 */
102
-	public function getStorageMTime();
103
-
104
-	/**
105
-	 * Get the etag for the file
106
-	 *
107
-	 * An etag is used for change detection of files and folders, an etag of a file changes whenever the content of the file changes
108
-	 * Etag for folders change whenever a file in the folder has changed
109
-	 *
110
-	 * @return string
111
-	 * @since 9.0.0
112
-	 */
113
-	public function getEtag();
114
-
115
-	/**
116
-	 * Get the permissions for the file stored as bitwise combination of \OCP\Constants::PERMISSION_READ, \OCP\Constants::PERMISSION_CREATE
117
-	 * \OCP\Constants::PERMISSION_UPDATE, \OCP\Constants::PERMISSION_DELETE and \OCP\Constants::PERMISSION_SHARE
118
-	 *
119
-	 * @return int
120
-	 * @since 9.0.0
121
-	 */
122
-	public function getPermissions();
123
-
124
-	/**
125
-	 * Check if the file is encrypted
126
-	 *
127
-	 * @return bool
128
-	 * @since 9.0.0
129
-	 */
130
-	public function isEncrypted();
131
-
132
-	/**
133
-	 * Get the metadata etag for the file
134
-	 *
135
-	 * @return string | null
136
-	 * @since 18.0.0
137
-	 */
138
-	public function getMetadataEtag(): ?string;
139
-
140
-	/**
141
-	 * Get the last modified date as unix timestamp
142
-	 *
143
-	 * @return int | null
144
-	 * @since 18.0.0
145
-	 */
146
-	public function getCreationTime(): ?int;
147
-
148
-	/**
149
-	 * Get the last modified date as unix timestamp
150
-	 *
151
-	 * @return int | null
152
-	 * @since 18.0.0
153
-	 */
154
-	public function getUploadTime(): ?int;
155
-
156
-	/**
157
-	 * Get the unencrypted size
158
-	 *
159
-	 * This might be different from the result of getSize
160
-	 *
161
-	 * @return int
162
-	 * @since 25.0.0
163
-	 */
164
-	public function getUnencryptedSize(): int;
165
-
166
-	/**
167
-	 * Get the file id of the parent folder
168
-	 *
169
-	 * @return int
170
-	 * @since 32.0.0
171
-	 */
172
-	public function getParentId(): int;
25
+    /**
26
+     * @since 9.0.0
27
+     */
28
+    public const DIRECTORY_MIMETYPE = 'httpd/unix-directory';
29
+
30
+    /**
31
+     * Get the numeric id of a file
32
+     *
33
+     * @return int
34
+     * @since 9.0.0
35
+     */
36
+    public function getId();
37
+
38
+    /**
39
+     * Get the numeric id for the storage
40
+     *
41
+     * @return int
42
+     * @since 9.0.0
43
+     */
44
+    public function getStorageId();
45
+
46
+    /**
47
+     * Get the path of the file relative to the storage root
48
+     *
49
+     * @return string
50
+     * @since 9.0.0
51
+     */
52
+    public function getPath();
53
+
54
+    /**
55
+     * Get the file name
56
+     *
57
+     * @return string
58
+     * @since 9.0.0
59
+     */
60
+    public function getName();
61
+
62
+    /**
63
+     * Get the full mimetype
64
+     *
65
+     * @since 9.0.0
66
+     */
67
+    public function getMimeType(): string;
68
+
69
+    /**
70
+     * Get the first part of the mimetype
71
+     *
72
+     * @return string
73
+     * @since 9.0.0
74
+     */
75
+    public function getMimePart();
76
+
77
+    /**
78
+     * Get the file size in bytes
79
+     *
80
+     * @return int
81
+     * @since 9.0.0
82
+     */
83
+    public function getSize();
84
+
85
+    /**
86
+     * Get the last modified date as unix timestamp
87
+     *
88
+     * @return int
89
+     * @since 9.0.0
90
+     */
91
+    public function getMTime();
92
+
93
+    /**
94
+     * Get the last modified date on the storage as unix timestamp
95
+     *
96
+     * Note that when a file is updated we also update the mtime of all parent folders to make it visible to the user which folder has had updates most recently
97
+     * This can differ from the mtime on the underlying storage which usually only changes when a direct child is added, removed or renamed
98
+     *
99
+     * @return int
100
+     * @since 9.0.0
101
+     */
102
+    public function getStorageMTime();
103
+
104
+    /**
105
+     * Get the etag for the file
106
+     *
107
+     * An etag is used for change detection of files and folders, an etag of a file changes whenever the content of the file changes
108
+     * Etag for folders change whenever a file in the folder has changed
109
+     *
110
+     * @return string
111
+     * @since 9.0.0
112
+     */
113
+    public function getEtag();
114
+
115
+    /**
116
+     * Get the permissions for the file stored as bitwise combination of \OCP\Constants::PERMISSION_READ, \OCP\Constants::PERMISSION_CREATE
117
+     * \OCP\Constants::PERMISSION_UPDATE, \OCP\Constants::PERMISSION_DELETE and \OCP\Constants::PERMISSION_SHARE
118
+     *
119
+     * @return int
120
+     * @since 9.0.0
121
+     */
122
+    public function getPermissions();
123
+
124
+    /**
125
+     * Check if the file is encrypted
126
+     *
127
+     * @return bool
128
+     * @since 9.0.0
129
+     */
130
+    public function isEncrypted();
131
+
132
+    /**
133
+     * Get the metadata etag for the file
134
+     *
135
+     * @return string | null
136
+     * @since 18.0.0
137
+     */
138
+    public function getMetadataEtag(): ?string;
139
+
140
+    /**
141
+     * Get the last modified date as unix timestamp
142
+     *
143
+     * @return int | null
144
+     * @since 18.0.0
145
+     */
146
+    public function getCreationTime(): ?int;
147
+
148
+    /**
149
+     * Get the last modified date as unix timestamp
150
+     *
151
+     * @return int | null
152
+     * @since 18.0.0
153
+     */
154
+    public function getUploadTime(): ?int;
155
+
156
+    /**
157
+     * Get the unencrypted size
158
+     *
159
+     * This might be different from the result of getSize
160
+     *
161
+     * @return int
162
+     * @since 25.0.0
163
+     */
164
+    public function getUnencryptedSize(): int;
165
+
166
+    /**
167
+     * Get the file id of the parent folder
168
+     *
169
+     * @return int
170
+     * @since 32.0.0
171
+     */
172
+    public function getParentId(): int;
173 173
 }
Please login to merge, or discard this patch.
lib/private/Files/Node/Node.php 1 patch
Indentation   +463 added lines, -463 removed lines patch added patch discarded remove patch
@@ -23,467 +23,467 @@
 block discarded – undo
23 23
 
24 24
 // FIXME: this class really should be abstract (+1)
25 25
 class Node implements INode {
26
-	/**
27
-	 * @var \OC\Files\View $view
28
-	 */
29
-	protected $view;
30
-
31
-	protected IRootFolder $root;
32
-
33
-	/**
34
-	 * @var string $path Absolute path to the node (e.g. /admin/files/folder/file)
35
-	 */
36
-	protected $path;
37
-
38
-	protected ?FileInfo $fileInfo;
39
-
40
-	protected ?INode $parent;
41
-
42
-	private bool $infoHasSubMountsIncluded;
43
-
44
-	/**
45
-	 * @param \OC\Files\View $view
46
-	 * @param \OCP\Files\IRootFolder $root
47
-	 * @param string $path
48
-	 * @param FileInfo $fileInfo
49
-	 */
50
-	public function __construct(IRootFolder $root, $view, $path, $fileInfo = null, ?INode $parent = null, bool $infoHasSubMountsIncluded = true) {
51
-		if (Filesystem::normalizePath($view->getRoot()) !== '/') {
52
-			throw new PreConditionNotMetException('The view passed to the node should not have any fake root set');
53
-		}
54
-		$this->view = $view;
55
-		$this->root = $root;
56
-		$this->path = $path;
57
-		$this->fileInfo = $fileInfo;
58
-		$this->parent = $parent;
59
-		$this->infoHasSubMountsIncluded = $infoHasSubMountsIncluded;
60
-	}
61
-
62
-	/**
63
-	 * Creates a Node of the same type that represents a non-existing path
64
-	 *
65
-	 * @param string $path path
66
-	 * @return Node non-existing node
67
-	 * @throws \Exception
68
-	 */
69
-	protected function createNonExistingNode($path) {
70
-		throw new \Exception('Must be implemented by subclasses');
71
-	}
72
-
73
-	/**
74
-	 * Returns the matching file info
75
-	 *
76
-	 * @return FileInfo
77
-	 * @throws InvalidPathException
78
-	 * @throws NotFoundException
79
-	 */
80
-	public function getFileInfo(bool $includeMountPoint = true) {
81
-		if (!$this->fileInfo) {
82
-			if (!Filesystem::isValidPath($this->path)) {
83
-				throw new InvalidPathException();
84
-			}
85
-			$fileInfo = $this->view->getFileInfo($this->path, $includeMountPoint);
86
-			$this->infoHasSubMountsIncluded = $includeMountPoint;
87
-			if ($fileInfo instanceof FileInfo) {
88
-				$this->fileInfo = $fileInfo;
89
-			} else {
90
-				throw new NotFoundException();
91
-			}
92
-		} elseif ($includeMountPoint && !$this->infoHasSubMountsIncluded && $this instanceof Folder) {
93
-			if ($this->fileInfo instanceof \OC\Files\FileInfo) {
94
-				$this->view->addSubMounts($this->fileInfo);
95
-			}
96
-			$this->infoHasSubMountsIncluded = true;
97
-		}
98
-		return $this->fileInfo;
99
-	}
100
-
101
-	/**
102
-	 * @param string[] $hooks
103
-	 */
104
-	protected function sendHooks($hooks, ?array $args = null) {
105
-		$args = !empty($args) ? $args : [$this];
106
-		/** @var IEventDispatcher $dispatcher */
107
-		$dispatcher = \OC::$server->get(IEventDispatcher::class);
108
-		foreach ($hooks as $hook) {
109
-			if (method_exists($this->root, 'emit')) {
110
-				$this->root->emit('\OC\Files', $hook, $args);
111
-			}
112
-
113
-			if (in_array($hook, ['preWrite', 'postWrite', 'preCreate', 'postCreate', 'preTouch', 'postTouch', 'preDelete', 'postDelete'], true)) {
114
-				$event = new GenericEvent($args[0]);
115
-			} else {
116
-				$event = new GenericEvent($args);
117
-			}
118
-
119
-			$dispatcher->dispatch('\OCP\Files::' . $hook, $event);
120
-		}
121
-	}
122
-
123
-	/**
124
-	 * @param int $permissions
125
-	 * @return bool
126
-	 * @throws InvalidPathException
127
-	 * @throws NotFoundException
128
-	 */
129
-	protected function checkPermissions($permissions) {
130
-		return ($this->getPermissions() & $permissions) === $permissions;
131
-	}
132
-
133
-	public function delete() {
134
-	}
135
-
136
-	/**
137
-	 * @param int $mtime
138
-	 * @throws InvalidPathException
139
-	 * @throws NotFoundException
140
-	 * @throws NotPermittedException
141
-	 */
142
-	public function touch($mtime = null) {
143
-		if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) {
144
-			$this->sendHooks(['preTouch']);
145
-			$this->view->touch($this->path, $mtime);
146
-			$this->sendHooks(['postTouch']);
147
-			if ($this->fileInfo) {
148
-				if (is_null($mtime)) {
149
-					$mtime = time();
150
-				}
151
-				$this->fileInfo['mtime'] = $mtime;
152
-			}
153
-		} else {
154
-			throw new NotPermittedException();
155
-		}
156
-	}
157
-
158
-	public function getStorage() {
159
-		$storage = $this->getMountPoint()->getStorage();
160
-		if (!$storage) {
161
-			throw new \Exception('No storage for node');
162
-		}
163
-		return $storage;
164
-	}
165
-
166
-	/**
167
-	 * @return string
168
-	 */
169
-	public function getPath() {
170
-		return $this->path;
171
-	}
172
-
173
-	/**
174
-	 * @return string
175
-	 */
176
-	public function getInternalPath() {
177
-		return $this->getFileInfo(false)->getInternalPath();
178
-	}
179
-
180
-	/**
181
-	 * @return int
182
-	 * @throws InvalidPathException
183
-	 * @throws NotFoundException
184
-	 */
185
-	public function getId() {
186
-		return $this->getFileInfo(false)->getId() ?? -1;
187
-	}
188
-
189
-	/**
190
-	 * @return array
191
-	 */
192
-	public function stat() {
193
-		return $this->view->stat($this->path);
194
-	}
195
-
196
-	/**
197
-	 * @return int
198
-	 * @throws InvalidPathException
199
-	 * @throws NotFoundException
200
-	 */
201
-	public function getMTime() {
202
-		return $this->getFileInfo()->getMTime();
203
-	}
204
-
205
-	/**
206
-	 * @param bool $includeMounts
207
-	 * @return int|float
208
-	 * @throws InvalidPathException
209
-	 * @throws NotFoundException
210
-	 */
211
-	public function getSize($includeMounts = true): int|float {
212
-		return $this->getFileInfo()->getSize($includeMounts);
213
-	}
214
-
215
-	/**
216
-	 * @return string
217
-	 * @throws InvalidPathException
218
-	 * @throws NotFoundException
219
-	 */
220
-	public function getEtag() {
221
-		return $this->getFileInfo()->getEtag();
222
-	}
223
-
224
-	/**
225
-	 * @return int
226
-	 * @throws InvalidPathException
227
-	 * @throws NotFoundException
228
-	 */
229
-	public function getPermissions() {
230
-		return $this->getFileInfo(false)->getPermissions();
231
-	}
232
-
233
-	/**
234
-	 * @return bool
235
-	 * @throws InvalidPathException
236
-	 * @throws NotFoundException
237
-	 */
238
-	public function isReadable() {
239
-		return $this->getFileInfo(false)->isReadable();
240
-	}
241
-
242
-	/**
243
-	 * @return bool
244
-	 * @throws InvalidPathException
245
-	 * @throws NotFoundException
246
-	 */
247
-	public function isUpdateable() {
248
-		return $this->getFileInfo(false)->isUpdateable();
249
-	}
250
-
251
-	/**
252
-	 * @return bool
253
-	 * @throws InvalidPathException
254
-	 * @throws NotFoundException
255
-	 */
256
-	public function isDeletable() {
257
-		return $this->getFileInfo(false)->isDeletable();
258
-	}
259
-
260
-	/**
261
-	 * @return bool
262
-	 * @throws InvalidPathException
263
-	 * @throws NotFoundException
264
-	 */
265
-	public function isShareable() {
266
-		return $this->getFileInfo(false)->isShareable();
267
-	}
268
-
269
-	/**
270
-	 * @return bool
271
-	 * @throws InvalidPathException
272
-	 * @throws NotFoundException
273
-	 */
274
-	public function isCreatable() {
275
-		return $this->getFileInfo(false)->isCreatable();
276
-	}
277
-
278
-	public function getParent(): INode|IRootFolder {
279
-		if ($this->parent === null) {
280
-			$newPath = dirname($this->path);
281
-			if ($newPath === '' || $newPath === '.' || $newPath === '/') {
282
-				return $this->root;
283
-			}
284
-
285
-			// Manually fetch the parent if the current node doesn't have a file info yet
286
-			try {
287
-				$fileInfo = $this->getFileInfo();
288
-			} catch (NotFoundException) {
289
-				$this->parent = $this->root->get($newPath);
290
-				/** @var \OCP\Files\Folder $this->parent */
291
-				return $this->parent;
292
-			}
293
-
294
-			// gather the metadata we already know about our parent
295
-			$parentData = [
296
-				'path' => $newPath,
297
-				'fileid' => $fileInfo->getParentId(),
298
-			];
299
-
300
-			// and create lazy folder with it instead of always querying
301
-			$this->parent = new LazyFolder($this->root, function () use ($newPath) {
302
-				return $this->root->get($newPath);
303
-			}, $parentData);
304
-		}
305
-
306
-		return $this->parent;
307
-	}
308
-
309
-	/**
310
-	 * @return string
311
-	 */
312
-	public function getName() {
313
-		return basename($this->path);
314
-	}
315
-
316
-	/**
317
-	 * @param string $path
318
-	 * @return string
319
-	 */
320
-	protected function normalizePath($path) {
321
-		return PathHelper::normalizePath($path);
322
-	}
323
-
324
-	/**
325
-	 * check if the requested path is valid
326
-	 *
327
-	 * @param string $path
328
-	 * @return bool
329
-	 */
330
-	public function isValidPath($path) {
331
-		return Filesystem::isValidPath($path);
332
-	}
333
-
334
-	public function isMounted() {
335
-		return $this->getFileInfo(false)->isMounted();
336
-	}
337
-
338
-	public function isShared() {
339
-		return $this->getFileInfo(false)->isShared();
340
-	}
341
-
342
-	public function getMimeType(): string {
343
-		return $this->getFileInfo(false)->getMimetype();
344
-	}
345
-
346
-	public function getMimePart() {
347
-		return $this->getFileInfo(false)->getMimePart();
348
-	}
349
-
350
-	public function getType() {
351
-		return $this->getFileInfo(false)->getType();
352
-	}
353
-
354
-	public function isEncrypted() {
355
-		return $this->getFileInfo(false)->isEncrypted();
356
-	}
357
-
358
-	public function getMountPoint() {
359
-		return $this->getFileInfo(false)->getMountPoint();
360
-	}
361
-
362
-	public function getOwner() {
363
-		return $this->getFileInfo(false)->getOwner();
364
-	}
365
-
366
-	public function getChecksum() {
367
-	}
368
-
369
-	public function getExtension(): string {
370
-		return $this->getFileInfo(false)->getExtension();
371
-	}
372
-
373
-	/**
374
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
375
-	 * @throws LockedException
376
-	 */
377
-	public function lock($type) {
378
-		$this->view->lockFile($this->path, $type);
379
-	}
380
-
381
-	/**
382
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
383
-	 * @throws LockedException
384
-	 */
385
-	public function changeLock($type) {
386
-		$this->view->changeLock($this->path, $type);
387
-	}
388
-
389
-	/**
390
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
391
-	 * @throws LockedException
392
-	 */
393
-	public function unlock($type) {
394
-		$this->view->unlockFile($this->path, $type);
395
-	}
396
-
397
-	/**
398
-	 * @param string $targetPath
399
-	 * @return INode
400
-	 * @throws InvalidPathException
401
-	 * @throws NotFoundException
402
-	 * @throws NotPermittedException if copy not allowed or failed
403
-	 */
404
-	public function copy($targetPath) {
405
-		$targetPath = $this->normalizePath($targetPath);
406
-		$parent = $this->root->get(dirname($targetPath));
407
-		if ($parent instanceof Folder && $this->isValidPath($targetPath) && $parent->isCreatable()) {
408
-			$nonExisting = $this->createNonExistingNode($targetPath);
409
-			$this->sendHooks(['preCopy'], [$this, $nonExisting]);
410
-			$this->sendHooks(['preWrite'], [$nonExisting]);
411
-			if (!$this->view->copy($this->path, $targetPath)) {
412
-				throw new NotPermittedException('Could not copy ' . $this->path . ' to ' . $targetPath);
413
-			}
414
-			$targetNode = $this->root->get($targetPath);
415
-			$this->sendHooks(['postCopy'], [$this, $targetNode]);
416
-			$this->sendHooks(['postWrite'], [$targetNode]);
417
-			return $targetNode;
418
-		} else {
419
-			throw new NotPermittedException('No permission to copy to path ' . $targetPath);
420
-		}
421
-	}
422
-
423
-	/**
424
-	 * @param string $targetPath
425
-	 * @return INode
426
-	 * @throws InvalidPathException
427
-	 * @throws NotFoundException
428
-	 * @throws NotPermittedException if move not allowed or failed
429
-	 * @throws LockedException
430
-	 */
431
-	public function move($targetPath) {
432
-		$targetPath = $this->normalizePath($targetPath);
433
-		$parent = $this->root->get(dirname($targetPath));
434
-		if (
435
-			($parent instanceof Folder)
436
-			&& $this->isValidPath($targetPath)
437
-			&& (
438
-				$parent->isCreatable()
439
-				|| (
440
-					$parent->getInternalPath() === ''
441
-					&& ($parent->getMountPoint() instanceof MoveableMount)
442
-				)
443
-			)
444
-		) {
445
-			$nonExisting = $this->createNonExistingNode($targetPath);
446
-			$this->sendHooks(['preRename'], [$this, $nonExisting]);
447
-			$this->sendHooks(['preWrite'], [$nonExisting]);
448
-			if (!$this->view->rename($this->path, $targetPath)) {
449
-				throw new NotPermittedException('Could not move ' . $this->path . ' to ' . $targetPath);
450
-			}
451
-
452
-			$mountPoint = $this->getMountPoint();
453
-			if ($mountPoint) {
454
-				// update the cached fileinfo with the new (internal) path
455
-				/** @var \OC\Files\FileInfo $oldFileInfo */
456
-				$oldFileInfo = $this->getFileInfo();
457
-				$this->fileInfo = new \OC\Files\FileInfo($targetPath, $oldFileInfo->getStorage(), $mountPoint->getInternalPath($targetPath), $oldFileInfo->getData(), $mountPoint, $oldFileInfo->getOwner());
458
-			}
459
-
460
-			$targetNode = $this->root->get($targetPath);
461
-			$this->sendHooks(['postRename'], [$this, $targetNode]);
462
-			$this->sendHooks(['postWrite'], [$targetNode]);
463
-			$this->path = $targetPath;
464
-			return $targetNode;
465
-		} else {
466
-			throw new NotPermittedException('No permission to move to path ' . $targetPath);
467
-		}
468
-	}
469
-
470
-	public function getCreationTime(): int {
471
-		return $this->getFileInfo()->getCreationTime();
472
-	}
473
-
474
-	public function getUploadTime(): int {
475
-		return $this->getFileInfo()->getUploadTime();
476
-	}
477
-
478
-	public function getParentId(): int {
479
-		return $this->fileInfo->getParentId();
480
-	}
481
-
482
-	/**
483
-	 * @inheritDoc
484
-	 * @return array<string, int|string|bool|float|string[]|int[]>
485
-	 */
486
-	public function getMetadata(): array {
487
-		return $this->fileInfo->getMetadata();
488
-	}
26
+    /**
27
+     * @var \OC\Files\View $view
28
+     */
29
+    protected $view;
30
+
31
+    protected IRootFolder $root;
32
+
33
+    /**
34
+     * @var string $path Absolute path to the node (e.g. /admin/files/folder/file)
35
+     */
36
+    protected $path;
37
+
38
+    protected ?FileInfo $fileInfo;
39
+
40
+    protected ?INode $parent;
41
+
42
+    private bool $infoHasSubMountsIncluded;
43
+
44
+    /**
45
+     * @param \OC\Files\View $view
46
+     * @param \OCP\Files\IRootFolder $root
47
+     * @param string $path
48
+     * @param FileInfo $fileInfo
49
+     */
50
+    public function __construct(IRootFolder $root, $view, $path, $fileInfo = null, ?INode $parent = null, bool $infoHasSubMountsIncluded = true) {
51
+        if (Filesystem::normalizePath($view->getRoot()) !== '/') {
52
+            throw new PreConditionNotMetException('The view passed to the node should not have any fake root set');
53
+        }
54
+        $this->view = $view;
55
+        $this->root = $root;
56
+        $this->path = $path;
57
+        $this->fileInfo = $fileInfo;
58
+        $this->parent = $parent;
59
+        $this->infoHasSubMountsIncluded = $infoHasSubMountsIncluded;
60
+    }
61
+
62
+    /**
63
+     * Creates a Node of the same type that represents a non-existing path
64
+     *
65
+     * @param string $path path
66
+     * @return Node non-existing node
67
+     * @throws \Exception
68
+     */
69
+    protected function createNonExistingNode($path) {
70
+        throw new \Exception('Must be implemented by subclasses');
71
+    }
72
+
73
+    /**
74
+     * Returns the matching file info
75
+     *
76
+     * @return FileInfo
77
+     * @throws InvalidPathException
78
+     * @throws NotFoundException
79
+     */
80
+    public function getFileInfo(bool $includeMountPoint = true) {
81
+        if (!$this->fileInfo) {
82
+            if (!Filesystem::isValidPath($this->path)) {
83
+                throw new InvalidPathException();
84
+            }
85
+            $fileInfo = $this->view->getFileInfo($this->path, $includeMountPoint);
86
+            $this->infoHasSubMountsIncluded = $includeMountPoint;
87
+            if ($fileInfo instanceof FileInfo) {
88
+                $this->fileInfo = $fileInfo;
89
+            } else {
90
+                throw new NotFoundException();
91
+            }
92
+        } elseif ($includeMountPoint && !$this->infoHasSubMountsIncluded && $this instanceof Folder) {
93
+            if ($this->fileInfo instanceof \OC\Files\FileInfo) {
94
+                $this->view->addSubMounts($this->fileInfo);
95
+            }
96
+            $this->infoHasSubMountsIncluded = true;
97
+        }
98
+        return $this->fileInfo;
99
+    }
100
+
101
+    /**
102
+     * @param string[] $hooks
103
+     */
104
+    protected function sendHooks($hooks, ?array $args = null) {
105
+        $args = !empty($args) ? $args : [$this];
106
+        /** @var IEventDispatcher $dispatcher */
107
+        $dispatcher = \OC::$server->get(IEventDispatcher::class);
108
+        foreach ($hooks as $hook) {
109
+            if (method_exists($this->root, 'emit')) {
110
+                $this->root->emit('\OC\Files', $hook, $args);
111
+            }
112
+
113
+            if (in_array($hook, ['preWrite', 'postWrite', 'preCreate', 'postCreate', 'preTouch', 'postTouch', 'preDelete', 'postDelete'], true)) {
114
+                $event = new GenericEvent($args[0]);
115
+            } else {
116
+                $event = new GenericEvent($args);
117
+            }
118
+
119
+            $dispatcher->dispatch('\OCP\Files::' . $hook, $event);
120
+        }
121
+    }
122
+
123
+    /**
124
+     * @param int $permissions
125
+     * @return bool
126
+     * @throws InvalidPathException
127
+     * @throws NotFoundException
128
+     */
129
+    protected function checkPermissions($permissions) {
130
+        return ($this->getPermissions() & $permissions) === $permissions;
131
+    }
132
+
133
+    public function delete() {
134
+    }
135
+
136
+    /**
137
+     * @param int $mtime
138
+     * @throws InvalidPathException
139
+     * @throws NotFoundException
140
+     * @throws NotPermittedException
141
+     */
142
+    public function touch($mtime = null) {
143
+        if ($this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE)) {
144
+            $this->sendHooks(['preTouch']);
145
+            $this->view->touch($this->path, $mtime);
146
+            $this->sendHooks(['postTouch']);
147
+            if ($this->fileInfo) {
148
+                if (is_null($mtime)) {
149
+                    $mtime = time();
150
+                }
151
+                $this->fileInfo['mtime'] = $mtime;
152
+            }
153
+        } else {
154
+            throw new NotPermittedException();
155
+        }
156
+    }
157
+
158
+    public function getStorage() {
159
+        $storage = $this->getMountPoint()->getStorage();
160
+        if (!$storage) {
161
+            throw new \Exception('No storage for node');
162
+        }
163
+        return $storage;
164
+    }
165
+
166
+    /**
167
+     * @return string
168
+     */
169
+    public function getPath() {
170
+        return $this->path;
171
+    }
172
+
173
+    /**
174
+     * @return string
175
+     */
176
+    public function getInternalPath() {
177
+        return $this->getFileInfo(false)->getInternalPath();
178
+    }
179
+
180
+    /**
181
+     * @return int
182
+     * @throws InvalidPathException
183
+     * @throws NotFoundException
184
+     */
185
+    public function getId() {
186
+        return $this->getFileInfo(false)->getId() ?? -1;
187
+    }
188
+
189
+    /**
190
+     * @return array
191
+     */
192
+    public function stat() {
193
+        return $this->view->stat($this->path);
194
+    }
195
+
196
+    /**
197
+     * @return int
198
+     * @throws InvalidPathException
199
+     * @throws NotFoundException
200
+     */
201
+    public function getMTime() {
202
+        return $this->getFileInfo()->getMTime();
203
+    }
204
+
205
+    /**
206
+     * @param bool $includeMounts
207
+     * @return int|float
208
+     * @throws InvalidPathException
209
+     * @throws NotFoundException
210
+     */
211
+    public function getSize($includeMounts = true): int|float {
212
+        return $this->getFileInfo()->getSize($includeMounts);
213
+    }
214
+
215
+    /**
216
+     * @return string
217
+     * @throws InvalidPathException
218
+     * @throws NotFoundException
219
+     */
220
+    public function getEtag() {
221
+        return $this->getFileInfo()->getEtag();
222
+    }
223
+
224
+    /**
225
+     * @return int
226
+     * @throws InvalidPathException
227
+     * @throws NotFoundException
228
+     */
229
+    public function getPermissions() {
230
+        return $this->getFileInfo(false)->getPermissions();
231
+    }
232
+
233
+    /**
234
+     * @return bool
235
+     * @throws InvalidPathException
236
+     * @throws NotFoundException
237
+     */
238
+    public function isReadable() {
239
+        return $this->getFileInfo(false)->isReadable();
240
+    }
241
+
242
+    /**
243
+     * @return bool
244
+     * @throws InvalidPathException
245
+     * @throws NotFoundException
246
+     */
247
+    public function isUpdateable() {
248
+        return $this->getFileInfo(false)->isUpdateable();
249
+    }
250
+
251
+    /**
252
+     * @return bool
253
+     * @throws InvalidPathException
254
+     * @throws NotFoundException
255
+     */
256
+    public function isDeletable() {
257
+        return $this->getFileInfo(false)->isDeletable();
258
+    }
259
+
260
+    /**
261
+     * @return bool
262
+     * @throws InvalidPathException
263
+     * @throws NotFoundException
264
+     */
265
+    public function isShareable() {
266
+        return $this->getFileInfo(false)->isShareable();
267
+    }
268
+
269
+    /**
270
+     * @return bool
271
+     * @throws InvalidPathException
272
+     * @throws NotFoundException
273
+     */
274
+    public function isCreatable() {
275
+        return $this->getFileInfo(false)->isCreatable();
276
+    }
277
+
278
+    public function getParent(): INode|IRootFolder {
279
+        if ($this->parent === null) {
280
+            $newPath = dirname($this->path);
281
+            if ($newPath === '' || $newPath === '.' || $newPath === '/') {
282
+                return $this->root;
283
+            }
284
+
285
+            // Manually fetch the parent if the current node doesn't have a file info yet
286
+            try {
287
+                $fileInfo = $this->getFileInfo();
288
+            } catch (NotFoundException) {
289
+                $this->parent = $this->root->get($newPath);
290
+                /** @var \OCP\Files\Folder $this->parent */
291
+                return $this->parent;
292
+            }
293
+
294
+            // gather the metadata we already know about our parent
295
+            $parentData = [
296
+                'path' => $newPath,
297
+                'fileid' => $fileInfo->getParentId(),
298
+            ];
299
+
300
+            // and create lazy folder with it instead of always querying
301
+            $this->parent = new LazyFolder($this->root, function () use ($newPath) {
302
+                return $this->root->get($newPath);
303
+            }, $parentData);
304
+        }
305
+
306
+        return $this->parent;
307
+    }
308
+
309
+    /**
310
+     * @return string
311
+     */
312
+    public function getName() {
313
+        return basename($this->path);
314
+    }
315
+
316
+    /**
317
+     * @param string $path
318
+     * @return string
319
+     */
320
+    protected function normalizePath($path) {
321
+        return PathHelper::normalizePath($path);
322
+    }
323
+
324
+    /**
325
+     * check if the requested path is valid
326
+     *
327
+     * @param string $path
328
+     * @return bool
329
+     */
330
+    public function isValidPath($path) {
331
+        return Filesystem::isValidPath($path);
332
+    }
333
+
334
+    public function isMounted() {
335
+        return $this->getFileInfo(false)->isMounted();
336
+    }
337
+
338
+    public function isShared() {
339
+        return $this->getFileInfo(false)->isShared();
340
+    }
341
+
342
+    public function getMimeType(): string {
343
+        return $this->getFileInfo(false)->getMimetype();
344
+    }
345
+
346
+    public function getMimePart() {
347
+        return $this->getFileInfo(false)->getMimePart();
348
+    }
349
+
350
+    public function getType() {
351
+        return $this->getFileInfo(false)->getType();
352
+    }
353
+
354
+    public function isEncrypted() {
355
+        return $this->getFileInfo(false)->isEncrypted();
356
+    }
357
+
358
+    public function getMountPoint() {
359
+        return $this->getFileInfo(false)->getMountPoint();
360
+    }
361
+
362
+    public function getOwner() {
363
+        return $this->getFileInfo(false)->getOwner();
364
+    }
365
+
366
+    public function getChecksum() {
367
+    }
368
+
369
+    public function getExtension(): string {
370
+        return $this->getFileInfo(false)->getExtension();
371
+    }
372
+
373
+    /**
374
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
375
+     * @throws LockedException
376
+     */
377
+    public function lock($type) {
378
+        $this->view->lockFile($this->path, $type);
379
+    }
380
+
381
+    /**
382
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
383
+     * @throws LockedException
384
+     */
385
+    public function changeLock($type) {
386
+        $this->view->changeLock($this->path, $type);
387
+    }
388
+
389
+    /**
390
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
391
+     * @throws LockedException
392
+     */
393
+    public function unlock($type) {
394
+        $this->view->unlockFile($this->path, $type);
395
+    }
396
+
397
+    /**
398
+     * @param string $targetPath
399
+     * @return INode
400
+     * @throws InvalidPathException
401
+     * @throws NotFoundException
402
+     * @throws NotPermittedException if copy not allowed or failed
403
+     */
404
+    public function copy($targetPath) {
405
+        $targetPath = $this->normalizePath($targetPath);
406
+        $parent = $this->root->get(dirname($targetPath));
407
+        if ($parent instanceof Folder && $this->isValidPath($targetPath) && $parent->isCreatable()) {
408
+            $nonExisting = $this->createNonExistingNode($targetPath);
409
+            $this->sendHooks(['preCopy'], [$this, $nonExisting]);
410
+            $this->sendHooks(['preWrite'], [$nonExisting]);
411
+            if (!$this->view->copy($this->path, $targetPath)) {
412
+                throw new NotPermittedException('Could not copy ' . $this->path . ' to ' . $targetPath);
413
+            }
414
+            $targetNode = $this->root->get($targetPath);
415
+            $this->sendHooks(['postCopy'], [$this, $targetNode]);
416
+            $this->sendHooks(['postWrite'], [$targetNode]);
417
+            return $targetNode;
418
+        } else {
419
+            throw new NotPermittedException('No permission to copy to path ' . $targetPath);
420
+        }
421
+    }
422
+
423
+    /**
424
+     * @param string $targetPath
425
+     * @return INode
426
+     * @throws InvalidPathException
427
+     * @throws NotFoundException
428
+     * @throws NotPermittedException if move not allowed or failed
429
+     * @throws LockedException
430
+     */
431
+    public function move($targetPath) {
432
+        $targetPath = $this->normalizePath($targetPath);
433
+        $parent = $this->root->get(dirname($targetPath));
434
+        if (
435
+            ($parent instanceof Folder)
436
+            && $this->isValidPath($targetPath)
437
+            && (
438
+                $parent->isCreatable()
439
+                || (
440
+                    $parent->getInternalPath() === ''
441
+                    && ($parent->getMountPoint() instanceof MoveableMount)
442
+                )
443
+            )
444
+        ) {
445
+            $nonExisting = $this->createNonExistingNode($targetPath);
446
+            $this->sendHooks(['preRename'], [$this, $nonExisting]);
447
+            $this->sendHooks(['preWrite'], [$nonExisting]);
448
+            if (!$this->view->rename($this->path, $targetPath)) {
449
+                throw new NotPermittedException('Could not move ' . $this->path . ' to ' . $targetPath);
450
+            }
451
+
452
+            $mountPoint = $this->getMountPoint();
453
+            if ($mountPoint) {
454
+                // update the cached fileinfo with the new (internal) path
455
+                /** @var \OC\Files\FileInfo $oldFileInfo */
456
+                $oldFileInfo = $this->getFileInfo();
457
+                $this->fileInfo = new \OC\Files\FileInfo($targetPath, $oldFileInfo->getStorage(), $mountPoint->getInternalPath($targetPath), $oldFileInfo->getData(), $mountPoint, $oldFileInfo->getOwner());
458
+            }
459
+
460
+            $targetNode = $this->root->get($targetPath);
461
+            $this->sendHooks(['postRename'], [$this, $targetNode]);
462
+            $this->sendHooks(['postWrite'], [$targetNode]);
463
+            $this->path = $targetPath;
464
+            return $targetNode;
465
+        } else {
466
+            throw new NotPermittedException('No permission to move to path ' . $targetPath);
467
+        }
468
+    }
469
+
470
+    public function getCreationTime(): int {
471
+        return $this->getFileInfo()->getCreationTime();
472
+    }
473
+
474
+    public function getUploadTime(): int {
475
+        return $this->getFileInfo()->getUploadTime();
476
+    }
477
+
478
+    public function getParentId(): int {
479
+        return $this->fileInfo->getParentId();
480
+    }
481
+
482
+    /**
483
+     * @inheritDoc
484
+     * @return array<string, int|string|bool|float|string[]|int[]>
485
+     */
486
+    public function getMetadata(): array {
487
+        return $this->fileInfo->getMetadata();
488
+    }
489 489
 }
Please login to merge, or discard this patch.
lib/private/Files/Node/LazyFolder.php 1 patch
Indentation   +538 added lines, -538 removed lines patch added patch discarded remove patch
@@ -24,542 +24,542 @@
 block discarded – undo
24 24
  * @package OC\Files\Node
25 25
  */
26 26
 class LazyFolder implements Folder {
27
-	/** @var \Closure(): Folder */
28
-	private \Closure $folderClosure;
29
-	protected ?Folder $folder = null;
30
-	protected IRootFolder $rootFolder;
31
-	protected array $data;
32
-
33
-	/**
34
-	 * @param IRootFolder $rootFolder
35
-	 * @param \Closure(): Folder $folderClosure
36
-	 * @param array $data
37
-	 */
38
-	public function __construct(IRootFolder $rootFolder, \Closure $folderClosure, array $data = []) {
39
-		$this->rootFolder = $rootFolder;
40
-		$this->folderClosure = $folderClosure;
41
-		$this->data = $data;
42
-	}
43
-
44
-	protected function getRootFolder(): IRootFolder {
45
-		return $this->rootFolder;
46
-	}
47
-
48
-	protected function getRealFolder(): Folder {
49
-		if ($this->folder === null) {
50
-			$this->folder = call_user_func($this->folderClosure);
51
-		}
52
-		return $this->folder;
53
-	}
54
-
55
-	/**
56
-	 * Magic method to first get the real rootFolder and then
57
-	 * call $method with $args on it
58
-	 *
59
-	 * @param $method
60
-	 * @param $args
61
-	 * @return mixed
62
-	 */
63
-	public function __call($method, $args) {
64
-		return call_user_func_array([$this->getRealFolder(), $method], $args);
65
-	}
66
-
67
-	/**
68
-	 * @inheritDoc
69
-	 */
70
-	public function getUser() {
71
-		return $this->__call(__FUNCTION__, func_get_args());
72
-	}
73
-
74
-	/**
75
-	 * @inheritDoc
76
-	 */
77
-	public function listen($scope, $method, callable $callback) {
78
-		$this->__call(__FUNCTION__, func_get_args());
79
-	}
80
-
81
-	/**
82
-	 * @inheritDoc
83
-	 */
84
-	public function removeListener($scope = null, $method = null, ?callable $callback = null) {
85
-		$this->__call(__FUNCTION__, func_get_args());
86
-	}
87
-
88
-	/**
89
-	 * @inheritDoc
90
-	 */
91
-	public function emit($scope, $method, $arguments = []) {
92
-		$this->__call(__FUNCTION__, func_get_args());
93
-	}
94
-
95
-	/**
96
-	 * @inheritDoc
97
-	 */
98
-	public function mount($storage, $mountPoint, $arguments = []) {
99
-		$this->__call(__FUNCTION__, func_get_args());
100
-	}
101
-
102
-	/**
103
-	 * @inheritDoc
104
-	 */
105
-	public function getMount(string $mountPoint): IMountPoint {
106
-		return $this->__call(__FUNCTION__, func_get_args());
107
-	}
108
-
109
-	/**
110
-	 * @return IMountPoint[]
111
-	 */
112
-	public function getMountsIn(string $mountPoint): array {
113
-		return $this->__call(__FUNCTION__, func_get_args());
114
-	}
115
-
116
-	/**
117
-	 * @inheritDoc
118
-	 */
119
-	public function getMountByStorageId($storageId) {
120
-		return $this->__call(__FUNCTION__, func_get_args());
121
-	}
122
-
123
-	/**
124
-	 * @inheritDoc
125
-	 */
126
-	public function getMountByNumericStorageId($numericId) {
127
-		return $this->__call(__FUNCTION__, func_get_args());
128
-	}
129
-
130
-	/**
131
-	 * @inheritDoc
132
-	 */
133
-	public function unMount($mount) {
134
-		$this->__call(__FUNCTION__, func_get_args());
135
-	}
136
-
137
-	public function get($path) {
138
-		return $this->getRootFolder()->get($this->getFullPath($path));
139
-	}
140
-
141
-	/**
142
-	 * @inheritDoc
143
-	 */
144
-	public function rename($targetPath) {
145
-		return $this->__call(__FUNCTION__, func_get_args());
146
-	}
147
-
148
-	/**
149
-	 * @inheritDoc
150
-	 */
151
-	public function delete() {
152
-		return $this->__call(__FUNCTION__, func_get_args());
153
-	}
154
-
155
-	/**
156
-	 * @inheritDoc
157
-	 */
158
-	public function copy($targetPath) {
159
-		return $this->__call(__FUNCTION__, func_get_args());
160
-	}
161
-
162
-	/**
163
-	 * @inheritDoc
164
-	 */
165
-	public function touch($mtime = null) {
166
-		$this->__call(__FUNCTION__, func_get_args());
167
-	}
168
-
169
-	/**
170
-	 * @inheritDoc
171
-	 */
172
-	public function getStorage() {
173
-		return $this->__call(__FUNCTION__, func_get_args());
174
-	}
175
-
176
-	/**
177
-	 * @inheritDoc
178
-	 */
179
-	public function getPath() {
180
-		if (isset($this->data['path'])) {
181
-			return $this->data['path'];
182
-		}
183
-		return $this->__call(__FUNCTION__, func_get_args());
184
-	}
185
-
186
-	/**
187
-	 * @inheritDoc
188
-	 */
189
-	public function getInternalPath() {
190
-		return $this->__call(__FUNCTION__, func_get_args());
191
-	}
192
-
193
-	/**
194
-	 * @inheritDoc
195
-	 */
196
-	public function getId() {
197
-		if (isset($this->data['fileid'])) {
198
-			return $this->data['fileid'];
199
-		}
200
-		return $this->__call(__FUNCTION__, func_get_args());
201
-	}
202
-
203
-	/**
204
-	 * @inheritDoc
205
-	 */
206
-	public function stat() {
207
-		return $this->__call(__FUNCTION__, func_get_args());
208
-	}
209
-
210
-	/**
211
-	 * @inheritDoc
212
-	 */
213
-	public function getMTime() {
214
-		if (isset($this->data['mtime'])) {
215
-			return $this->data['mtime'];
216
-		}
217
-		return $this->__call(__FUNCTION__, func_get_args());
218
-	}
219
-
220
-	/**
221
-	 * @inheritDoc
222
-	 */
223
-	public function getSize($includeMounts = true): int|float {
224
-		if (isset($this->data['size'])) {
225
-			return $this->data['size'];
226
-		}
227
-		return $this->__call(__FUNCTION__, func_get_args());
228
-	}
229
-
230
-	/**
231
-	 * @inheritDoc
232
-	 */
233
-	public function getEtag() {
234
-		if (isset($this->data['etag'])) {
235
-			return $this->data['etag'];
236
-		}
237
-		return $this->__call(__FUNCTION__, func_get_args());
238
-	}
239
-
240
-	/**
241
-	 * @inheritDoc
242
-	 */
243
-	public function getPermissions() {
244
-		if (isset($this->data['permissions'])) {
245
-			return $this->data['permissions'];
246
-		}
247
-		return $this->__call(__FUNCTION__, func_get_args());
248
-	}
249
-
250
-	/**
251
-	 * @inheritDoc
252
-	 */
253
-	public function isReadable() {
254
-		if (isset($this->data['permissions'])) {
255
-			return ($this->data['permissions'] & Constants::PERMISSION_READ) == Constants::PERMISSION_READ;
256
-		}
257
-		return $this->__call(__FUNCTION__, func_get_args());
258
-	}
259
-
260
-	/**
261
-	 * @inheritDoc
262
-	 */
263
-	public function isUpdateable() {
264
-		if (isset($this->data['permissions'])) {
265
-			return ($this->data['permissions'] & Constants::PERMISSION_UPDATE) == Constants::PERMISSION_UPDATE;
266
-		}
267
-		return $this->__call(__FUNCTION__, func_get_args());
268
-	}
269
-
270
-	/**
271
-	 * @inheritDoc
272
-	 */
273
-	public function isDeletable() {
274
-		if (isset($this->data['permissions'])) {
275
-			return ($this->data['permissions'] & Constants::PERMISSION_DELETE) == Constants::PERMISSION_DELETE;
276
-		}
277
-		return $this->__call(__FUNCTION__, func_get_args());
278
-	}
279
-
280
-	/**
281
-	 * @inheritDoc
282
-	 */
283
-	public function isShareable() {
284
-		if (isset($this->data['permissions'])) {
285
-			return ($this->data['permissions'] & Constants::PERMISSION_SHARE) == Constants::PERMISSION_SHARE;
286
-		}
287
-		return $this->__call(__FUNCTION__, func_get_args());
288
-	}
289
-
290
-	/**
291
-	 * @inheritDoc
292
-	 */
293
-	public function getParent() {
294
-		return $this->__call(__FUNCTION__, func_get_args());
295
-	}
296
-
297
-	/**
298
-	 * @inheritDoc
299
-	 */
300
-	public function getName() {
301
-		if (isset($this->data['path'])) {
302
-			return basename($this->data['path']);
303
-		}
304
-		if (isset($this->data['name'])) {
305
-			return $this->data['name'];
306
-		}
307
-		return $this->__call(__FUNCTION__, func_get_args());
308
-	}
309
-
310
-	/**
311
-	 * @inheritDoc
312
-	 */
313
-	public function getUserFolder($userId) {
314
-		return $this->__call(__FUNCTION__, func_get_args());
315
-	}
316
-
317
-	public function getMimetype(): string {
318
-		if (isset($this->data['mimetype'])) {
319
-			return $this->data['mimetype'];
320
-		}
321
-		return $this->__call(__FUNCTION__, func_get_args());
322
-	}
323
-
324
-	/**
325
-	 * @inheritDoc
326
-	 */
327
-	public function getMimePart() {
328
-		if (isset($this->data['mimetype'])) {
329
-			[$part,] = explode('/', $this->data['mimetype']);
330
-			return $part;
331
-		}
332
-		return $this->__call(__FUNCTION__, func_get_args());
333
-	}
334
-
335
-	/**
336
-	 * @inheritDoc
337
-	 */
338
-	public function isEncrypted() {
339
-		return $this->__call(__FUNCTION__, func_get_args());
340
-	}
341
-
342
-	/**
343
-	 * @inheritDoc
344
-	 */
345
-	public function getType() {
346
-		if (isset($this->data['type'])) {
347
-			return $this->data['type'];
348
-		}
349
-		return $this->__call(__FUNCTION__, func_get_args());
350
-	}
351
-
352
-	/**
353
-	 * @inheritDoc
354
-	 */
355
-	public function isShared() {
356
-		return $this->__call(__FUNCTION__, func_get_args());
357
-	}
358
-
359
-	/**
360
-	 * @inheritDoc
361
-	 */
362
-	public function isMounted() {
363
-		return $this->__call(__FUNCTION__, func_get_args());
364
-	}
365
-
366
-	/**
367
-	 * @inheritDoc
368
-	 */
369
-	public function getMountPoint() {
370
-		return $this->__call(__FUNCTION__, func_get_args());
371
-	}
372
-
373
-	/**
374
-	 * @inheritDoc
375
-	 */
376
-	public function getOwner() {
377
-		return $this->__call(__FUNCTION__, func_get_args());
378
-	}
379
-
380
-	/**
381
-	 * @inheritDoc
382
-	 */
383
-	public function getChecksum() {
384
-		return $this->__call(__FUNCTION__, func_get_args());
385
-	}
386
-
387
-	public function getExtension(): string {
388
-		return $this->__call(__FUNCTION__, func_get_args());
389
-	}
390
-
391
-	/**
392
-	 * @inheritDoc
393
-	 */
394
-	public function getFullPath($path) {
395
-		if (isset($this->data['path'])) {
396
-			$path = PathHelper::normalizePath($path);
397
-			if (!Filesystem::isValidPath($path)) {
398
-				throw new NotPermittedException('Invalid path "' . $path . '"');
399
-			}
400
-			return $this->data['path'] . $path;
401
-		}
402
-		return $this->__call(__FUNCTION__, func_get_args());
403
-	}
404
-
405
-	/**
406
-	 * @inheritDoc
407
-	 */
408
-	public function isSubNode($node) {
409
-		return $this->__call(__FUNCTION__, func_get_args());
410
-	}
411
-
412
-	/**
413
-	 * @inheritDoc
414
-	 */
415
-	public function getDirectoryListing() {
416
-		return $this->__call(__FUNCTION__, func_get_args());
417
-	}
418
-
419
-	public function nodeExists($path) {
420
-		return $this->__call(__FUNCTION__, func_get_args());
421
-	}
422
-
423
-	/**
424
-	 * @inheritDoc
425
-	 */
426
-	public function newFolder($path) {
427
-		return $this->__call(__FUNCTION__, func_get_args());
428
-	}
429
-
430
-	/**
431
-	 * @inheritDoc
432
-	 */
433
-	public function newFile($path, $content = null) {
434
-		return $this->__call(__FUNCTION__, func_get_args());
435
-	}
436
-
437
-	/**
438
-	 * @inheritDoc
439
-	 */
440
-	public function search($query) {
441
-		return $this->__call(__FUNCTION__, func_get_args());
442
-	}
443
-
444
-	/**
445
-	 * @inheritDoc
446
-	 */
447
-	public function searchByMime($mimetype) {
448
-		return $this->__call(__FUNCTION__, func_get_args());
449
-	}
450
-
451
-	/**
452
-	 * @inheritDoc
453
-	 */
454
-	public function searchByTag($tag, $userId) {
455
-		return $this->__call(__FUNCTION__, func_get_args());
456
-	}
457
-
458
-	public function searchBySystemTag(string $tagName, string $userId, int $limit = 0, int $offset = 0) {
459
-		return $this->__call(__FUNCTION__, func_get_args());
460
-	}
461
-
462
-	/**
463
-	 * @inheritDoc
464
-	 */
465
-	public function getById($id) {
466
-		return $this->getRootFolder()->getByIdInPath((int)$id, $this->getPath());
467
-	}
468
-
469
-	public function getFirstNodeById(int $id): ?\OCP\Files\Node {
470
-		return $this->getRootFolder()->getFirstNodeByIdInPath($id, $this->getPath());
471
-	}
472
-
473
-	/**
474
-	 * @inheritDoc
475
-	 */
476
-	public function getFreeSpace() {
477
-		return $this->__call(__FUNCTION__, func_get_args());
478
-	}
479
-
480
-	/**
481
-	 * @inheritDoc
482
-	 */
483
-	public function isCreatable() {
484
-		return $this->__call(__FUNCTION__, func_get_args());
485
-	}
486
-
487
-	/**
488
-	 * @inheritDoc
489
-	 */
490
-	public function getNonExistingName($name) {
491
-		return $this->__call(__FUNCTION__, func_get_args());
492
-	}
493
-
494
-	/**
495
-	 * @inheritDoc
496
-	 */
497
-	public function move($targetPath) {
498
-		return $this->__call(__FUNCTION__, func_get_args());
499
-	}
500
-
501
-	/**
502
-	 * @inheritDoc
503
-	 */
504
-	public function lock($type) {
505
-		return $this->__call(__FUNCTION__, func_get_args());
506
-	}
507
-
508
-	/**
509
-	 * @inheritDoc
510
-	 */
511
-	public function changeLock($targetType) {
512
-		return $this->__call(__FUNCTION__, func_get_args());
513
-	}
514
-
515
-	/**
516
-	 * @inheritDoc
517
-	 */
518
-	public function unlock($type) {
519
-		return $this->__call(__FUNCTION__, func_get_args());
520
-	}
521
-
522
-	/**
523
-	 * @inheritDoc
524
-	 */
525
-	public function getRecent($limit, $offset = 0) {
526
-		return $this->__call(__FUNCTION__, func_get_args());
527
-	}
528
-
529
-	/**
530
-	 * @inheritDoc
531
-	 */
532
-	public function getCreationTime(): int {
533
-		return $this->__call(__FUNCTION__, func_get_args());
534
-	}
535
-
536
-	/**
537
-	 * @inheritDoc
538
-	 */
539
-	public function getUploadTime(): int {
540
-		return $this->__call(__FUNCTION__, func_get_args());
541
-	}
542
-
543
-	public function getRelativePath($path) {
544
-		return PathHelper::getRelativePath($this->getPath(), $path);
545
-	}
546
-
547
-	public function getParentId(): int {
548
-		if (isset($this->data['parent'])) {
549
-			return $this->data['parent'];
550
-		}
551
-		return $this->__call(__FUNCTION__, func_get_args());
552
-	}
553
-
554
-	/**
555
-	 * @inheritDoc
556
-	 * @return array<string, int|string|bool|float|string[]|int[]>
557
-	 */
558
-	public function getMetadata(): array {
559
-		return $this->data['metadata'] ?? $this->__call(__FUNCTION__, func_get_args());
560
-	}
561
-
562
-	public function verifyPath($fileName, $readonly = false): void {
563
-		$this->__call(__FUNCTION__, func_get_args());
564
-	}
27
+    /** @var \Closure(): Folder */
28
+    private \Closure $folderClosure;
29
+    protected ?Folder $folder = null;
30
+    protected IRootFolder $rootFolder;
31
+    protected array $data;
32
+
33
+    /**
34
+     * @param IRootFolder $rootFolder
35
+     * @param \Closure(): Folder $folderClosure
36
+     * @param array $data
37
+     */
38
+    public function __construct(IRootFolder $rootFolder, \Closure $folderClosure, array $data = []) {
39
+        $this->rootFolder = $rootFolder;
40
+        $this->folderClosure = $folderClosure;
41
+        $this->data = $data;
42
+    }
43
+
44
+    protected function getRootFolder(): IRootFolder {
45
+        return $this->rootFolder;
46
+    }
47
+
48
+    protected function getRealFolder(): Folder {
49
+        if ($this->folder === null) {
50
+            $this->folder = call_user_func($this->folderClosure);
51
+        }
52
+        return $this->folder;
53
+    }
54
+
55
+    /**
56
+     * Magic method to first get the real rootFolder and then
57
+     * call $method with $args on it
58
+     *
59
+     * @param $method
60
+     * @param $args
61
+     * @return mixed
62
+     */
63
+    public function __call($method, $args) {
64
+        return call_user_func_array([$this->getRealFolder(), $method], $args);
65
+    }
66
+
67
+    /**
68
+     * @inheritDoc
69
+     */
70
+    public function getUser() {
71
+        return $this->__call(__FUNCTION__, func_get_args());
72
+    }
73
+
74
+    /**
75
+     * @inheritDoc
76
+     */
77
+    public function listen($scope, $method, callable $callback) {
78
+        $this->__call(__FUNCTION__, func_get_args());
79
+    }
80
+
81
+    /**
82
+     * @inheritDoc
83
+     */
84
+    public function removeListener($scope = null, $method = null, ?callable $callback = null) {
85
+        $this->__call(__FUNCTION__, func_get_args());
86
+    }
87
+
88
+    /**
89
+     * @inheritDoc
90
+     */
91
+    public function emit($scope, $method, $arguments = []) {
92
+        $this->__call(__FUNCTION__, func_get_args());
93
+    }
94
+
95
+    /**
96
+     * @inheritDoc
97
+     */
98
+    public function mount($storage, $mountPoint, $arguments = []) {
99
+        $this->__call(__FUNCTION__, func_get_args());
100
+    }
101
+
102
+    /**
103
+     * @inheritDoc
104
+     */
105
+    public function getMount(string $mountPoint): IMountPoint {
106
+        return $this->__call(__FUNCTION__, func_get_args());
107
+    }
108
+
109
+    /**
110
+     * @return IMountPoint[]
111
+     */
112
+    public function getMountsIn(string $mountPoint): array {
113
+        return $this->__call(__FUNCTION__, func_get_args());
114
+    }
115
+
116
+    /**
117
+     * @inheritDoc
118
+     */
119
+    public function getMountByStorageId($storageId) {
120
+        return $this->__call(__FUNCTION__, func_get_args());
121
+    }
122
+
123
+    /**
124
+     * @inheritDoc
125
+     */
126
+    public function getMountByNumericStorageId($numericId) {
127
+        return $this->__call(__FUNCTION__, func_get_args());
128
+    }
129
+
130
+    /**
131
+     * @inheritDoc
132
+     */
133
+    public function unMount($mount) {
134
+        $this->__call(__FUNCTION__, func_get_args());
135
+    }
136
+
137
+    public function get($path) {
138
+        return $this->getRootFolder()->get($this->getFullPath($path));
139
+    }
140
+
141
+    /**
142
+     * @inheritDoc
143
+     */
144
+    public function rename($targetPath) {
145
+        return $this->__call(__FUNCTION__, func_get_args());
146
+    }
147
+
148
+    /**
149
+     * @inheritDoc
150
+     */
151
+    public function delete() {
152
+        return $this->__call(__FUNCTION__, func_get_args());
153
+    }
154
+
155
+    /**
156
+     * @inheritDoc
157
+     */
158
+    public function copy($targetPath) {
159
+        return $this->__call(__FUNCTION__, func_get_args());
160
+    }
161
+
162
+    /**
163
+     * @inheritDoc
164
+     */
165
+    public function touch($mtime = null) {
166
+        $this->__call(__FUNCTION__, func_get_args());
167
+    }
168
+
169
+    /**
170
+     * @inheritDoc
171
+     */
172
+    public function getStorage() {
173
+        return $this->__call(__FUNCTION__, func_get_args());
174
+    }
175
+
176
+    /**
177
+     * @inheritDoc
178
+     */
179
+    public function getPath() {
180
+        if (isset($this->data['path'])) {
181
+            return $this->data['path'];
182
+        }
183
+        return $this->__call(__FUNCTION__, func_get_args());
184
+    }
185
+
186
+    /**
187
+     * @inheritDoc
188
+     */
189
+    public function getInternalPath() {
190
+        return $this->__call(__FUNCTION__, func_get_args());
191
+    }
192
+
193
+    /**
194
+     * @inheritDoc
195
+     */
196
+    public function getId() {
197
+        if (isset($this->data['fileid'])) {
198
+            return $this->data['fileid'];
199
+        }
200
+        return $this->__call(__FUNCTION__, func_get_args());
201
+    }
202
+
203
+    /**
204
+     * @inheritDoc
205
+     */
206
+    public function stat() {
207
+        return $this->__call(__FUNCTION__, func_get_args());
208
+    }
209
+
210
+    /**
211
+     * @inheritDoc
212
+     */
213
+    public function getMTime() {
214
+        if (isset($this->data['mtime'])) {
215
+            return $this->data['mtime'];
216
+        }
217
+        return $this->__call(__FUNCTION__, func_get_args());
218
+    }
219
+
220
+    /**
221
+     * @inheritDoc
222
+     */
223
+    public function getSize($includeMounts = true): int|float {
224
+        if (isset($this->data['size'])) {
225
+            return $this->data['size'];
226
+        }
227
+        return $this->__call(__FUNCTION__, func_get_args());
228
+    }
229
+
230
+    /**
231
+     * @inheritDoc
232
+     */
233
+    public function getEtag() {
234
+        if (isset($this->data['etag'])) {
235
+            return $this->data['etag'];
236
+        }
237
+        return $this->__call(__FUNCTION__, func_get_args());
238
+    }
239
+
240
+    /**
241
+     * @inheritDoc
242
+     */
243
+    public function getPermissions() {
244
+        if (isset($this->data['permissions'])) {
245
+            return $this->data['permissions'];
246
+        }
247
+        return $this->__call(__FUNCTION__, func_get_args());
248
+    }
249
+
250
+    /**
251
+     * @inheritDoc
252
+     */
253
+    public function isReadable() {
254
+        if (isset($this->data['permissions'])) {
255
+            return ($this->data['permissions'] & Constants::PERMISSION_READ) == Constants::PERMISSION_READ;
256
+        }
257
+        return $this->__call(__FUNCTION__, func_get_args());
258
+    }
259
+
260
+    /**
261
+     * @inheritDoc
262
+     */
263
+    public function isUpdateable() {
264
+        if (isset($this->data['permissions'])) {
265
+            return ($this->data['permissions'] & Constants::PERMISSION_UPDATE) == Constants::PERMISSION_UPDATE;
266
+        }
267
+        return $this->__call(__FUNCTION__, func_get_args());
268
+    }
269
+
270
+    /**
271
+     * @inheritDoc
272
+     */
273
+    public function isDeletable() {
274
+        if (isset($this->data['permissions'])) {
275
+            return ($this->data['permissions'] & Constants::PERMISSION_DELETE) == Constants::PERMISSION_DELETE;
276
+        }
277
+        return $this->__call(__FUNCTION__, func_get_args());
278
+    }
279
+
280
+    /**
281
+     * @inheritDoc
282
+     */
283
+    public function isShareable() {
284
+        if (isset($this->data['permissions'])) {
285
+            return ($this->data['permissions'] & Constants::PERMISSION_SHARE) == Constants::PERMISSION_SHARE;
286
+        }
287
+        return $this->__call(__FUNCTION__, func_get_args());
288
+    }
289
+
290
+    /**
291
+     * @inheritDoc
292
+     */
293
+    public function getParent() {
294
+        return $this->__call(__FUNCTION__, func_get_args());
295
+    }
296
+
297
+    /**
298
+     * @inheritDoc
299
+     */
300
+    public function getName() {
301
+        if (isset($this->data['path'])) {
302
+            return basename($this->data['path']);
303
+        }
304
+        if (isset($this->data['name'])) {
305
+            return $this->data['name'];
306
+        }
307
+        return $this->__call(__FUNCTION__, func_get_args());
308
+    }
309
+
310
+    /**
311
+     * @inheritDoc
312
+     */
313
+    public function getUserFolder($userId) {
314
+        return $this->__call(__FUNCTION__, func_get_args());
315
+    }
316
+
317
+    public function getMimetype(): string {
318
+        if (isset($this->data['mimetype'])) {
319
+            return $this->data['mimetype'];
320
+        }
321
+        return $this->__call(__FUNCTION__, func_get_args());
322
+    }
323
+
324
+    /**
325
+     * @inheritDoc
326
+     */
327
+    public function getMimePart() {
328
+        if (isset($this->data['mimetype'])) {
329
+            [$part,] = explode('/', $this->data['mimetype']);
330
+            return $part;
331
+        }
332
+        return $this->__call(__FUNCTION__, func_get_args());
333
+    }
334
+
335
+    /**
336
+     * @inheritDoc
337
+     */
338
+    public function isEncrypted() {
339
+        return $this->__call(__FUNCTION__, func_get_args());
340
+    }
341
+
342
+    /**
343
+     * @inheritDoc
344
+     */
345
+    public function getType() {
346
+        if (isset($this->data['type'])) {
347
+            return $this->data['type'];
348
+        }
349
+        return $this->__call(__FUNCTION__, func_get_args());
350
+    }
351
+
352
+    /**
353
+     * @inheritDoc
354
+     */
355
+    public function isShared() {
356
+        return $this->__call(__FUNCTION__, func_get_args());
357
+    }
358
+
359
+    /**
360
+     * @inheritDoc
361
+     */
362
+    public function isMounted() {
363
+        return $this->__call(__FUNCTION__, func_get_args());
364
+    }
365
+
366
+    /**
367
+     * @inheritDoc
368
+     */
369
+    public function getMountPoint() {
370
+        return $this->__call(__FUNCTION__, func_get_args());
371
+    }
372
+
373
+    /**
374
+     * @inheritDoc
375
+     */
376
+    public function getOwner() {
377
+        return $this->__call(__FUNCTION__, func_get_args());
378
+    }
379
+
380
+    /**
381
+     * @inheritDoc
382
+     */
383
+    public function getChecksum() {
384
+        return $this->__call(__FUNCTION__, func_get_args());
385
+    }
386
+
387
+    public function getExtension(): string {
388
+        return $this->__call(__FUNCTION__, func_get_args());
389
+    }
390
+
391
+    /**
392
+     * @inheritDoc
393
+     */
394
+    public function getFullPath($path) {
395
+        if (isset($this->data['path'])) {
396
+            $path = PathHelper::normalizePath($path);
397
+            if (!Filesystem::isValidPath($path)) {
398
+                throw new NotPermittedException('Invalid path "' . $path . '"');
399
+            }
400
+            return $this->data['path'] . $path;
401
+        }
402
+        return $this->__call(__FUNCTION__, func_get_args());
403
+    }
404
+
405
+    /**
406
+     * @inheritDoc
407
+     */
408
+    public function isSubNode($node) {
409
+        return $this->__call(__FUNCTION__, func_get_args());
410
+    }
411
+
412
+    /**
413
+     * @inheritDoc
414
+     */
415
+    public function getDirectoryListing() {
416
+        return $this->__call(__FUNCTION__, func_get_args());
417
+    }
418
+
419
+    public function nodeExists($path) {
420
+        return $this->__call(__FUNCTION__, func_get_args());
421
+    }
422
+
423
+    /**
424
+     * @inheritDoc
425
+     */
426
+    public function newFolder($path) {
427
+        return $this->__call(__FUNCTION__, func_get_args());
428
+    }
429
+
430
+    /**
431
+     * @inheritDoc
432
+     */
433
+    public function newFile($path, $content = null) {
434
+        return $this->__call(__FUNCTION__, func_get_args());
435
+    }
436
+
437
+    /**
438
+     * @inheritDoc
439
+     */
440
+    public function search($query) {
441
+        return $this->__call(__FUNCTION__, func_get_args());
442
+    }
443
+
444
+    /**
445
+     * @inheritDoc
446
+     */
447
+    public function searchByMime($mimetype) {
448
+        return $this->__call(__FUNCTION__, func_get_args());
449
+    }
450
+
451
+    /**
452
+     * @inheritDoc
453
+     */
454
+    public function searchByTag($tag, $userId) {
455
+        return $this->__call(__FUNCTION__, func_get_args());
456
+    }
457
+
458
+    public function searchBySystemTag(string $tagName, string $userId, int $limit = 0, int $offset = 0) {
459
+        return $this->__call(__FUNCTION__, func_get_args());
460
+    }
461
+
462
+    /**
463
+     * @inheritDoc
464
+     */
465
+    public function getById($id) {
466
+        return $this->getRootFolder()->getByIdInPath((int)$id, $this->getPath());
467
+    }
468
+
469
+    public function getFirstNodeById(int $id): ?\OCP\Files\Node {
470
+        return $this->getRootFolder()->getFirstNodeByIdInPath($id, $this->getPath());
471
+    }
472
+
473
+    /**
474
+     * @inheritDoc
475
+     */
476
+    public function getFreeSpace() {
477
+        return $this->__call(__FUNCTION__, func_get_args());
478
+    }
479
+
480
+    /**
481
+     * @inheritDoc
482
+     */
483
+    public function isCreatable() {
484
+        return $this->__call(__FUNCTION__, func_get_args());
485
+    }
486
+
487
+    /**
488
+     * @inheritDoc
489
+     */
490
+    public function getNonExistingName($name) {
491
+        return $this->__call(__FUNCTION__, func_get_args());
492
+    }
493
+
494
+    /**
495
+     * @inheritDoc
496
+     */
497
+    public function move($targetPath) {
498
+        return $this->__call(__FUNCTION__, func_get_args());
499
+    }
500
+
501
+    /**
502
+     * @inheritDoc
503
+     */
504
+    public function lock($type) {
505
+        return $this->__call(__FUNCTION__, func_get_args());
506
+    }
507
+
508
+    /**
509
+     * @inheritDoc
510
+     */
511
+    public function changeLock($targetType) {
512
+        return $this->__call(__FUNCTION__, func_get_args());
513
+    }
514
+
515
+    /**
516
+     * @inheritDoc
517
+     */
518
+    public function unlock($type) {
519
+        return $this->__call(__FUNCTION__, func_get_args());
520
+    }
521
+
522
+    /**
523
+     * @inheritDoc
524
+     */
525
+    public function getRecent($limit, $offset = 0) {
526
+        return $this->__call(__FUNCTION__, func_get_args());
527
+    }
528
+
529
+    /**
530
+     * @inheritDoc
531
+     */
532
+    public function getCreationTime(): int {
533
+        return $this->__call(__FUNCTION__, func_get_args());
534
+    }
535
+
536
+    /**
537
+     * @inheritDoc
538
+     */
539
+    public function getUploadTime(): int {
540
+        return $this->__call(__FUNCTION__, func_get_args());
541
+    }
542
+
543
+    public function getRelativePath($path) {
544
+        return PathHelper::getRelativePath($this->getPath(), $path);
545
+    }
546
+
547
+    public function getParentId(): int {
548
+        if (isset($this->data['parent'])) {
549
+            return $this->data['parent'];
550
+        }
551
+        return $this->__call(__FUNCTION__, func_get_args());
552
+    }
553
+
554
+    /**
555
+     * @inheritDoc
556
+     * @return array<string, int|string|bool|float|string[]|int[]>
557
+     */
558
+    public function getMetadata(): array {
559
+        return $this->data['metadata'] ?? $this->__call(__FUNCTION__, func_get_args());
560
+    }
561
+
562
+    public function verifyPath($fileName, $readonly = false): void {
563
+        $this->__call(__FUNCTION__, func_get_args());
564
+    }
565 565
 }
Please login to merge, or discard this patch.
lib/private/Files/Node/NonExistingFile.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -10,127 +10,127 @@
 block discarded – undo
10 10
 use OCP\Files\NotFoundException;
11 11
 
12 12
 class NonExistingFile extends File {
13
-	/**
14
-	 * @param string $newPath
15
-	 * @throws \OCP\Files\NotFoundException
16
-	 */
17
-	public function rename($newPath) {
18
-		throw new NotFoundException();
19
-	}
20
-
21
-	public function delete() {
22
-		throw new NotFoundException();
23
-	}
24
-
25
-	public function copy($targetPath) {
26
-		throw new NotFoundException();
27
-	}
28
-
29
-	public function touch($mtime = null) {
30
-		throw new NotFoundException();
31
-	}
32
-
33
-	public function getId() {
34
-		if ($this->fileInfo) {
35
-			return parent::getId();
36
-		} else {
37
-			throw new NotFoundException();
38
-		}
39
-	}
40
-
41
-	public function getInternalPath() {
42
-		if ($this->fileInfo) {
43
-			return parent::getInternalPath();
44
-		} else {
45
-			return $this->getParent()->getMountPoint()->getInternalPath($this->getPath());
46
-		}
47
-	}
48
-
49
-	public function stat() {
50
-		throw new NotFoundException();
51
-	}
52
-
53
-	public function getMTime() {
54
-		if ($this->fileInfo) {
55
-			return parent::getMTime();
56
-		} else {
57
-			throw new NotFoundException();
58
-		}
59
-	}
60
-
61
-	public function getSize($includeMounts = true): int|float {
62
-		if ($this->fileInfo) {
63
-			return parent::getSize($includeMounts);
64
-		} else {
65
-			throw new NotFoundException();
66
-		}
67
-	}
68
-
69
-	public function getEtag() {
70
-		if ($this->fileInfo) {
71
-			return parent::getEtag();
72
-		} else {
73
-			throw new NotFoundException();
74
-		}
75
-	}
76
-
77
-	public function getPermissions() {
78
-		if ($this->fileInfo) {
79
-			return parent::getPermissions();
80
-		} else {
81
-			throw new NotFoundException();
82
-		}
83
-	}
84
-
85
-	public function isReadable() {
86
-		if ($this->fileInfo) {
87
-			return parent::isReadable();
88
-		} else {
89
-			throw new NotFoundException();
90
-		}
91
-	}
92
-
93
-	public function isUpdateable() {
94
-		if ($this->fileInfo) {
95
-			return parent::isUpdateable();
96
-		} else {
97
-			throw new NotFoundException();
98
-		}
99
-	}
100
-
101
-	public function isDeletable() {
102
-		if ($this->fileInfo) {
103
-			return parent::isDeletable();
104
-		} else {
105
-			throw new NotFoundException();
106
-		}
107
-	}
108
-
109
-	public function isShareable() {
110
-		if ($this->fileInfo) {
111
-			return parent::isShareable();
112
-		} else {
113
-			throw new NotFoundException();
114
-		}
115
-	}
116
-
117
-	public function getContent() {
118
-		throw new NotFoundException();
119
-	}
120
-
121
-	public function putContent($data) {
122
-		throw new NotFoundException();
123
-	}
124
-
125
-	public function getMimeType(): string {
126
-		if ($this->fileInfo) {
127
-			return parent::getMimeType();
128
-		} else {
129
-			throw new NotFoundException();
130
-		}
131
-	}
132
-
133
-	public function fopen($mode) {
134
-		throw new NotFoundException();
135
-	}
13
+    /**
14
+     * @param string $newPath
15
+     * @throws \OCP\Files\NotFoundException
16
+     */
17
+    public function rename($newPath) {
18
+        throw new NotFoundException();
19
+    }
20
+
21
+    public function delete() {
22
+        throw new NotFoundException();
23
+    }
24
+
25
+    public function copy($targetPath) {
26
+        throw new NotFoundException();
27
+    }
28
+
29
+    public function touch($mtime = null) {
30
+        throw new NotFoundException();
31
+    }
32
+
33
+    public function getId() {
34
+        if ($this->fileInfo) {
35
+            return parent::getId();
36
+        } else {
37
+            throw new NotFoundException();
38
+        }
39
+    }
40
+
41
+    public function getInternalPath() {
42
+        if ($this->fileInfo) {
43
+            return parent::getInternalPath();
44
+        } else {
45
+            return $this->getParent()->getMountPoint()->getInternalPath($this->getPath());
46
+        }
47
+    }
48
+
49
+    public function stat() {
50
+        throw new NotFoundException();
51
+    }
52
+
53
+    public function getMTime() {
54
+        if ($this->fileInfo) {
55
+            return parent::getMTime();
56
+        } else {
57
+            throw new NotFoundException();
58
+        }
59
+    }
60
+
61
+    public function getSize($includeMounts = true): int|float {
62
+        if ($this->fileInfo) {
63
+            return parent::getSize($includeMounts);
64
+        } else {
65
+            throw new NotFoundException();
66
+        }
67
+    }
68
+
69
+    public function getEtag() {
70
+        if ($this->fileInfo) {
71
+            return parent::getEtag();
72
+        } else {
73
+            throw new NotFoundException();
74
+        }
75
+    }
76
+
77
+    public function getPermissions() {
78
+        if ($this->fileInfo) {
79
+            return parent::getPermissions();
80
+        } else {
81
+            throw new NotFoundException();
82
+        }
83
+    }
84
+
85
+    public function isReadable() {
86
+        if ($this->fileInfo) {
87
+            return parent::isReadable();
88
+        } else {
89
+            throw new NotFoundException();
90
+        }
91
+    }
92
+
93
+    public function isUpdateable() {
94
+        if ($this->fileInfo) {
95
+            return parent::isUpdateable();
96
+        } else {
97
+            throw new NotFoundException();
98
+        }
99
+    }
100
+
101
+    public function isDeletable() {
102
+        if ($this->fileInfo) {
103
+            return parent::isDeletable();
104
+        } else {
105
+            throw new NotFoundException();
106
+        }
107
+    }
108
+
109
+    public function isShareable() {
110
+        if ($this->fileInfo) {
111
+            return parent::isShareable();
112
+        } else {
113
+            throw new NotFoundException();
114
+        }
115
+    }
116
+
117
+    public function getContent() {
118
+        throw new NotFoundException();
119
+    }
120
+
121
+    public function putContent($data) {
122
+        throw new NotFoundException();
123
+    }
124
+
125
+    public function getMimeType(): string {
126
+        if ($this->fileInfo) {
127
+            return parent::getMimeType();
128
+        } else {
129
+            throw new NotFoundException();
130
+        }
131
+    }
132
+
133
+    public function fopen($mode) {
134
+        throw new NotFoundException();
135
+    }
136 136
 }
Please login to merge, or discard this patch.
lib/private/Files/FileInfo.php 2 patches
Indentation   +372 added lines, -372 removed lines patch added patch discarded remove patch
@@ -18,376 +18,376 @@
 block discarded – undo
18 18
  * @template-implements \ArrayAccess<string,mixed>
19 19
  */
20 20
 class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
21
-	private array|ICacheEntry $data;
22
-	/**
23
-	 * @var string
24
-	 */
25
-	private $path;
26
-
27
-	/**
28
-	 * @var \OC\Files\Storage\Storage $storage
29
-	 */
30
-	private $storage;
31
-
32
-	/**
33
-	 * @var string
34
-	 */
35
-	private $internalPath;
36
-
37
-	/**
38
-	 * @var \OCP\Files\Mount\IMountPoint
39
-	 */
40
-	private $mount;
41
-
42
-	private ?IUser $owner;
43
-
44
-	/**
45
-	 * @var string[]
46
-	 */
47
-	private array $childEtags = [];
48
-
49
-	/**
50
-	 * @var IMountPoint[]
51
-	 */
52
-	private array $subMounts = [];
53
-
54
-	private bool $subMountsUsed = false;
55
-
56
-	/**
57
-	 * The size of the file/folder without any sub mount
58
-	 */
59
-	private int|float $rawSize = 0;
60
-
61
-	/**
62
-	 * @param string|boolean $path
63
-	 * @param Storage\Storage $storage
64
-	 * @param string $internalPath
65
-	 * @param array|ICacheEntry $data
66
-	 * @param IMountPoint $mount
67
-	 * @param ?IUser $owner
68
-	 */
69
-	public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) {
70
-		$this->path = $path;
71
-		$this->storage = $storage;
72
-		$this->internalPath = $internalPath;
73
-		$this->data = $data;
74
-		$this->mount = $mount;
75
-		$this->owner = $owner;
76
-		if (isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] !== 0) {
77
-			$this->rawSize = $this->data['unencrypted_size'];
78
-		} else {
79
-			$this->rawSize = $this->data['size'] ?? 0;
80
-		}
81
-	}
82
-
83
-	public function offsetSet($offset, $value): void {
84
-		if (is_null($offset)) {
85
-			throw new \TypeError('Null offset not supported');
86
-		}
87
-		$this->data[$offset] = $value;
88
-	}
89
-
90
-	public function offsetExists($offset): bool {
91
-		return isset($this->data[$offset]);
92
-	}
93
-
94
-	public function offsetUnset($offset): void {
95
-		unset($this->data[$offset]);
96
-	}
97
-
98
-	public function offsetGet(mixed $offset): mixed {
99
-		return match ($offset) {
100
-			'type' => $this->getType(),
101
-			'etag' => $this->getEtag(),
102
-			'size' => $this->getSize(),
103
-			'mtime' => $this->getMTime(),
104
-			'permissions' => $this->getPermissions(),
105
-			default => $this->data[$offset] ?? null,
106
-		};
107
-	}
108
-
109
-	/**
110
-	 * @return string
111
-	 */
112
-	public function getPath() {
113
-		return $this->path;
114
-	}
115
-
116
-	public function getStorage() {
117
-		return $this->storage;
118
-	}
119
-
120
-	/**
121
-	 * @return string
122
-	 */
123
-	public function getInternalPath() {
124
-		return $this->internalPath;
125
-	}
126
-
127
-	/**
128
-	 * Get FileInfo ID or null in case of part file
129
-	 *
130
-	 * @return int|null
131
-	 */
132
-	public function getId() {
133
-		return isset($this->data['fileid']) ? (int)$this->data['fileid'] : null;
134
-	}
135
-
136
-	public function getMimetype(): string {
137
-		return $this->data['mimetype'] ?? 'application/octet-stream';
138
-	}
139
-
140
-	/**
141
-	 * @return string
142
-	 */
143
-	public function getMimePart() {
144
-		return $this->data['mimepart'];
145
-	}
146
-
147
-	/**
148
-	 * @return string
149
-	 */
150
-	public function getName() {
151
-		return empty($this->data['name'])
152
-			? basename($this->getPath())
153
-			: $this->data['name'];
154
-	}
155
-
156
-	/**
157
-	 * @return string
158
-	 */
159
-	public function getEtag() {
160
-		$this->updateEntryFromSubMounts();
161
-		if (count($this->childEtags) > 0) {
162
-			$combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
163
-			return md5($combinedEtag);
164
-		} else {
165
-			return $this->data['etag'];
166
-		}
167
-	}
168
-
169
-	/**
170
-	 * @param bool $includeMounts
171
-	 * @return int|float
172
-	 */
173
-	public function getSize($includeMounts = true) {
174
-		if ($includeMounts) {
175
-			$this->updateEntryFromSubMounts();
176
-
177
-			if ($this->isEncrypted() && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
178
-				return $this->data['unencrypted_size'];
179
-			} else {
180
-				return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
181
-			}
182
-		} else {
183
-			return $this->rawSize;
184
-		}
185
-	}
186
-
187
-	/**
188
-	 * @return int
189
-	 */
190
-	public function getMTime() {
191
-		$this->updateEntryFromSubMounts();
192
-		return (int)$this->data['mtime'];
193
-	}
194
-
195
-	/**
196
-	 * @return bool
197
-	 */
198
-	public function isEncrypted() {
199
-		return $this->data['encrypted'] ?? false;
200
-	}
201
-
202
-	/**
203
-	 * Return the current version used for the HMAC in the encryption app
204
-	 */
205
-	public function getEncryptedVersion(): int {
206
-		return isset($this->data['encryptedVersion']) ? (int)$this->data['encryptedVersion'] : 1;
207
-	}
208
-
209
-	/**
210
-	 * @return int
211
-	 */
212
-	public function getPermissions() {
213
-		return (int)$this->data['permissions'];
214
-	}
215
-
216
-	/**
217
-	 * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
218
-	 */
219
-	public function getType() {
220
-		if (!isset($this->data['type'])) {
221
-			$this->data['type'] = ($this->getMimetype() === self::MIMETYPE_FOLDER) ? self::TYPE_FOLDER : self::TYPE_FILE;
222
-		}
223
-		return $this->data['type'];
224
-	}
225
-
226
-	public function getData() {
227
-		return $this->data;
228
-	}
229
-
230
-	/**
231
-	 * @param int $permissions
232
-	 * @return bool
233
-	 */
234
-	protected function checkPermissions($permissions) {
235
-		return ($this->getPermissions() & $permissions) === $permissions;
236
-	}
237
-
238
-	/**
239
-	 * @return bool
240
-	 */
241
-	public function isReadable() {
242
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_READ);
243
-	}
244
-
245
-	/**
246
-	 * @return bool
247
-	 */
248
-	public function isUpdateable() {
249
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE);
250
-	}
251
-
252
-	/**
253
-	 * Check whether new files or folders can be created inside this folder
254
-	 *
255
-	 * @return bool
256
-	 */
257
-	public function isCreatable() {
258
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE);
259
-	}
260
-
261
-	/**
262
-	 * @return bool
263
-	 */
264
-	public function isDeletable() {
265
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE);
266
-	}
267
-
268
-	/**
269
-	 * @return bool
270
-	 */
271
-	public function isShareable() {
272
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE);
273
-	}
274
-
275
-	/**
276
-	 * Check if a file or folder is shared
277
-	 *
278
-	 * @return bool
279
-	 */
280
-	public function isShared() {
281
-		return $this->mount instanceof ISharedMountPoint;
282
-	}
283
-
284
-	public function isMounted() {
285
-		$isHome = $this->mount instanceof HomeMountPoint;
286
-		return !$isHome && !$this->isShared();
287
-	}
288
-
289
-	/**
290
-	 * Get the mountpoint the file belongs to
291
-	 *
292
-	 * @return \OCP\Files\Mount\IMountPoint
293
-	 */
294
-	public function getMountPoint() {
295
-		return $this->mount;
296
-	}
297
-
298
-	/**
299
-	 * Get the owner of the file
300
-	 *
301
-	 * @return ?IUser
302
-	 */
303
-	public function getOwner() {
304
-		return $this->owner;
305
-	}
306
-
307
-	/**
308
-	 * @param IMountPoint[] $mounts
309
-	 */
310
-	public function setSubMounts(array $mounts) {
311
-		$this->subMounts = $mounts;
312
-	}
313
-
314
-	private function updateEntryFromSubMounts(): void {
315
-		if ($this->subMountsUsed) {
316
-			return;
317
-		}
318
-		$this->subMountsUsed = true;
319
-		foreach ($this->subMounts as $mount) {
320
-			$subStorage = $mount->getStorage();
321
-			if ($subStorage) {
322
-				$subCache = $subStorage->getCache('');
323
-				$rootEntry = $subCache->get('');
324
-				$this->addSubEntry($rootEntry, $mount->getMountPoint());
325
-			}
326
-		}
327
-	}
328
-
329
-	/**
330
-	 * Add a cache entry which is the child of this folder
331
-	 *
332
-	 * Sets the size, etag and size to for cross-storage childs
333
-	 *
334
-	 * @param array|ICacheEntry $data cache entry for the child
335
-	 * @param string $entryPath full path of the child entry
336
-	 */
337
-	public function addSubEntry($data, $entryPath) {
338
-		if (!$data) {
339
-			return;
340
-		}
341
-		$hasUnencryptedSize = isset($data['unencrypted_size']) && $data['unencrypted_size'] > 0;
342
-		if ($hasUnencryptedSize) {
343
-			$subSize = $data['unencrypted_size'];
344
-		} else {
345
-			$subSize = $data['size'] ?: 0;
346
-		}
347
-		$this->data['size'] += $subSize;
348
-		if ($hasUnencryptedSize) {
349
-			$this->data['unencrypted_size'] += $subSize;
350
-		}
351
-		if (isset($data['mtime'])) {
352
-			$this->data['mtime'] = max($this->data['mtime'], $data['mtime']);
353
-		}
354
-		if (isset($data['etag'])) {
355
-			// prefix the etag with the relative path of the subentry to propagate etag on mount moves
356
-			$relativeEntryPath = substr($entryPath, strlen($this->getPath()));
357
-			// attach the permissions to propagate etag on permission changes of submounts
358
-			$permissions = isset($data['permissions']) ? $data['permissions'] : 0;
359
-			$this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
360
-		}
361
-	}
362
-
363
-	/**
364
-	 * @inheritdoc
365
-	 */
366
-	public function getChecksum() {
367
-		return $this->data['checksum'];
368
-	}
369
-
370
-	public function getExtension(): string {
371
-		return pathinfo($this->getName(), PATHINFO_EXTENSION);
372
-	}
373
-
374
-	public function getCreationTime(): int {
375
-		return (int)$this->data['creation_time'];
376
-	}
377
-
378
-	public function getUploadTime(): int {
379
-		return (int)$this->data['upload_time'];
380
-	}
381
-
382
-	public function getParentId(): int {
383
-		return $this->data['parent'] ?? -1;
384
-	}
385
-
386
-	/**
387
-	 * @inheritDoc
388
-	 * @return array<string, int|string|bool|float|string[]|int[]>
389
-	 */
390
-	public function getMetadata(): array {
391
-		return $this->data['metadata'] ?? [];
392
-	}
21
+    private array|ICacheEntry $data;
22
+    /**
23
+     * @var string
24
+     */
25
+    private $path;
26
+
27
+    /**
28
+     * @var \OC\Files\Storage\Storage $storage
29
+     */
30
+    private $storage;
31
+
32
+    /**
33
+     * @var string
34
+     */
35
+    private $internalPath;
36
+
37
+    /**
38
+     * @var \OCP\Files\Mount\IMountPoint
39
+     */
40
+    private $mount;
41
+
42
+    private ?IUser $owner;
43
+
44
+    /**
45
+     * @var string[]
46
+     */
47
+    private array $childEtags = [];
48
+
49
+    /**
50
+     * @var IMountPoint[]
51
+     */
52
+    private array $subMounts = [];
53
+
54
+    private bool $subMountsUsed = false;
55
+
56
+    /**
57
+     * The size of the file/folder without any sub mount
58
+     */
59
+    private int|float $rawSize = 0;
60
+
61
+    /**
62
+     * @param string|boolean $path
63
+     * @param Storage\Storage $storage
64
+     * @param string $internalPath
65
+     * @param array|ICacheEntry $data
66
+     * @param IMountPoint $mount
67
+     * @param ?IUser $owner
68
+     */
69
+    public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) {
70
+        $this->path = $path;
71
+        $this->storage = $storage;
72
+        $this->internalPath = $internalPath;
73
+        $this->data = $data;
74
+        $this->mount = $mount;
75
+        $this->owner = $owner;
76
+        if (isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] !== 0) {
77
+            $this->rawSize = $this->data['unencrypted_size'];
78
+        } else {
79
+            $this->rawSize = $this->data['size'] ?? 0;
80
+        }
81
+    }
82
+
83
+    public function offsetSet($offset, $value): void {
84
+        if (is_null($offset)) {
85
+            throw new \TypeError('Null offset not supported');
86
+        }
87
+        $this->data[$offset] = $value;
88
+    }
89
+
90
+    public function offsetExists($offset): bool {
91
+        return isset($this->data[$offset]);
92
+    }
93
+
94
+    public function offsetUnset($offset): void {
95
+        unset($this->data[$offset]);
96
+    }
97
+
98
+    public function offsetGet(mixed $offset): mixed {
99
+        return match ($offset) {
100
+            'type' => $this->getType(),
101
+            'etag' => $this->getEtag(),
102
+            'size' => $this->getSize(),
103
+            'mtime' => $this->getMTime(),
104
+            'permissions' => $this->getPermissions(),
105
+            default => $this->data[$offset] ?? null,
106
+        };
107
+    }
108
+
109
+    /**
110
+     * @return string
111
+     */
112
+    public function getPath() {
113
+        return $this->path;
114
+    }
115
+
116
+    public function getStorage() {
117
+        return $this->storage;
118
+    }
119
+
120
+    /**
121
+     * @return string
122
+     */
123
+    public function getInternalPath() {
124
+        return $this->internalPath;
125
+    }
126
+
127
+    /**
128
+     * Get FileInfo ID or null in case of part file
129
+     *
130
+     * @return int|null
131
+     */
132
+    public function getId() {
133
+        return isset($this->data['fileid']) ? (int)$this->data['fileid'] : null;
134
+    }
135
+
136
+    public function getMimetype(): string {
137
+        return $this->data['mimetype'] ?? 'application/octet-stream';
138
+    }
139
+
140
+    /**
141
+     * @return string
142
+     */
143
+    public function getMimePart() {
144
+        return $this->data['mimepart'];
145
+    }
146
+
147
+    /**
148
+     * @return string
149
+     */
150
+    public function getName() {
151
+        return empty($this->data['name'])
152
+            ? basename($this->getPath())
153
+            : $this->data['name'];
154
+    }
155
+
156
+    /**
157
+     * @return string
158
+     */
159
+    public function getEtag() {
160
+        $this->updateEntryFromSubMounts();
161
+        if (count($this->childEtags) > 0) {
162
+            $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
163
+            return md5($combinedEtag);
164
+        } else {
165
+            return $this->data['etag'];
166
+        }
167
+    }
168
+
169
+    /**
170
+     * @param bool $includeMounts
171
+     * @return int|float
172
+     */
173
+    public function getSize($includeMounts = true) {
174
+        if ($includeMounts) {
175
+            $this->updateEntryFromSubMounts();
176
+
177
+            if ($this->isEncrypted() && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
178
+                return $this->data['unencrypted_size'];
179
+            } else {
180
+                return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
181
+            }
182
+        } else {
183
+            return $this->rawSize;
184
+        }
185
+    }
186
+
187
+    /**
188
+     * @return int
189
+     */
190
+    public function getMTime() {
191
+        $this->updateEntryFromSubMounts();
192
+        return (int)$this->data['mtime'];
193
+    }
194
+
195
+    /**
196
+     * @return bool
197
+     */
198
+    public function isEncrypted() {
199
+        return $this->data['encrypted'] ?? false;
200
+    }
201
+
202
+    /**
203
+     * Return the current version used for the HMAC in the encryption app
204
+     */
205
+    public function getEncryptedVersion(): int {
206
+        return isset($this->data['encryptedVersion']) ? (int)$this->data['encryptedVersion'] : 1;
207
+    }
208
+
209
+    /**
210
+     * @return int
211
+     */
212
+    public function getPermissions() {
213
+        return (int)$this->data['permissions'];
214
+    }
215
+
216
+    /**
217
+     * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
218
+     */
219
+    public function getType() {
220
+        if (!isset($this->data['type'])) {
221
+            $this->data['type'] = ($this->getMimetype() === self::MIMETYPE_FOLDER) ? self::TYPE_FOLDER : self::TYPE_FILE;
222
+        }
223
+        return $this->data['type'];
224
+    }
225
+
226
+    public function getData() {
227
+        return $this->data;
228
+    }
229
+
230
+    /**
231
+     * @param int $permissions
232
+     * @return bool
233
+     */
234
+    protected function checkPermissions($permissions) {
235
+        return ($this->getPermissions() & $permissions) === $permissions;
236
+    }
237
+
238
+    /**
239
+     * @return bool
240
+     */
241
+    public function isReadable() {
242
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_READ);
243
+    }
244
+
245
+    /**
246
+     * @return bool
247
+     */
248
+    public function isUpdateable() {
249
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE);
250
+    }
251
+
252
+    /**
253
+     * Check whether new files or folders can be created inside this folder
254
+     *
255
+     * @return bool
256
+     */
257
+    public function isCreatable() {
258
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE);
259
+    }
260
+
261
+    /**
262
+     * @return bool
263
+     */
264
+    public function isDeletable() {
265
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE);
266
+    }
267
+
268
+    /**
269
+     * @return bool
270
+     */
271
+    public function isShareable() {
272
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE);
273
+    }
274
+
275
+    /**
276
+     * Check if a file or folder is shared
277
+     *
278
+     * @return bool
279
+     */
280
+    public function isShared() {
281
+        return $this->mount instanceof ISharedMountPoint;
282
+    }
283
+
284
+    public function isMounted() {
285
+        $isHome = $this->mount instanceof HomeMountPoint;
286
+        return !$isHome && !$this->isShared();
287
+    }
288
+
289
+    /**
290
+     * Get the mountpoint the file belongs to
291
+     *
292
+     * @return \OCP\Files\Mount\IMountPoint
293
+     */
294
+    public function getMountPoint() {
295
+        return $this->mount;
296
+    }
297
+
298
+    /**
299
+     * Get the owner of the file
300
+     *
301
+     * @return ?IUser
302
+     */
303
+    public function getOwner() {
304
+        return $this->owner;
305
+    }
306
+
307
+    /**
308
+     * @param IMountPoint[] $mounts
309
+     */
310
+    public function setSubMounts(array $mounts) {
311
+        $this->subMounts = $mounts;
312
+    }
313
+
314
+    private function updateEntryFromSubMounts(): void {
315
+        if ($this->subMountsUsed) {
316
+            return;
317
+        }
318
+        $this->subMountsUsed = true;
319
+        foreach ($this->subMounts as $mount) {
320
+            $subStorage = $mount->getStorage();
321
+            if ($subStorage) {
322
+                $subCache = $subStorage->getCache('');
323
+                $rootEntry = $subCache->get('');
324
+                $this->addSubEntry($rootEntry, $mount->getMountPoint());
325
+            }
326
+        }
327
+    }
328
+
329
+    /**
330
+     * Add a cache entry which is the child of this folder
331
+     *
332
+     * Sets the size, etag and size to for cross-storage childs
333
+     *
334
+     * @param array|ICacheEntry $data cache entry for the child
335
+     * @param string $entryPath full path of the child entry
336
+     */
337
+    public function addSubEntry($data, $entryPath) {
338
+        if (!$data) {
339
+            return;
340
+        }
341
+        $hasUnencryptedSize = isset($data['unencrypted_size']) && $data['unencrypted_size'] > 0;
342
+        if ($hasUnencryptedSize) {
343
+            $subSize = $data['unencrypted_size'];
344
+        } else {
345
+            $subSize = $data['size'] ?: 0;
346
+        }
347
+        $this->data['size'] += $subSize;
348
+        if ($hasUnencryptedSize) {
349
+            $this->data['unencrypted_size'] += $subSize;
350
+        }
351
+        if (isset($data['mtime'])) {
352
+            $this->data['mtime'] = max($this->data['mtime'], $data['mtime']);
353
+        }
354
+        if (isset($data['etag'])) {
355
+            // prefix the etag with the relative path of the subentry to propagate etag on mount moves
356
+            $relativeEntryPath = substr($entryPath, strlen($this->getPath()));
357
+            // attach the permissions to propagate etag on permission changes of submounts
358
+            $permissions = isset($data['permissions']) ? $data['permissions'] : 0;
359
+            $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
360
+        }
361
+    }
362
+
363
+    /**
364
+     * @inheritdoc
365
+     */
366
+    public function getChecksum() {
367
+        return $this->data['checksum'];
368
+    }
369
+
370
+    public function getExtension(): string {
371
+        return pathinfo($this->getName(), PATHINFO_EXTENSION);
372
+    }
373
+
374
+    public function getCreationTime(): int {
375
+        return (int)$this->data['creation_time'];
376
+    }
377
+
378
+    public function getUploadTime(): int {
379
+        return (int)$this->data['upload_time'];
380
+    }
381
+
382
+    public function getParentId(): int {
383
+        return $this->data['parent'] ?? -1;
384
+    }
385
+
386
+    /**
387
+     * @inheritDoc
388
+     * @return array<string, int|string|bool|float|string[]|int[]>
389
+     */
390
+    public function getMetadata(): array {
391
+        return $this->data['metadata'] ?? [];
392
+    }
393 393
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  * @template-implements \ArrayAccess<string,mixed>
19 19
  */
20 20
 class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
21
-	private array|ICacheEntry $data;
21
+	private array | ICacheEntry $data;
22 22
 	/**
23 23
 	 * @var string
24 24
 	 */
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	/**
57 57
 	 * The size of the file/folder without any sub mount
58 58
 	 */
59
-	private int|float $rawSize = 0;
59
+	private int | float $rawSize = 0;
60 60
 
61 61
 	/**
62 62
 	 * @param string|boolean $path
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @return int|null
131 131
 	 */
132 132
 	public function getId() {
133
-		return isset($this->data['fileid']) ? (int)$this->data['fileid'] : null;
133
+		return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null;
134 134
 	}
135 135
 
136 136
 	public function getMimetype(): string {
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	public function getEtag() {
160 160
 		$this->updateEntryFromSubMounts();
161 161
 		if (count($this->childEtags) > 0) {
162
-			$combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
162
+			$combinedEtag = $this->data['etag'].'::'.implode('::', $this->childEtags);
163 163
 			return md5($combinedEtag);
164 164
 		} else {
165 165
 			return $this->data['etag'];
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 */
190 190
 	public function getMTime() {
191 191
 		$this->updateEntryFromSubMounts();
192
-		return (int)$this->data['mtime'];
192
+		return (int) $this->data['mtime'];
193 193
 	}
194 194
 
195 195
 	/**
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
 	 * Return the current version used for the HMAC in the encryption app
204 204
 	 */
205 205
 	public function getEncryptedVersion(): int {
206
-		return isset($this->data['encryptedVersion']) ? (int)$this->data['encryptedVersion'] : 1;
206
+		return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1;
207 207
 	}
208 208
 
209 209
 	/**
210 210
 	 * @return int
211 211
 	 */
212 212
 	public function getPermissions() {
213
-		return (int)$this->data['permissions'];
213
+		return (int) $this->data['permissions'];
214 214
 	}
215 215
 
216 216
 	/**
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 			$relativeEntryPath = substr($entryPath, strlen($this->getPath()));
357 357
 			// attach the permissions to propagate etag on permission changes of submounts
358 358
 			$permissions = isset($data['permissions']) ? $data['permissions'] : 0;
359
-			$this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
359
+			$this->childEtags[] = $relativeEntryPath.'/'.$data['etag'].$permissions;
360 360
 		}
361 361
 	}
362 362
 
@@ -372,11 +372,11 @@  discard block
 block discarded – undo
372 372
 	}
373 373
 
374 374
 	public function getCreationTime(): int {
375
-		return (int)$this->data['creation_time'];
375
+		return (int) $this->data['creation_time'];
376 376
 	}
377 377
 
378 378
 	public function getUploadTime(): int {
379
-		return (int)$this->data['upload_time'];
379
+		return (int) $this->data['upload_time'];
380 380
 	}
381 381
 
382 382
 	public function getParentId(): int {
Please login to merge, or discard this patch.
lib/private/Files/Cache/CacheEntry.php 1 patch
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -13,120 +13,120 @@
 block discarded – undo
13 13
  * meta data for a file or folder
14 14
  */
15 15
 class CacheEntry implements ICacheEntry {
16
-	/**
17
-	 * @var array
18
-	 */
19
-	private $data;
16
+    /**
17
+     * @var array
18
+     */
19
+    private $data;
20 20
 
21
-	public function __construct(array $data) {
22
-		$this->data = $data;
23
-	}
21
+    public function __construct(array $data) {
22
+        $this->data = $data;
23
+    }
24 24
 
25
-	public function offsetSet($offset, $value): void {
26
-		$this->data[$offset] = $value;
27
-	}
25
+    public function offsetSet($offset, $value): void {
26
+        $this->data[$offset] = $value;
27
+    }
28 28
 
29
-	public function offsetExists($offset): bool {
30
-		return isset($this->data[$offset]);
31
-	}
32
-
33
-	public function offsetUnset($offset): void {
34
-		unset($this->data[$offset]);
35
-	}
36
-
37
-	/**
38
-	 * @return mixed
39
-	 */
40
-	#[\ReturnTypeWillChange]
41
-	public function offsetGet($offset) {
42
-		if (isset($this->data[$offset])) {
43
-			return $this->data[$offset];
44
-		} else {
45
-			return null;
46
-		}
47
-	}
48
-
49
-	public function getId() {
50
-		return (int)$this->data['fileid'];
51
-	}
52
-
53
-	public function getStorageId() {
54
-		return $this->data['storage'];
55
-	}
56
-
57
-
58
-	public function getPath() {
59
-		return (string)$this->data['path'];
60
-	}
61
-
62
-
63
-	public function getName() {
64
-		return $this->data['name'];
65
-	}
66
-
67
-
68
-	public function getMimeType(): string {
69
-		return $this->data['mimetype'] ?? 'application/octet-stream';
70
-	}
71
-
72
-
73
-	public function getMimePart() {
74
-		return $this->data['mimepart'];
75
-	}
76
-
77
-	public function getSize() {
78
-		return $this->data['size'];
79
-	}
80
-
81
-	public function getMTime() {
82
-		return $this->data['mtime'];
83
-	}
84
-
85
-	public function getStorageMTime() {
86
-		return $this->data['storage_mtime'];
87
-	}
88
-
89
-	public function getEtag() {
90
-		return $this->data['etag'];
91
-	}
92
-
93
-	public function getPermissions() {
94
-		return $this->data['permissions'];
95
-	}
96
-
97
-	public function isEncrypted() {
98
-		return isset($this->data['encrypted']) && $this->data['encrypted'];
99
-	}
100
-
101
-	public function getMetadataEtag(): ?string {
102
-		return $this->data['metadata_etag'] ?? null;
103
-	}
104
-
105
-	public function getCreationTime(): ?int {
106
-		return $this->data['creation_time'] ?? null;
107
-	}
108
-
109
-	public function getUploadTime(): ?int {
110
-		return $this->data['upload_time'] ?? null;
111
-	}
112
-
113
-	public function getParentId(): int {
114
-		return $this->data['parent'];
115
-	}
116
-
117
-	public function getData() {
118
-		return $this->data;
119
-	}
29
+    public function offsetExists($offset): bool {
30
+        return isset($this->data[$offset]);
31
+    }
32
+
33
+    public function offsetUnset($offset): void {
34
+        unset($this->data[$offset]);
35
+    }
36
+
37
+    /**
38
+     * @return mixed
39
+     */
40
+    #[\ReturnTypeWillChange]
41
+    public function offsetGet($offset) {
42
+        if (isset($this->data[$offset])) {
43
+            return $this->data[$offset];
44
+        } else {
45
+            return null;
46
+        }
47
+    }
48
+
49
+    public function getId() {
50
+        return (int)$this->data['fileid'];
51
+    }
52
+
53
+    public function getStorageId() {
54
+        return $this->data['storage'];
55
+    }
56
+
57
+
58
+    public function getPath() {
59
+        return (string)$this->data['path'];
60
+    }
61
+
62
+
63
+    public function getName() {
64
+        return $this->data['name'];
65
+    }
66
+
67
+
68
+    public function getMimeType(): string {
69
+        return $this->data['mimetype'] ?? 'application/octet-stream';
70
+    }
71
+
72
+
73
+    public function getMimePart() {
74
+        return $this->data['mimepart'];
75
+    }
76
+
77
+    public function getSize() {
78
+        return $this->data['size'];
79
+    }
80
+
81
+    public function getMTime() {
82
+        return $this->data['mtime'];
83
+    }
84
+
85
+    public function getStorageMTime() {
86
+        return $this->data['storage_mtime'];
87
+    }
88
+
89
+    public function getEtag() {
90
+        return $this->data['etag'];
91
+    }
92
+
93
+    public function getPermissions() {
94
+        return $this->data['permissions'];
95
+    }
96
+
97
+    public function isEncrypted() {
98
+        return isset($this->data['encrypted']) && $this->data['encrypted'];
99
+    }
100
+
101
+    public function getMetadataEtag(): ?string {
102
+        return $this->data['metadata_etag'] ?? null;
103
+    }
104
+
105
+    public function getCreationTime(): ?int {
106
+        return $this->data['creation_time'] ?? null;
107
+    }
108
+
109
+    public function getUploadTime(): ?int {
110
+        return $this->data['upload_time'] ?? null;
111
+    }
112
+
113
+    public function getParentId(): int {
114
+        return $this->data['parent'];
115
+    }
116
+
117
+    public function getData() {
118
+        return $this->data;
119
+    }
120 120
 
121
-	public function __clone() {
122
-		$this->data = array_merge([], $this->data);
123
-	}
121
+    public function __clone() {
122
+        $this->data = array_merge([], $this->data);
123
+    }
124 124
 
125
-	public function getUnencryptedSize(): int {
126
-		if ($this->data['encrypted'] && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
127
-			return $this->data['unencrypted_size'];
128
-		} else {
129
-			return $this->data['size'] ?? 0;
130
-		}
131
-	}
125
+    public function getUnencryptedSize(): int {
126
+        if ($this->data['encrypted'] && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
127
+            return $this->data['unencrypted_size'];
128
+        } else {
129
+            return $this->data['size'] ?? 0;
130
+        }
131
+    }
132 132
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Trash/TrashItem.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -11,162 +11,162 @@
 block discarded – undo
11 11
 
12 12
 class TrashItem implements ITrashItem {
13 13
 
14
-	public function __construct(
15
-		private ITrashBackend $backend,
16
-		private string $originalLocation,
17
-		private int $deletedTime,
18
-		private string $trashPath,
19
-		private FileInfo $fileInfo,
20
-		private IUser $user,
21
-		private ?IUser $deletedBy,
22
-	) {
23
-	}
24
-
25
-	public function getTrashBackend(): ITrashBackend {
26
-		return $this->backend;
27
-	}
28
-
29
-	public function getOriginalLocation(): string {
30
-		return $this->originalLocation;
31
-	}
32
-
33
-	public function getDeletedTime(): int {
34
-		return $this->deletedTime;
35
-	}
36
-
37
-	public function getTrashPath(): string {
38
-		return $this->trashPath;
39
-	}
40
-
41
-	public function isRootItem(): bool {
42
-		return substr_count($this->getTrashPath(), '/') === 1;
43
-	}
44
-
45
-	public function getUser(): IUser {
46
-		return $this->user;
47
-	}
48
-
49
-	public function getEtag() {
50
-		return $this->fileInfo->getEtag();
51
-	}
52
-
53
-	public function getSize($includeMounts = true) {
54
-		return $this->fileInfo->getSize($includeMounts);
55
-	}
56
-
57
-	public function getMtime() {
58
-		return $this->fileInfo->getMtime();
59
-	}
60
-
61
-	public function getName() {
62
-		return $this->fileInfo->getName();
63
-	}
64
-
65
-	public function getInternalPath() {
66
-		return $this->fileInfo->getInternalPath();
67
-	}
68
-
69
-	public function getPath() {
70
-		return $this->fileInfo->getPath();
71
-	}
72
-
73
-	public function getMimetype(): string {
74
-		return $this->fileInfo->getMimetype();
75
-	}
76
-
77
-	public function getMimePart() {
78
-		return $this->fileInfo->getMimePart();
79
-	}
80
-
81
-	public function getStorage() {
82
-		return $this->fileInfo->getStorage();
83
-	}
84
-
85
-	public function getId() {
86
-		return $this->fileInfo->getId();
87
-	}
88
-
89
-	public function isEncrypted() {
90
-		return $this->fileInfo->isEncrypted();
91
-	}
92
-
93
-	public function getPermissions() {
94
-		return $this->fileInfo->getPermissions();
95
-	}
96
-
97
-	public function getType() {
98
-		return $this->fileInfo->getType();
99
-	}
100
-
101
-	public function isReadable() {
102
-		return $this->fileInfo->isReadable();
103
-	}
104
-
105
-	public function isUpdateable() {
106
-		return $this->fileInfo->isUpdateable();
107
-	}
108
-
109
-	public function isCreatable() {
110
-		return $this->fileInfo->isCreatable();
111
-	}
112
-
113
-	public function isDeletable() {
114
-		return $this->fileInfo->isDeletable();
115
-	}
116
-
117
-	public function isShareable() {
118
-		return $this->fileInfo->isShareable();
119
-	}
120
-
121
-	public function isShared() {
122
-		return $this->fileInfo->isShared();
123
-	}
124
-
125
-	public function isMounted() {
126
-		return $this->fileInfo->isMounted();
127
-	}
128
-
129
-	public function getMountPoint() {
130
-		return $this->fileInfo->getMountPoint();
131
-	}
132
-
133
-	public function getOwner() {
134
-		return $this->fileInfo->getOwner();
135
-	}
136
-
137
-	public function getChecksum() {
138
-		return $this->fileInfo->getChecksum();
139
-	}
140
-
141
-	public function getExtension(): string {
142
-		return $this->fileInfo->getExtension();
143
-	}
144
-
145
-	public function getTitle(): string {
146
-		return $this->getOriginalLocation();
147
-	}
148
-
149
-	public function getCreationTime(): int {
150
-		return $this->fileInfo->getCreationTime();
151
-	}
152
-
153
-	public function getUploadTime(): int {
154
-		return $this->fileInfo->getUploadTime();
155
-	}
156
-
157
-	public function getParentId(): int {
158
-		return $this->fileInfo->getParentId();
159
-	}
160
-
161
-	public function getDeletedBy(): ?IUser {
162
-		return $this->deletedBy;
163
-	}
164
-
165
-	/**
166
-	 * @inheritDoc
167
-	 * @return array<string, int|string|bool|float|string[]|int[]>
168
-	 */
169
-	public function getMetadata(): array {
170
-		return $this->fileInfo->getMetadata();
171
-	}
14
+    public function __construct(
15
+        private ITrashBackend $backend,
16
+        private string $originalLocation,
17
+        private int $deletedTime,
18
+        private string $trashPath,
19
+        private FileInfo $fileInfo,
20
+        private IUser $user,
21
+        private ?IUser $deletedBy,
22
+    ) {
23
+    }
24
+
25
+    public function getTrashBackend(): ITrashBackend {
26
+        return $this->backend;
27
+    }
28
+
29
+    public function getOriginalLocation(): string {
30
+        return $this->originalLocation;
31
+    }
32
+
33
+    public function getDeletedTime(): int {
34
+        return $this->deletedTime;
35
+    }
36
+
37
+    public function getTrashPath(): string {
38
+        return $this->trashPath;
39
+    }
40
+
41
+    public function isRootItem(): bool {
42
+        return substr_count($this->getTrashPath(), '/') === 1;
43
+    }
44
+
45
+    public function getUser(): IUser {
46
+        return $this->user;
47
+    }
48
+
49
+    public function getEtag() {
50
+        return $this->fileInfo->getEtag();
51
+    }
52
+
53
+    public function getSize($includeMounts = true) {
54
+        return $this->fileInfo->getSize($includeMounts);
55
+    }
56
+
57
+    public function getMtime() {
58
+        return $this->fileInfo->getMtime();
59
+    }
60
+
61
+    public function getName() {
62
+        return $this->fileInfo->getName();
63
+    }
64
+
65
+    public function getInternalPath() {
66
+        return $this->fileInfo->getInternalPath();
67
+    }
68
+
69
+    public function getPath() {
70
+        return $this->fileInfo->getPath();
71
+    }
72
+
73
+    public function getMimetype(): string {
74
+        return $this->fileInfo->getMimetype();
75
+    }
76
+
77
+    public function getMimePart() {
78
+        return $this->fileInfo->getMimePart();
79
+    }
80
+
81
+    public function getStorage() {
82
+        return $this->fileInfo->getStorage();
83
+    }
84
+
85
+    public function getId() {
86
+        return $this->fileInfo->getId();
87
+    }
88
+
89
+    public function isEncrypted() {
90
+        return $this->fileInfo->isEncrypted();
91
+    }
92
+
93
+    public function getPermissions() {
94
+        return $this->fileInfo->getPermissions();
95
+    }
96
+
97
+    public function getType() {
98
+        return $this->fileInfo->getType();
99
+    }
100
+
101
+    public function isReadable() {
102
+        return $this->fileInfo->isReadable();
103
+    }
104
+
105
+    public function isUpdateable() {
106
+        return $this->fileInfo->isUpdateable();
107
+    }
108
+
109
+    public function isCreatable() {
110
+        return $this->fileInfo->isCreatable();
111
+    }
112
+
113
+    public function isDeletable() {
114
+        return $this->fileInfo->isDeletable();
115
+    }
116
+
117
+    public function isShareable() {
118
+        return $this->fileInfo->isShareable();
119
+    }
120
+
121
+    public function isShared() {
122
+        return $this->fileInfo->isShared();
123
+    }
124
+
125
+    public function isMounted() {
126
+        return $this->fileInfo->isMounted();
127
+    }
128
+
129
+    public function getMountPoint() {
130
+        return $this->fileInfo->getMountPoint();
131
+    }
132
+
133
+    public function getOwner() {
134
+        return $this->fileInfo->getOwner();
135
+    }
136
+
137
+    public function getChecksum() {
138
+        return $this->fileInfo->getChecksum();
139
+    }
140
+
141
+    public function getExtension(): string {
142
+        return $this->fileInfo->getExtension();
143
+    }
144
+
145
+    public function getTitle(): string {
146
+        return $this->getOriginalLocation();
147
+    }
148
+
149
+    public function getCreationTime(): int {
150
+        return $this->fileInfo->getCreationTime();
151
+    }
152
+
153
+    public function getUploadTime(): int {
154
+        return $this->fileInfo->getUploadTime();
155
+    }
156
+
157
+    public function getParentId(): int {
158
+        return $this->fileInfo->getParentId();
159
+    }
160
+
161
+    public function getDeletedBy(): ?IUser {
162
+        return $this->deletedBy;
163
+    }
164
+
165
+    /**
166
+     * @inheritDoc
167
+     * @return array<string, int|string|bool|float|string[]|int[]>
168
+     */
169
+    public function getMetadata(): array {
170
+        return $this->fileInfo->getMetadata();
171
+    }
172 172
 }
Please login to merge, or discard this patch.