2017-06-25 15:05:24 +08:00
|
|
|
// Read, write and edit the config file
|
|
|
|
// Unix specific functions.
|
|
|
|
|
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
|
|
|
|
2020-11-08 05:05:58 +08:00
|
|
|
package configfile
|
2017-06-25 15:05:24 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/user"
|
|
|
|
"strconv"
|
|
|
|
"syscall"
|
2018-01-13 00:30:54 +08:00
|
|
|
|
2019-07-29 01:47:38 +08:00
|
|
|
"github.com/rclone/rclone/fs"
|
2017-06-25 15:05:24 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// attemptCopyGroups tries to keep the group the same. User will be the one
|
|
|
|
// who is currently running this process.
|
|
|
|
func attemptCopyGroup(fromPath, toPath string) {
|
|
|
|
info, err := os.Stat(fromPath)
|
|
|
|
if err != nil || info.Sys() == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if stat, ok := info.Sys().(*syscall.Stat_t); ok {
|
|
|
|
uid := int(stat.Uid)
|
|
|
|
// prefer self over previous owner of file, because it has a higher chance
|
|
|
|
// of success
|
|
|
|
if user, err := user.Current(); err == nil {
|
|
|
|
if tmpUID, err := strconv.Atoi(user.Uid); err == nil {
|
|
|
|
uid = tmpUID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err = os.Chown(toPath, uid, int(stat.Gid)); err != nil {
|
2018-01-13 00:30:54 +08:00
|
|
|
fs.Debugf(nil, "Failed to keep previous owner of config file: %v", err)
|
2017-06-25 15:05:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|