Skip to content

Handle symlink entries correctly in ACR remote build context packing#9071

Draft
bterlson with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-pack-remote-build-source-symlinks
Draft

Handle symlink entries correctly in ACR remote build context packing#9071
bterlson with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-pack-remote-build-source-symlinks

Conversation

Copilot AI commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

PackRemoteBuildSource treated all non-directory entries as regular files, so symlinked directories in the build context caused io.Copy to read a directory fd (EISDIR) and abort archive creation. It also generated incorrect symlink tar metadata by passing info.Name() instead of the symlink target to tar.FileInfoHeader.

  • Symlink-aware tar header generation

    • Detect symlinks from FileMode.
    • Resolve link target via os.Readlink(path).
    • Pass the resolved target into tar.FileInfoHeader(info, linkTarget) so tar entries preserve correct Linkname.
  • Payload copy restricted to regular files

    • Continue writing tar headers for included entries.
    • Only stream file bytes when info.Mode().IsRegular().
    • Avoid attempting to open/copy symlink entries (and other non-regular entries) as file payloads.
  • Regression coverage for symlink contexts

    • Added focused tests for:
      • symlink → directory
      • symlink → file
    • Assertions validate tar entry type (TypeSymlink) and preserved link target.
linkTarget, err := getSymlinkTarget(path, info.Mode())
if err != nil {
	return err
}

hdr, err := tar.FileInfoHeader(info, linkTarget)
if err != nil {
	return err
}

if err := tw.WriteHeader(hdr); err != nil {
	return err
}

if info.Mode().IsRegular() {
	f, err := os.Open(path)
	if err != nil {
		return err
	}
	defer f.Close()

	if _, err := io.Copy(tw, f); err != nil {
		return err
	}
}

Copilot AI changed the title [WIP] Fix PackRemoteBuildSource to handle symlinks correctly Handle symlink entries correctly in ACR remote build context packing Jul 10, 2026
Copilot AI requested a review from bterlson July 10, 2026 00:29
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.

ACR remote build: PackRemoteBuildSource fails on symlinks ("is a directory"); mishandles symlink tar entries

2 participants