mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 18:41:59 -07:00
75dcff0a0e
This adds a folder option "CopyOwnershipFromParent" which, when set, makes Syncthing attempt to retain the owner/group information when syncing files. Specifically, at the finisher stage we look at the parent dir to get owner/group and then attempt a Lchown call on the temp file. For this to succeed Syncthing must be running with the appropriate permissions. On Linux this is CAP_FOWNER, which can be granted by the service manager on startup or set on the binary in the filesystem. Other operating systems do other things, but often it's not required to run as full "root". On Windows this patch does nothing - ownership works differently there and is generally less of a deal, as permissions are inherited as ACLs anyway. There are unit tests on the Lchown functionality, which requires the above permissions to run. There is also a unit test on the folder which uses the fake filesystem and hence does not need special permissions.
26 lines
537 B
Go
26 lines
537 B
Go
// Copyright (C) 2019 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
// +build !windows
|
|
|
|
package fs
|
|
|
|
import "syscall"
|
|
|
|
func (e fsFileInfo) Owner() int {
|
|
if st, ok := e.Sys().(*syscall.Stat_t); ok {
|
|
return int(st.Uid)
|
|
}
|
|
return -1
|
|
}
|
|
|
|
func (e fsFileInfo) Group() int {
|
|
if st, ok := e.Sys().(*syscall.Stat_t); ok {
|
|
return int(st.Gid)
|
|
}
|
|
return -1
|
|
}
|