@@ -420,11 +420,14 @@ def single_value(xs):
420
420
421
421
422
422
def add_permissions (path : Path , mode : int , user = None , group = None ):
423
+ """
424
+ Add permissions to a file or directory, and optionally change its ownership.
425
+ """
423
426
# TODO: accept PathLike etc as well
424
427
# TODO: maybe umask is a better/cleaner option
425
- # TODO: Don't change permissions on s3 urls?
426
- # if str( path).lower().startswith("s3:/"):
427
- # return
428
+ if str ( path ). lower (). startswith ( "s3:/" ):
429
+ logger . warning ( f"add_permissions called on S3 path { path !r } , which is not supported." )
430
+ return
428
431
if path .exists ():
429
432
current_permission_bits = os .stat (path ).st_mode
430
433
os .chmod (path , current_permission_bits | mode )
@@ -435,7 +438,14 @@ def add_permissions(path: Path, mode: int, user=None, group=None):
435
438
logger .warning (f"Could not change user/group of { path } to { user } /{ group } ." )
436
439
except PermissionError as e :
437
440
logger .warning (f"Could not change user/group of { path } to { user } /{ group } , no permissions." )
441
+
442
+
443
+ def add_permissions_with_failsafe (path : Path , mode : int , user = None , group = None ):
444
+ if path .exists ():
445
+ add_permissions (path , mode , user = user , group = group )
438
446
else :
447
+ # If the path does not exist, we set the permissions on all siblings in the parent directory.
448
+ # TODO: This was originally implemented for tiffs with multiple dates (EP-3800). Check if this can be removed.
439
449
for p in path .parent .glob ('*' ):
440
450
current_permission_bits = os .stat (p ).st_mode
441
451
p .chmod (current_permission_bits | mode )
0 commit comments