Skip to content

archive/zip: AddFS with a symlink results in an empty file #61875

Description

@mauri870

What version of Go are you using (go version)?

$ go version
tip

Does this issue reproduce with the latest release?

Yes, this is a tip (1.22) only issue.

What did you do?

Tried to call AddFS with a fs.FS with symlinks.

package main

import (
	"archive/zip"
	"log"
	"os"
)

func main() {
	fsys := os.DirFS("./dir") // ./dir contains symlinks inside
	f, err := os.OpenFile("file.zip", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	zw := zip.NewWriter(f)
	defer zw.Close()
	zw.AddFS(fsys)
}

What did you expect to see?

Either an error or the proper file contents.

What did you see instead?

Files that are symlinks result in an empty file inside the zip archive.

Had a discussion on this CL about symlink support in zip files.
We have the proposal for fs.ReadLinkFS that could somewhat make this possible to implement, but the proposal is currently on hold.

I see a couple options to be weighted:

  • Keep it as it is, file gets added to the zip but is empty
  • Detect files that are symlinks and then return an error upon calling AddFS
  • Don't return an error and don't add the file to the zip. This seems to be the behavior with the zip command line tool. There is a logged message zip warning: name not matched: ./dir/iamasymlink but the zip gets created, skipping the symlinks.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.release-blocker

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions