Skip to content

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

Merged
aiuto merged 2 commits into
bazelbuild:mainfrom
JSGette:jsgette/pkg-install-windows-junctions
Oct 1, 2026
Merged

aiuto merged 2 commits into
bazelbuild:mainfrom
JSGette:jsgette/pkg-install-windows-junctions

Conversation

@JSGette

@JSGette JSGette commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

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

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>
@aiuto

aiuto commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Can you rebase and push so tests run without the broken setup.

--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.
@JSGette
JSGette force-pushed the jsgette/pkg-install-windows-junctions branch from 2bd3f8c to e5e3b7c Compare October 1, 2026 08:04
@JSGette
JSGette marked this pull request as ready for review October 1, 2026 08:05
@JSGette
JSGette requested review from aiuto and cgrindel as code owners October 1, 2026 08:05
@aiuto
aiuto merged commit 1b2295d into bazelbuild:main Oct 1, 2026
6 checks passed
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.

3 participants