MCPcopy
hub / github.com/syncthing/syncthing / syncOwnership

Method syncOwnership

lib/model/folder_sendrecv_unix.go:19–45  ·  view source on GitHub ↗
(file *protocol.FileInfo, path string)

Source from the content-addressed store, hash-verified

17)
18
19func (f *sendReceiveFolder) syncOwnership(file *protocol.FileInfo, path string) error {
20 if file.Platform.Unix == nil {
21 // No owner data, nothing to do
22 return nil
23 }
24
25 // Try to look up the user and group by name, defaulting to the
26 // numerical UID and GID if there is no match.
27
28 uid := strconv.Itoa(file.Platform.Unix.UID)
29 if file.Platform.Unix.OwnerName != "" {
30 us, err := user.Lookup(file.Platform.Unix.OwnerName)
31 if err == nil && us.Uid != "" {
32 uid = us.Uid
33 }
34 }
35
36 gid := strconv.Itoa(file.Platform.Unix.GID)
37 if file.Platform.Unix.GroupName != "" {
38 gr, err := user.LookupGroup(file.Platform.Unix.GroupName)
39 if err == nil && gr.Gid != "" {
40 gid = gr.Gid
41 }
42 }
43
44 return f.mtimefs.Lchown(path, uid, gid)
45}

Callers 1

setPlatformDataMethod · 0.95

Calls 2

LookupMethod · 0.65
LchownMethod · 0.65

Tested by

no test coverage detected