Skip to content

Commit

Permalink
Ignore error when changing log folder permissions
Browse files Browse the repository at this point in the history
In some circumstances, changing the permission of a parent folder
for the log might not be possible - for example when it was
created by another user (with impersonation) or when the filesystem
does not allow for permission change.

Fixes: apache#29112
  • Loading branch information
potiuk committed Mar 15, 2023
1 parent 2f02e84 commit 0a6ae89
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions airflow/utils/log/file_task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,16 @@ def _prepare_log_folder(self, directory: Path):
)
directory.mkdir(mode=new_folder_permissions, parents=True, exist_ok=True)
if directory.stat().st_mode % 0o1000 != new_folder_permissions % 0o1000:
print(f"Changing dir permission to {new_folder_permissions}")
directory.chmod(new_folder_permissions)
print(f"Changing {directory} permission to {new_folder_permissions}")
try:
directory.chmod(new_folder_permissions)
except PermissionError as e:
# In some circumstances (depends on user and filesystem) we might not be able to
# change the permission for the folder (when the folder was created by another user
# before or when the filesystem does not allow to change permission). We should not
# fail in this case but rather ignore it.
print(f"Failed to change {directory} permission to {new_folder_permissions}: {e}")
pass

def _init_file(self, ti):
"""
Expand Down

0 comments on commit 0a6ae89

Please sign in to comment.