24 lines
573 B
Go
24 lines
573 B
Go
//go:build !windows
|
|
|
|
package app
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
// preserveOwnership applies the owner and group of the original file to the
|
|
// temporary replacement file. Permission failures are ignored because the
|
|
// process may be allowed to replace the file without being allowed to chown it.
|
|
func preserveOwnership(path string, info os.FileInfo) error {
|
|
stat, ok := info.Sys().(*syscall.Stat_t)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
if err := os.Chown(path, int(stat.Uid), int(stat.Gid)); err != nil && !errors.Is(err, os.ErrPermission) {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|