You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed a bug: it's skipping over empty directories in the output tar file! (Tar archives are not git directories and this is not expected.)
I've looked at the source for the AddFS function and I've created a fixed version which correctly adds those directories. It's shown here as a standalone function. You can transplant the body over to the function.
Cheers!
func addFS(tw *tar.Writer, fsys fs.FS) error {
return fs.WalkDir(fsys, ".", func(name string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
info, err := d.Info()
if err != nil {
return err
}
// TODO(#49580): Handle symlinks when fs.ReadLinkFS is available.
if !info.Mode().IsRegular() && !info.Mode().IsDir() {
return fmt.Errorf("tar: cannot add non-regular file")
}
h, err := tar.FileInfoHeader(info, "")
if err != nil {
return err
}
h.Name = name
if d.IsDir() {
h.Name += "/" // dir
fmt.Printf("XXX: DIR: %+v\n", h.Name)
}
if err := tw.WriteHeader(h); err != nil {
return err
}
if d.IsDir() {
return nil // no contents to copy in
}
f, err := fsys.Open(name)
if err != nil {
return err
}
defer f.Close()
_, err = io.Copy(tw, f)
return err
})
}
The text was updated successfully, but these errors were encountered:
Go version
1.23
Output of
go env
in your module/workspace:What did you do?
Created a tar file that should have included empty directories.
What did you see happen?
No empty directories were included.
What did you expect to see?
I'm using the archive/tar package and the AddFS function: https://pkg.go.dev/archive/tar#Writer.AddFS
This is very useful thanks!
I noticed a bug: it's skipping over empty directories in the output tar file! (Tar archives are not git directories and this is not expected.)
I've looked at the source for the AddFS function and I've created a fixed version which correctly adds those directories. It's shown here as a standalone function. You can transplant the body over to the function.
Cheers!
The text was updated successfully, but these errors were encountered: