Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame^] | 1 | package lumberjack |
2 | |||||
3 | import ( | ||||
4 | "os" | ||||
5 | "syscall" | ||||
6 | ) | ||||
7 | |||||
8 | // os_Chown is a var so we can mock it out during tests. | ||||
9 | var os_Chown = os.Chown | ||||
10 | |||||
11 | func 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 | } |