Skip to content

Commit 5d75752

Browse files
committed
feat: allow for symlinks in tar files
1 parent d9b26fc commit 5d75752

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,18 @@ func addFileToTar(tw *tar.Writer, path string, pathInArchive string) error {
421421
}
422422
defer file.Close()
423423

424-
if stat, err := file.Stat(); err == nil {
424+
if stat, err := os.Lstat(path); err == nil {
425+
var linkTarget string
426+
// Check if file is symlink
427+
if stat.Mode()&os.ModeSymlink != 0 {
428+
log.Printf("Found link: %s", path)
429+
var err error
430+
linkTarget, err = os.Readlink(path)
431+
if err != nil {
432+
return fmt.Errorf("%s: readlink: %v", stat.Name(), err)
433+
}
434+
}
435+
425436
// now lets create the header as needed for this file within the tarball
426437
header, err := tar.FileInfoHeader(stat, filepath.ToSlash(linkTarget))
427438
if err != nil {

0 commit comments

Comments
 (0)