Skip to content

Commit

Permalink
Avoid re-fetching symlinks on every run if we already have a matching…
Browse files Browse the repository at this point in the history
… one

Previously, symlinks would not be re-fetched when a tarball was available, but
now we might not have a tarball, even if the package in question is already
installed.

Just look for a symlinks with a matching hash (since that's all we really need
here).
  • Loading branch information
TimoWilken committed Mar 6, 2024
1 parent 7f3ccd9 commit de261e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions alibuild_helpers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ def fetch_symlinks(self, spec):
links_path = resolve_links_path(self.architecture, spec["package"])
os.makedirs(os.path.join(self.workdir, links_path), exist_ok=True)

# If we already have a symlink we can use, don't update the list. This
# speeds up rebuilds significantly.
if any(f"/{pkg_hash[:2]}/{pkg_hash}/" in target
for target in (os.readlink(os.path.join(self.workdir, links_path, link))
for link in os.listdir(os.path.join(self.workdir, links_path)))
for pkg_hash in spec["remote_hashes"]):
debug("Found symlink for %s@%s, not updating", spec["package"], spec["version"])
return

Check warning on line 196 in alibuild_helpers/sync.py

View check run for this annotation

Codecov / codecov/patch

alibuild_helpers/sync.py#L195-L196

Added lines #L195 - L196 were not covered by tests

with requests.Session() as session:
# Fetch manifest file with initial symlinks. This file is updated
# regularly; we use it to avoid many small network requests.
Expand Down
1 change: 1 addition & 0 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def mock_get(self, url, *args, **kw):
@patch("os.path.isfile", new=MagicMock(return_value=False))
@patch("os.rename", new=MagicMock(return_value=None))
@patch("os.makedirs", new=MagicMock(return_value=None))
@patch("os.listdir", new=MagicMock(return_value=[]))
@patch("alibuild_helpers.sync.symlink", new=MagicMock(return_value=None))
@patch("alibuild_helpers.sync.execute", new=MagicMock(return_value=None))
@patch("alibuild_helpers.sync.debug")
Expand Down

0 comments on commit de261e0

Please sign in to comment.