Skip to content

fix: make clone-cache copy tolerate symlinks and existing dirs - #108

Open
eugene-nuvacore wants to merge 1 commit into
c0fec0de:mainfrom
eugene-nuvacore:clone-cache-symlinks
Open

fix: make clone-cache copy tolerate symlinks and existing dirs#108
eugene-nuvacore wants to merge 1 commit into
c0fec0de:mainfrom
eugene-nuvacore:clone-cache-symlinks

Conversation

@eugene-nuvacore

Copy link
Copy Markdown

Cloning a repository through the clone cache (GIT_WS_CLONE_CACHE) fails when the repository contains a dangling symlink — a symlink whose target doesn't exist on the machine.

git-ws populates and serves the cache with shutil.copytree, which follows symlinks by default (symlinks=False). When it encounters a symlink pointing at a missing target, it tries to copy the target and aborts the whole clone with ENOENT.

Pass symlinks=True to copytree at both copy sites so symlinks are recreated as-is instead of dereferenced

Copying a cache entry into the workspace used shutil.copytree with defaults,
which broke two real cases:

- A cached repo may contain a dangling symlink (e.g. edk2's EmulatorPkg
  X11IncludeHack, pointing at system X11 headers that need not exist); copytree
  followed it and aborted with ENOENT. Copy with symlinks=True at both sites:
  the cache -> workspace copy in Git._clone_cache and the atomic-update copy in
  _pathlock (hit when an existing cache entry is reused).

- The destination may be an empty submodule mountpoint left by a parent clone
  (a dependency whose path lands inside another repo's uninitialised submodule);
  copytree rejected the existing dir with FileExistsError, though plain git clone
  tolerates it. Copy with dirs_exist_ok=True in _clone_cache (clone() already
  asserts the destination is empty).

Add regression tests covering the dangling-symlink and existing-empty-dir cases
across the cache-init and cache-reuse paths.
@eugene-nuvacore eugene-nuvacore changed the title fix: preserve symlinks when copying the clone cache fix: make clone-cache copy tolerate symlinks and existing dirs Jul 17, 2026
@eugene-nuvacore

Copy link
Copy Markdown
Author

@c0fec0de please review at your convenience, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant