...

Source file src/edge-infra.dev/pkg/lib/filesystem/owners.go

Documentation: edge-infra.dev/pkg/lib/filesystem

     1  package filesystem
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	syscall "golang.org/x/sys/unix"
     8  )
     9  
    10  const (
    11  	GroupReadWritePerm os.FileMode = syscall.S_IRGRP | syscall.S_IWGRP
    12  )
    13  
    14  // GroupID will attempt to stat and fetch the group owner id
    15  // for the given file path
    16  func GroupID(path string) (int64, error) {
    17  	statInfo := syscall.Stat_t{}
    18  	if err := syscall.Stat(path, &statInfo); err != nil {
    19  		return -1, fmt.Errorf("failed to stat file: %w", err)
    20  	}
    21  	return int64(statInfo.Gid), nil
    22  }
    23  
    24  // UserID will attempt to stat and fetch the user owner id
    25  // for the given file path
    26  func UserID(path string) (int64, error) {
    27  	statInfo := syscall.Stat_t{}
    28  	if err := syscall.Stat(path, &statInfo); err != nil {
    29  		return -1, fmt.Errorf("failed to stat file: %w", err)
    30  	}
    31  	return int64(statInfo.Uid), nil
    32  }
    33  

View as plain text