Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions airflow/utils/log/file_processor_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,19 @@ def _symlink_latest_log_directory(self):
log_directory = self._get_log_directory()
latest_log_directory_path = os.path.join(self.base_log_folder, "latest")
if os.path.isdir(log_directory):
rel_link_target = Path(log_directory).relative_to(Path(latest_log_directory_path).parent)
try:
# if symlink exists but is stale, update it
if os.path.islink(latest_log_directory_path):
if os.readlink(latest_log_directory_path) != log_directory:
if os.path.realpath(latest_log_directory_path) != log_directory:
os.unlink(latest_log_directory_path)
os.symlink(log_directory, latest_log_directory_path)
os.symlink(rel_link_target, latest_log_directory_path)
elif os.path.isdir(latest_log_directory_path) or os.path.isfile(latest_log_directory_path):
logging.warning(
"%s already exists as a dir/file. Skip creating symlink.", latest_log_directory_path
)
else:
os.symlink(log_directory, latest_log_directory_path)
os.symlink(rel_link_target, latest_log_directory_path)
except OSError:
logging.warning("OSError while attempting to symlink the latest log directory")

Expand Down
4 changes: 2 additions & 2 deletions tests/utils/log/test_file_processor_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ def test_symlink_latest_log_directory(self):
with time_machine.travel(date1, tick=False):
handler.set_context(filename=os.path.join(self.dag_dir, "log1"))
assert os.path.islink(link)
assert os.path.basename(os.readlink(link)) == date1
assert os.path.basename(os.path.realpath(link)) == date1
assert os.path.exists(os.path.join(link, "log1"))

with time_machine.travel(date2, tick=False):
handler.set_context(filename=os.path.join(self.dag_dir, "log2"))
assert os.path.islink(link)
assert os.path.basename(os.readlink(link)) == date2
assert os.path.basename(os.path.realpath(link)) == date2
assert os.path.exists(os.path.join(link, "log2"))

def test_symlink_latest_log_directory_exists(self):
Expand Down