forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/gopkg.in/natefinch/lumberjack.v2/chown_linux.go

29 lines
402 B
Go
Raw Normal View History

2024-02-18 10:42:21 +00:00
package lumberjack
import (
"os"
"syscall"
)
// osChown is a var so we can mock it out during tests.
2024-02-18 10:42:21 +00:00
var osChown = os.Chown
func chown(name string, info os.FileInfo) error {
2024-02-18 10:42:21 +00:00
f, err := os.OpenFile(name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode())
2024-02-18 10:42:21 +00:00
if err != nil {
2024-02-18 10:42:21 +00:00
return err
2024-02-18 10:42:21 +00:00
}
2024-02-18 10:42:21 +00:00
f.Close()
2024-02-18 10:42:21 +00:00
stat := info.Sys().(*syscall.Stat_t)
2024-02-18 10:42:21 +00:00
return osChown(name, int(stat.Uid), int(stat.Gid))
2024-02-18 10:42:21 +00:00
}