From ba7779400068a74eea75f8408bd14e43dad8e990 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: May 18 2023 10:51:36 +0000 Subject: Ignore non-latest symlinks --- diff --git a/compose_utils/symlink.py b/compose_utils/symlink.py index 424f6ed..ac4e1e6 100644 --- a/compose_utils/symlink.py +++ b/compose_utils/symlink.py @@ -108,9 +108,10 @@ def update_symlinks(compose_path, dry_run=False): def ver_len(s): return s.count(".") - # Find all symlinks in the directory. + # Find all latest symlinks in the directory. all_symlinks = filter( - lambda x: os.path.islink(os.path.join(compose_path, x)), os.listdir(compose_path) + lambda x: os.path.islink(os.path.join(compose_path, x)), + (x for x in os.listdir(compose_path) if latest_symlink_re.match(x)), ) # Filter the ones with most version components. links = sorted(all_symlinks, key=ver_len, reverse=True) diff --git a/tests/test_symlink.py b/tests/test_symlink.py index 0690748..82c3b34 100644 --- a/tests/test_symlink.py +++ b/tests/test_symlink.py @@ -175,3 +175,11 @@ class TestUpdateSymlinks(unittest.TestCase): self.assert_symlink('latest-DP-1.1-B-2', 'latest-DP-1.1.0-B-2') self.assert_symlink('latest-DP-1.2-B-2', 'latest-DP-1.2.0-B-2') self.assert_symlink('latest-DP-1.3-B-2', 'latest-DP-1.3.0-B-2') + + def test_ignore_non_latest_symlink(self): + self.create_full_symlink('latest-DP-1.0') + self.create_full_symlink('DP-1.0-20230510.0') + + symlink.update_symlinks(self.compose_dir) + + self.assert_symlink('latest-DP-1', 'latest-DP-1.0')