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()