mirror of
https://github.com/rclone/rclone.git
synced 2025-08-16 00:28:09 +02:00
keep file permissions and try to keep user/group on supported systems (fixes #1467)
This commit is contained in:
35
fs/config_unix.go
Normal file
35
fs/config_unix.go
Normal file
@ -0,0 +1,35 @@
|
||||
// Read, write and edit the config file
|
||||
// Unix specific functions.
|
||||
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/user"
|
||||
"strconv"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
Debugf(nil, "Failed to keep previous owner of config file: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user