From f587ce0dac0fc2d11774173e656a59ebb4372b48 Mon Sep 17 00:00:00 2001 From: Old-Ding <35417409+Old-Ding@users.noreply.github.com> Date: Sat, 11 Jul 2026 02:32:05 +0800 Subject: [PATCH] Use relative target for latest log symlink The latest link and each run directory are siblings. Point the link at the run directory basename so it remains valid when the parent log directory is mounted at a different absolute path. Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com> --- launch/launch/logging/__init__.py | 2 +- launch/test/launch/test_logging.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/launch/launch/logging/__init__.py b/launch/launch/logging/__init__.py index b0bd2b24b..668f4aff9 100644 --- a/launch/launch/logging/__init__.py +++ b/launch/launch/logging/__init__.py @@ -104,7 +104,7 @@ def _renew_latest_log_dir(*, log_dir: str) -> bool: if not os.path.islink(latest_dir): return False os.unlink(latest_dir) - os.symlink(log_dir, latest_dir, target_is_directory=True) + os.symlink(os.path.basename(log_dir), latest_dir, target_is_directory=True) return True diff --git a/launch/test/launch/test_logging.py b/launch/test/launch/test_logging.py index 62ecebae9..5a02a57e2 100644 --- a/launch/test/launch/test_logging.py +++ b/launch/test/launch/test_logging.py @@ -37,6 +37,20 @@ def mock_clean_env(monkeypatch): monkeypatch.delenv('OVERRIDE_LAUNCH_LOG_FORMAT', raising=False) +def test_renew_latest_log_dir_uses_relative_target(tmp_path): + log_dir = tmp_path / 'run' + latest_dir = tmp_path / 'latest' + + with mock.patch('launch.logging.os.symlink') as symlink_mock: + assert launch.logging._renew_latest_log_dir(log_dir=str(log_dir)) + + target = symlink_mock.call_args.args[0] + assert not os.path.isabs(target) + assert os.path.normpath(os.path.join(tmp_path, target)) == str(log_dir) + symlink_mock.assert_called_once_with( + log_dir.name, str(latest_dir), target_is_directory=True) + + def test_bad_logging_launch_config(mock_clean_env): """Tests that setup throws at bad configuration.""" launch.logging.reset()