From e29b993aa2fe5367938ffdc391ffbca511d83e8e Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 15 Jul 2016 15:35:56 -0400 Subject: [PATCH] keywords: obtain all permission bits Fixes #7. Upper 3 bits are 'special' mode bits, and are not included when calling info.Mode().Perm(). Need to mask the info.Mode() with the corresponding mode bit defined by the go library to see if these bits are set or not. Signed-off-by: Stephen Chung --- keywords.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/keywords.go b/keywords.go index 8b01c80..c6607c9 100644 --- a/keywords.go +++ b/keywords.go @@ -166,7 +166,17 @@ var ( var ( modeKeywordFunc = func(path string, info os.FileInfo) (string, error) { - return fmt.Sprintf("mode=%#o", info.Mode().Perm()), nil + permissions := info.Mode().Perm() + if os.ModeSetuid&info.Mode() > 0 { + permissions |= (1 << 11) + } + if os.ModeSetgid&info.Mode() > 0 { + permissions |= (1 << 10) + } + if os.ModeSticky&info.Mode() > 0 { + permissions |= (1 << 9) + } + return fmt.Sprintf("mode=%#o", permissions), nil } sizeKeywordFunc = func(path string, info os.FileInfo) (string, error) { return fmt.Sprintf("size=%d", info.Size()), nil