chown_linux.go 396 B

12345678910111213141516171819
  1. package lumberjack
  2. import (
  3. "os"
  4. "syscall"
  5. )
  6. // os_Chown is a var so we can mock it out during tests.
  7. var os_Chown = os.Chown
  8. func chown(name string, info os.FileInfo) error {
  9. f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode())
  10. if err != nil {
  11. return err
  12. }
  13. f.Close()
  14. stat := info.Sys().(*syscall.Stat_t)
  15. return os_Chown(name, int(stat.Uid), int(stat.Gid))
  16. }