utils_daemon.go 366 B

123456789101112131415161718
  1. // +build daemon
  2. package utils
  3. import (
  4. "os"
  5. "syscall"
  6. )
  7. // IsFileOwner checks whether the current user is the owner of the given file.
  8. func IsFileOwner(f string) bool {
  9. if fileInfo, err := os.Stat(f); err == nil && fileInfo != nil {
  10. if stat, ok := fileInfo.Sys().(*syscall.Stat_t); ok && int(stat.Uid) == os.Getuid() {
  11. return true
  12. }
  13. }
  14. return false
  15. }