Debian Codegraph @

internal/test/testsuite/socket_unix.go

raw
1 //go:build !windows
2
3 package testsuite
4
5 import (
6 "errors"
7 "fmt"
8 "os"
9 "syscall"
10 )
11
12 // GetGIDOfFile returns the numeric group ID of the given file.
13 func GetGIDOfFile(fileName string) (int, error) {
14 stat, err := os.Stat(fileName)
15 if err != nil {
16 return 0, fmt.Errorf("failed to get file stat: %w", err)
17 }
18
19 gid, ok := stat.Sys().(*syscall.Stat_t)
20
21 if !ok {
22 return 0, errors.New("no stat_t")
23 }
24
25 return int(gid.Gid), nil
26 }
27
28 // GetPermissionsOfFile returns the permission bits of the given file as a
29 // string, for example "drwxr-xr-x".
30 func GetPermissionsOfFile(fileName string) (string, error) {
31 stat, err := os.Stat(fileName)
32 if err != nil {
33 return "", fmt.Errorf("failed to get file stat: %w", err)
34 }
35
36 return stat.Mode().Perm().String(), nil
37 }