@@ -56,8 +56,8 @@ public function __construct($parameters) {
5656 /**
5757 * @throws ForbiddenException
5858 */
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 ) );
6161 }
6262
6363 /*
@@ -165,7 +165,7 @@ public function getPermissions($path) {
165165 * @throws ForbiddenException
166166 */
167167 public function file_get_contents ($ path ) {
168- $ this ->checkFileAccess ($ path );
168+ $ this ->checkFileAccess ($ path, false );
169169 return $ this ->storage ->file_get_contents ($ path );
170170 }
171171
@@ -178,7 +178,7 @@ public function file_get_contents($path) {
178178 * @throws ForbiddenException
179179 */
180180 public function file_put_contents ($ path , $ data ) {
181- $ this ->checkFileAccess ($ path );
181+ $ this ->checkFileAccess ($ path, false );
182182 return $ this ->storage ->file_put_contents ($ path , $ data );
183183 }
184184
@@ -190,7 +190,7 @@ public function file_put_contents($path, $data) {
190190 * @throws ForbiddenException
191191 */
192192 public function unlink ($ path ) {
193- $ this ->checkFileAccess ($ path );
193+ $ this ->checkFileAccess ($ path, false );
194194 return $ this ->storage ->unlink ($ path );
195195 }
196196
@@ -203,8 +203,9 @@ public function unlink($path) {
203203 * @throws ForbiddenException
204204 */
205205 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 );
208209 return $ this ->storage ->rename ($ path1 , $ path2 );
209210 }
210211
@@ -217,8 +218,9 @@ public function rename($path1, $path2) {
217218 * @throws ForbiddenException
218219 */
219220 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 );
222224 return $ this ->storage ->copy ($ path1 , $ path2 );
223225 }
224226
@@ -231,7 +233,7 @@ public function copy($path1, $path2) {
231233 * @throws ForbiddenException
232234 */
233235 public function fopen ($ path , $ mode ) {
234- $ this ->checkFileAccess ($ path );
236+ $ this ->checkFileAccess ($ path, false );
235237 return $ this ->storage ->fopen ($ path , $ mode );
236238 }
237239
@@ -245,7 +247,7 @@ public function fopen($path, $mode) {
245247 * @throws ForbiddenException
246248 */
247249 public function touch ($ path , $ mtime = null ) {
248- $ this ->checkFileAccess ($ path );
250+ $ this ->checkFileAccess ($ path, false );
249251 return $ this ->storage ->touch ($ path , $ mtime );
250252 }
251253
@@ -274,7 +276,7 @@ public function getCache($path = '', $storage = null) {
274276 * @throws ForbiddenException
275277 */
276278 public function getDirectDownload ($ path ) {
277- $ this ->checkFileAccess ($ path );
279+ $ this ->checkFileAccess ($ path, false );
278280 return $ this ->storage ->getDirectDownload ($ path );
279281 }
280282
@@ -290,7 +292,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
290292 return $ this ->copy ($ sourceInternalPath , $ targetInternalPath );
291293 }
292294
293- $ this ->checkFileAccess ($ targetInternalPath );
295+ $ this ->checkFileAccess ($ targetInternalPath, $ sourceStorage -> is_dir ( $ sourceInternalPath ) );
294296 return $ this ->storage ->copyFromStorage ($ sourceStorage , $ sourceInternalPath , $ targetInternalPath );
295297 }
296298
@@ -306,7 +308,7 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
306308 return $ this ->rename ($ sourceInternalPath , $ targetInternalPath );
307309 }
308310
309- $ this ->checkFileAccess ($ targetInternalPath );
311+ $ this ->checkFileAccess ($ targetInternalPath, $ sourceStorage -> is_dir ( $ sourceInternalPath ) );
310312 return $ this ->storage ->moveFromStorage ($ sourceStorage , $ sourceInternalPath , $ targetInternalPath );
311313 }
312314
@@ -315,18 +317,18 @@ public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
315317 */
316318 public function writeStream (string $ path , $ stream , int $ size = null ): int {
317319 if (!$ this ->isPartFile ($ path )) {
318- $ this ->checkFileAccess ($ path );
320+ $ this ->checkFileAccess ($ path, false );
319321 }
320322
321323 $ result = $ this ->storage ->writeStream ($ path , $ stream , $ size );
322324 if (!$ this ->isPartFile ($ path )) {
323325 return $ result ;
324326 }
325327
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
327329 // As an alternative we might be able to check on the cache update/insert/delete though the Cache wrapper
328330 try {
329- $ this ->checkFileAccess ($ path );
331+ $ this ->checkFileAccess ($ path, false );
330332 } catch (\Exception $ e ) {
331333 $ this ->storage ->unlink ($ path );
332334 throw $ e ;
0 commit comments