Skip to content

Commit 0a12b4a

Browse files
split add_permissions_with_failsafe from add_permissions
1 parent 84d0a00 commit 0a12b4a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

openeogeotrellis/deploy/batch_job.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
to_jsonable,
7979
unzip,
8080
wait_till_path_available,
81+
add_permissions_with_failsafe,
8182
)
8283

8384
logger = logging.getLogger("openeogeotrellis.deploy.batch_job")
@@ -488,7 +489,7 @@ def unique_key(asset_id, href):
488489
# fusemount could have some delay to make files accessible, so poll a bit:
489490
asset_path = get_abs_path_of_asset(file_path, job_dir)
490491
wait_till_path_available(asset_path)
491-
add_permissions(Path(asset["href"]), stat.S_IWGRP)
492+
add_permissions_with_failsafe(Path(asset["href"]), stat.S_IWGRP)
492493
logger.info(f"wrote {len(the_assets_metadata)} assets to {output_file}")
493494

494495
if any(dependency["card4l"] for dependency in dependencies): # TODO: clean this up

openeogeotrellis/utils.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,14 @@ def single_value(xs):
420420

421421

422422
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+
"""
423426
# TODO: accept PathLike etc as well
424427
# 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
428431
if path.exists():
429432
current_permission_bits = os.stat(path).st_mode
430433
os.chmod(path, current_permission_bits | mode)
@@ -435,7 +438,14 @@ def add_permissions(path: Path, mode: int, user=None, group=None):
435438
logger.warning(f"Could not change user/group of {path} to {user}/{group}.")
436439
except PermissionError as e:
437440
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)
438446
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.
439449
for p in path.parent.glob('*'):
440450
current_permission_bits = os.stat(p).st_mode
441451
p.chmod(current_permission_bits | mode)

0 commit comments

Comments
 (0)