Skip to content

proposal: archive/tar: AddFS: add support for symlinks outside subdirectory #73464

@dmivankov

Description

@dmivankov

Proposal Details

1.25 AddFS will support resolving symlinks to their target contents,
but it doesn't work for symlinks pointing to locations outside of added fs

func (tw *Writer) AddFS(fsys fs.FS) error {
	return fs.WalkDir(fsys, ".", func(name string, d fs.DirEntry, err error) error {

Here whole fs is traversed, so fs should be the whole archive contents.
Despite fs not being chroot symlink resolution to targets outside fs doesn't work.

Context

Bazel and rules_oci use symlinks for build actions environment setup, there an OCI image layout can be in one directory but some of base layer blobs be symlink to locations in another directory. If Go archive/tar is used to archive that image AddFS won't be able to package it and fail

Proposal

Replace hardcoded "." walkdir start with a subdirectory string parameter, then it will be possible to archive
symlinks pointing to outside of archive directory, by calling AddFS(os.DirFS("/"), absolutePath) or say AddFS(pwd, subdirectory) when all dependencies are within pwd but archive only needs to contain subdirectory layout

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions