From 4dc50001060be415aab87989aa1f8065c8025666 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 2 Aug 2016 15:39:54 -0400 Subject: [PATCH] keywords: return non-zero symlink size Previously, the symlink size reported by a archive/tar header was 0. This is incorrect, as the size of a symlink should be the size of its contents, which is just the path to where the symlink points to. Thus, the size of this file would just be len(Linkname). Signed-off-by: Stephen Chung --- keywords.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/keywords.go b/keywords.go index 28d585f..88220a5 100644 --- a/keywords.go +++ b/keywords.go @@ -255,6 +255,11 @@ var ( return fmt.Sprintf("mode=%#o", permissions), nil } sizeKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (string, error) { + if sys, ok := info.Sys().(*tar.Header); ok { + if sys.Typeflag == tar.TypeSymlink { + return fmt.Sprintf("size=%d", len(sys.Linkname)), nil + } + } return fmt.Sprintf("size=%d", info.Size()), nil } cksumKeywordFunc = func(path string, info os.FileInfo, r io.Reader) (string, error) {