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