From 07638524bd63fe8debe0a055fe784365b48b31a4 Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Fri, 24 May 2024 13:41:12 +0200 Subject: [PATCH] Show setuid, setgid and sticky attributes See https://en.wikipedia.org/wiki/File-system_permissions#Notation_of_traditional_Unix_permissions --- dive/filetree/file_node.go | 26 +++++++++++++++++-- .../testdata/TestFileShowAggregateChanges.txt | 2 +- .../testdata/TestFileTreeDirCollapse.txt | 2 +- .../testdata/TestFileTreeDirCollapseAll.txt | 2 +- .../testdata/TestFileTreeDirCursorRight.txt | 2 +- .../viewmodel/testdata/TestFileTreeGoCase.txt | 2 +- .../TestFileTreeHideAddedRemovedModified.txt | 2 +- .../testdata/TestFileTreeSelectLayer.txt | 2 +- 8 files changed, 31 insertions(+), 9 deletions(-) diff --git a/dive/filetree/file_node.go b/dive/filetree/file_node.go index 2cb1bb7c..88ff29d0 100644 --- a/dive/filetree/file_node.go +++ b/dive/filetree/file_node.go @@ -141,11 +141,33 @@ func (node *FileNode) MetadataString() string { return "" } - fileMode := permbits.FileMode(node.Data.FileInfo.Mode).String() dir := "-" if node.Data.FileInfo.IsDir { dir = "d" } + + fm := permbits.FileMode(node.Data.FileInfo.Mode) + var fileMode strings.Builder + fileMode.Grow(9) + cond := func(c bool, x, y byte) byte { + if c { + return x + } else { + return y + } + } + fileMode.WriteByte(cond(fm.UserRead(), 'r', '-')) + fileMode.WriteByte(cond(fm.UserWrite(), 'w', '-')) + fileMode.WriteByte(cond(fm.UserExecute(), cond(fm.Setuid(), 's', 'x'), cond(fm.Setuid(), 'S', '-'))) + + fileMode.WriteByte(cond(fm.GroupRead(), 'r', '-')) + fileMode.WriteByte(cond(fm.GroupWrite(), 'w', '-')) + fileMode.WriteByte(cond(fm.GroupExecute(), cond(fm.Setgid(), 's', 'x'), cond(fm.Setgid(), 'S', '-'))) + + fileMode.WriteByte(cond(fm.OtherRead(), 'r', '-')) + fileMode.WriteByte(cond(fm.OtherWrite(), 'w', '-')) + fileMode.WriteByte(cond(fm.OtherExecute(), cond(fm.Sticky(), 't', 'x'), cond(fm.Sticky(), 'T', '-'))) + user := node.Data.FileInfo.Uid group := node.Data.FileInfo.Gid userGroup := fmt.Sprintf("%d:%d", user, group) @@ -156,7 +178,7 @@ func (node *FileNode) MetadataString() string { size := humanize.Bytes(uint64(sizeBytes)) - return diffTypeColor[node.Data.DiffType].Sprint(fmt.Sprintf(AttributeFormat, dir, fileMode, userGroup, size)) + return diffTypeColor[node.Data.DiffType].Sprint(fmt.Sprintf(AttributeFormat, dir, fileMode.String(), userGroup, size)) } func (node *FileNode) GetSize() int64 { diff --git a/runtime/ui/viewmodel/testdata/TestFileShowAggregateChanges.txt b/runtime/ui/viewmodel/testdata/TestFileShowAggregateChanges.txt index 5fdc49ca..4cce4eee 100644 --- a/runtime/ui/viewmodel/testdata/TestFileShowAggregateChanges.txt +++ b/runtime/ui/viewmodel/testdata/TestFileShowAggregateChanges.txt @@ -25,7 +25,7 @@ drwxr-xr-x 0:0 0 B │ │ │ └── nested -rw-r--r-- 0:0 6.4 kB │ │ └── somefile3.txt -rwxr-xr-x 0:0 6.4 kB │ └── saved.txt -rw-rw-r-- 0:0 6.4 kB ├── somefile.txt -drwxrwxrwx 0:0 6.4 kB ├── tmp +drwxrwxrwt 0:0 6.4 kB ├── tmp -rw-r--r-- 0:0 6.4 kB │ └── saved.again1.txt drwxr-xr-x 0:0 0 B ├── usr drwxr-xr-x 1:1 0 B │ └── sbin diff --git a/runtime/ui/viewmodel/testdata/TestFileTreeDirCollapse.txt b/runtime/ui/viewmodel/testdata/TestFileTreeDirCollapse.txt index 09b1f31b..23c5246e 100644 --- a/runtime/ui/viewmodel/testdata/TestFileTreeDirCollapse.txt +++ b/runtime/ui/viewmodel/testdata/TestFileTreeDirCollapse.txt @@ -3,7 +3,7 @@ drwxr-xr-x 0:0 0 B ├── dev drwxr-xr-x 0:0 1.0 kB ├─⊕ etc drwxr-xr-x 65534:65534 0 B ├── home drwx------ 0:0 0 B ├── root -drwxrwxrwx 0:0 0 B ├── tmp +drwxrwxrwt 0:0 0 B ├── tmp drwxr-xr-x 0:0 0 B ├── usr drwxr-xr-x 1:1 0 B │ └── sbin drwxr-xr-x 0:0 0 B └── var diff --git a/runtime/ui/viewmodel/testdata/TestFileTreeDirCollapseAll.txt b/runtime/ui/viewmodel/testdata/TestFileTreeDirCollapseAll.txt index 581ba484..89d27dde 100644 --- a/runtime/ui/viewmodel/testdata/TestFileTreeDirCollapseAll.txt +++ b/runtime/ui/viewmodel/testdata/TestFileTreeDirCollapseAll.txt @@ -3,7 +3,7 @@ drwxr-xr-x 0:0 0 B ├── dev drwxr-xr-x 0:0 1.0 kB ├─⊕ etc drwxr-xr-x 65534:65534 0 B ├── home drwx------ 0:0 0 B ├── root -drwxrwxrwx 0:0 0 B ├── tmp +drwxrwxrwt 0:0 0 B ├── tmp drwxr-xr-x 0:0 0 B ├─⊕ usr drwxr-xr-x 0:0 0 B └─⊕ var diff --git a/runtime/ui/viewmodel/testdata/TestFileTreeDirCursorRight.txt b/runtime/ui/viewmodel/testdata/TestFileTreeDirCursorRight.txt index c4126a9a..bab317d8 100644 --- a/runtime/ui/viewmodel/testdata/TestFileTreeDirCursorRight.txt +++ b/runtime/ui/viewmodel/testdata/TestFileTreeDirCursorRight.txt @@ -12,7 +12,7 @@ drwxr-xr-x 0:0 0 B │ │ └── if-up.d -rw------- 0:0 243 B │ └── shadow drwxr-xr-x 65534:65534 0 B ├── home drwx------ 0:0 0 B ├── root -drwxrwxrwx 0:0 0 B ├── tmp +drwxrwxrwt 0:0 0 B ├── tmp drwxr-xr-x 0:0 0 B ├── usr drwxr-xr-x 1:1 0 B │ └── sbin drwxr-xr-x 0:0 0 B └── var diff --git a/runtime/ui/viewmodel/testdata/TestFileTreeGoCase.txt b/runtime/ui/viewmodel/testdata/TestFileTreeGoCase.txt index e86415c6..1c1e43c8 100644 --- a/runtime/ui/viewmodel/testdata/TestFileTreeGoCase.txt +++ b/runtime/ui/viewmodel/testdata/TestFileTreeGoCase.txt @@ -406,7 +406,7 @@ drwxr-xr-x 0:0 0 B │ │ └── if-up.d -rw------- 0:0 243 B │ └── shadow drwxr-xr-x 65534:65534 0 B ├── home drwx------ 0:0 0 B ├── root -drwxrwxrwx 0:0 0 B ├── tmp +drwxrwxrwt 0:0 0 B ├── tmp drwxr-xr-x 0:0 0 B ├── usr drwxr-xr-x 1:1 0 B │ └── sbin drwxr-xr-x 0:0 0 B └── var diff --git a/runtime/ui/viewmodel/testdata/TestFileTreeHideAddedRemovedModified.txt b/runtime/ui/viewmodel/testdata/TestFileTreeHideAddedRemovedModified.txt index a34de17d..d0e35ef3 100644 --- a/runtime/ui/viewmodel/testdata/TestFileTreeHideAddedRemovedModified.txt +++ b/runtime/ui/viewmodel/testdata/TestFileTreeHideAddedRemovedModified.txt @@ -11,7 +11,7 @@ drwxr-xr-x 0:0 0 B │ │ └── if-up.d -rw-r--r-- 0:0 340 B │ ├── passwd -rw------- 0:0 243 B │ └── shadow drwxr-xr-x 65534:65534 0 B ├── home -drwxrwxrwx 0:0 0 B ├── tmp +drwxrwxrwt 0:0 0 B ├── tmp drwxr-xr-x 0:0 0 B ├── usr drwxr-xr-x 1:1 0 B │ └── sbin drwxr-xr-x 0:0 0 B └── var diff --git a/runtime/ui/viewmodel/testdata/TestFileTreeSelectLayer.txt b/runtime/ui/viewmodel/testdata/TestFileTreeSelectLayer.txt index 360737b5..a5ade1cc 100644 --- a/runtime/ui/viewmodel/testdata/TestFileTreeSelectLayer.txt +++ b/runtime/ui/viewmodel/testdata/TestFileTreeSelectLayer.txt @@ -13,7 +13,7 @@ drwxr-xr-x 0:0 0 B │ │ └── if-up.d drwxr-xr-x 65534:65534 0 B ├── home drwx------ 0:0 0 B ├── root -rw-rw-r-- 0:0 6.4 kB ├── somefile.txt -drwxrwxrwx 0:0 0 B ├── tmp +drwxrwxrwt 0:0 0 B ├── tmp drwxr-xr-x 0:0 0 B ├── usr drwxr-xr-x 1:1 0 B │ └── sbin drwxr-xr-x 0:0 0 B └── var