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.
What version of Go are you using (
go version)?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.
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:
zip warning: name not matched: ./dir/iamasymlinkbut the zip gets created, skipping the symlinks.