Skip to content

Commit

Permalink
Apply PR mholt#296 from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
kolbycrouch committed Oct 23, 2021
1 parent 3a58df2 commit ffb0f0c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions archiver.go
Expand Up @@ -125,6 +125,7 @@ type File struct {
type FileInfo struct {
os.FileInfo
CustomName string
SrcPath string
}

// Name returns fi.CustomName if not empty;
Expand Down
9 changes: 7 additions & 2 deletions tar.go
Expand Up @@ -333,6 +333,7 @@ func (t *Tar) writeWalk(source, topLevelFolder, destination string) error {
FileInfo: FileInfo{
FileInfo: info,
CustomName: nameInArchive,
SrcPath: fpath,
},
ReadCloser: file,
})
Expand Down Expand Up @@ -378,10 +379,14 @@ func (t *Tar) Write(f File) error {

var linkTarget string
if isSymlink(f) {
fi, ok := f.FileInfo.(FileInfo)
if !ok {
return fmt.Errorf("failed to cast fs.FileInfo to archiver.FileInfo: %v", f)
}
var err error
linkTarget, err = os.Readlink(f.Name())
linkTarget, err = os.Readlink(fi.SrcPath)
if err != nil {
return fmt.Errorf("%s: readlink: %v", f.Name(), err)
return fmt.Errorf("%s: readlink: %v", fi.SrcPath, err)
}
}

Expand Down
11 changes: 8 additions & 3 deletions zip.go
Expand Up @@ -353,6 +353,7 @@ func (z *Zip) writeWalk(source, topLevelFolder, destination string) error {
FileInfo: FileInfo{
FileInfo: info,
CustomName: nameInArchive,
SrcPath: fpath,
},
ReadCloser: file,
})
Expand Down Expand Up @@ -434,14 +435,18 @@ func (z *Zip) writeFile(f File, writer io.Writer) error {
return nil // directories have no contents
}
if isSymlink(f) {
fi, ok := f.FileInfo.(FileInfo)
if !ok {
return fmt.Errorf("failed to cast fs.FileInfo to archiver.FileInfo: %v", f)
}
// file body for symlinks is the symlink target
linkTarget, err := os.Readlink(f.Name())
linkTarget, err := os.Readlink(fi.SrcPath)
if err != nil {
return fmt.Errorf("%s: readlink: %v", f.Name(), err)
return fmt.Errorf("%s: readlink: %v", fi.SrcPath, err)
}
_, err = writer.Write([]byte(filepath.ToSlash(linkTarget)))
if err != nil {
return fmt.Errorf("%s: writing symlink target: %v", f.Name(), err)
return fmt.Errorf("%s: writing symlink target: %v", fi.SrcPath, err)
}
return nil
}
Expand Down

0 comments on commit ffb0f0c

Please sign in to comment.