blob: 2758ec9cedd6e94a4e5b1a735e614efcd7a9e6ca [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001package lumberjack
2
3import (
4 "os"
5 "syscall"
6)
7
8// os_Chown is a var so we can mock it out during tests.
9var os_Chown = os.Chown
10
11func chown(name string, info os.FileInfo) error {
12 f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode())
13 if err != nil {
14 return err
15 }
16 f.Close()
17 stat := info.Sys().(*syscall.Stat_t)
18 return os_Chown(name, int(stat.Uid), int(stat.Gid))
19}