Skip to content

fix(install): follow Windows runfiles junctions when copying files - #1076

Draft
JSGette wants to merge 2 commits into
bazelbuild:mainfrom
JSGette:jsgette/pkg-install-windows-junctions
Draft

fix(install): follow Windows runfiles junctions when copying files#1076
JSGette wants to merge 2 commits into
bazelbuild:mainfrom
JSGette:jsgette/pkg-install-windows-junctions

Conversation

@JSGette

@JSGette JSGette commented Aug 13, 2026

Copy link
Copy Markdown

pkg_install fails on Windows when --enable_runfiles is set. Bazel materializes file runfiles as directory junctions, but junctions cannot point at files, so shutil.copyfile or open() raises PermissionError: [Errno 13] Permission denied.

os.path.realpath() resolves full path following symlinks, so that is essentially a no-op on Unix (extra stat() call) but resolves junctions on Windows

--enable_runfiles on Windows creates directory junctions for file runfiles.
Junctions cannot point at files, so shutil.copyfile fails with Permission denied.
Resolve the reparse point before copying.
Suggested by @alopezz: realpath resolves reparse points on Windows
and symlinks on Unix, removing the need for sys.platform conditional
and os.readlink try/except.
gh-worker-dd-mergequeue-cf854d Bot pushed a commit to DataDog/datadog-agent that referenced this pull request Aug 17, 2026
<!--Please give us some feedback on your experience writing this PR ! https://app.datadoghq.com/forms/43db4c02-6837-400c-8083-692e141b1b88 !-->

### What does this PR do?

As described in bazelbuild/rules_pkg#1076, Bazel creates a junction on files that is wrong as they are only supposed to be used with directories. This leads to permission errors:
```python
PermissionError: [Errno 13] Permission denied
```

Co-authored-by: joseph.gette <joseph.gette@datadoghq.com>
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