Skip to content

Commit 5ad4a37

Browse files
committed
chown
1 parent ba3df51 commit 5ad4a37

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

chown.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// +build !linux
2+
3+
package timberjack
4+
5+
import (
6+
"os"
7+
)
8+
9+
func chown(_ string, _ os.FileInfo) error {
10+
return nil
11+
}

chown_linux.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package timberjack
2+
3+
import (
4+
"os"
5+
"syscall"
6+
)
7+
8+
// osChown is a var so we can mock it out during tests.
9+
var osChown = 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 osChown(name, int(stat.Uid), int(stat.Gid))
19+
}

0 commit comments

Comments
 (0)