Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show setuid, setgid and sticky attributes #524

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions dive/filetree/file_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/ui/viewmodel/testdata/TestFileTreeDirCollapse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/ui/viewmodel/testdata/TestFileTreeGoCase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/ui/viewmodel/testdata/TestFileTreeSelectLayer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down