@@ -56,8 +56,8 @@ public function __construct($parameters) {
56
56
/**
57
57
* @throws ForbiddenException
58
58
*/
59
- protected function checkFileAccess (string $ path , bool $ isDir = false ): void {
60
- $ this ->operation ->checkFileAccess ($ this , $ path , $ isDir );
59
+ protected function checkFileAccess (string $ path , ? bool $ isDir = null ): void {
60
+ $ this ->operation ->checkFileAccess ($ this , $ path , is_bool ( $ isDir) ? $ isDir : $ this -> is_dir ( $ path ) );
61
61
}
62
62
63
63
/*
@@ -165,7 +165,7 @@ public function getPermissions($path) {
165
165
* @throws ForbiddenException
166
166
*/
167
167
public function file_get_contents ($ path ) {
168
- $ this ->checkFileAccess ($ path );
168
+ $ this ->checkFileAccess ($ path, false );
169
169
return $ this ->storage ->file_get_contents ($ path );
170
170
}
171
171
@@ -178,7 +178,7 @@ public function file_get_contents($path) {
178
178
* @throws ForbiddenException
179
179
*/
180
180
public function file_put_contents ($ path , $ data ) {
181
- $ this ->checkFileAccess ($ path );
181
+ $ this ->checkFileAccess ($ path, false );
182
182
return $ this ->storage ->file_put_contents ($ path , $ data );
183
183
}
184
184
@@ -190,7 +190,7 @@ public function file_put_contents($path, $data) {
190
190
* @throws ForbiddenException
191
191
*/
192
192
public function unlink ($ path ) {
193
- $ this ->checkFileAccess ($ path );
193
+ $ this ->checkFileAccess ($ path, false );
194
194
return $ this ->storage ->unlink ($ path );
195
195
}
196
196
@@ -203,8 +203,9 @@ public function unlink($path) {
203
203
* @throws ForbiddenException
204
204
*/
205
205
public function rename ($ path1 , $ path2 ) {
206
- $ this ->checkFileAccess ($ path1 );
207
- $ this ->checkFileAccess ($ path2 );
206
+ $ isDir = $ this ->is_dir ($ path1 );
207
+ $ this ->checkFileAccess ($ path1 , $ isDir );
208
+ $ this ->checkFileAccess ($ path2 , $ isDir );
208
209
return $ this ->storage ->rename ($ path1 , $ path2 );
209
210
}
210
211
@@ -217,8 +218,9 @@ public function rename($path1, $path2) {
217
218
* @throws ForbiddenException
218
219
*/
219
220
public function copy ($ path1 , $ path2 ) {
220
- $ this ->checkFileAccess ($ path1 );
221
- $ this ->checkFileAccess ($ path2 );
221
+ $ isDir = $ this ->is_dir ($ path1 );
222
+ $ this ->checkFileAccess ($ path1 , $ isDir );
223
+ $ this ->checkFileAccess ($ path2 , $ isDir );
222
224
return $ this ->storage ->copy ($ path1 , $ path2 );
223
225
}
224
226
@@ -231,7 +233,7 @@ public function copy($path1, $path2) {
231
233
* @throws ForbiddenException
232
234
*/
233
235
public function fopen ($ path , $ mode ) {
234
- $ this ->checkFileAccess ($ path );
236
+ $ this ->checkFileAccess ($ path, false );
235
237
return $ this ->storage ->fopen ($ path , $ mode );
236
238
}
237
239
@@ -245,7 +247,7 @@ public function fopen($path, $mode) {
245
247
* @throws ForbiddenException
246
248
*/
247
249
public function touch ($ path , $ mtime = null ) {
248
- $ this ->checkFileAccess ($ path );
250
+ $ this ->checkFileAccess ($ path, false );
249
251
return $ this ->storage ->touch ($ path , $ mtime );
250
252
}
251
253
@@ -274,7 +276,7 @@ public function getCache($path = '', $storage = null) {
274
276
* @throws ForbiddenException
275
277
*/
276
278
public function getDirectDownload ($ path ) {
277
- $ this ->checkFileAccess ($ path );
279
+ $ this ->checkFileAccess ($ path, false );
278
280
return $ this ->storage ->getDirectDownload ($ path );
279
281
}
280
282
@@ -290,7 +292,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
290
292
return $ this ->copy ($ sourceInternalPath , $ targetInternalPath );
291
293
}
292
294
293
- $ this ->checkFileAccess ($ targetInternalPath );
295
+ $ this ->checkFileAccess ($ targetInternalPath, $ sourceStorage -> is_dir ( $ sourceInternalPath ) );
294
296
return $ this ->storage ->copyFromStorage ($ sourceStorage , $ sourceInternalPath , $ targetInternalPath );
295
297
}
296
298
@@ -306,7 +308,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
306
308
return $ this ->rename ($ sourceInternalPath , $ targetInternalPath );
307
309
}
308
310
309
- $ this ->checkFileAccess ($ targetInternalPath );
311
+ $ this ->checkFileAccess ($ targetInternalPath, $ sourceStorage -> is_dir ( $ sourceInternalPath ) );
310
312
return $ this ->storage ->moveFromStorage ($ sourceStorage , $ sourceInternalPath , $ targetInternalPath );
311
313
}
312
314
@@ -315,18 +317,18 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
315
317
*/
316
318
public function writeStream (string $ path , $ stream , ?int $ size = null ): int {
317
319
if (!$ this ->isPartFile ($ path )) {
318
- $ this ->checkFileAccess ($ path );
320
+ $ this ->checkFileAccess ($ path, false );
319
321
}
320
322
321
323
$ result = $ this ->storage ->writeStream ($ path , $ stream , $ size );
322
324
if (!$ this ->isPartFile ($ path )) {
323
325
return $ result ;
324
326
}
325
327
326
- // Required for object storage since part file is not in the storage so we cannot check it before moving it to the storage
328
+ // Required for object storage since part file is not in the storage so we cannot check it before moving it to the storage
327
329
// As an alternative we might be able to check on the cache update/insert/delete though the Cache wrapper
328
330
try {
329
- $ this ->checkFileAccess ($ path );
331
+ $ this ->checkFileAccess ($ path, false );
330
332
} catch (\Exception $ e ) {
331
333
$ this ->storage ->unlink ($ path );
332
334
throw $ e ;
0 commit comments