2022-03-26 13:34:10 -04:00
|
|
|
//go:build !windows
|
2019-12-17 03:36:25 -05:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package configfile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// copyFilePermissions copies file ownership and permissions from "src" to "dst",
|
|
|
|
// ignoring any error during the process.
|
|
|
|
func copyFilePermissions(src, dst string) {
|
|
|
|
var (
|
2022-09-30 13:13:22 -04:00
|
|
|
mode os.FileMode = 0o600
|
2019-12-17 03:36:25 -05:00
|
|
|
uid, gid int
|
|
|
|
)
|
|
|
|
|
|
|
|
fi, err := os.Stat(src)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if fi.Mode().IsRegular() {
|
|
|
|
mode = fi.Mode()
|
|
|
|
}
|
|
|
|
if err := os.Chmod(dst, mode); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
uid = int(fi.Sys().(*syscall.Stat_t).Uid)
|
|
|
|
gid = int(fi.Sys().(*syscall.Stat_t).Gid)
|
|
|
|
|
|
|
|
if uid > 0 && gid > 0 {
|
|
|
|
_ = os.Chown(dst, uid, gid)
|
|
|
|
}
|
|
|
|
}
|