summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/natefinch/lumberjack.v2/chown_linux.go
blob: 2758ec9cedd6e94a4e5b1a735e614efcd7a9e6ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package lumberjack

import (
	"os"
	"syscall"
)

// os_Chown is a var so we can mock it out during tests.
var os_Chown = os.Chown

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)
	return os_Chown(name, int(stat.Uid), int(stat.Gid))
}