MCPcopy
hub / github.com/containerd/containerd / chown

Function chown

client/container_opts_unix.go:127–147  ·  view source on GitHub ↗
(root string, idMap userns.IDMap)

Source from the content-addressed store, hash-verified

125}
126
127func chown(root string, idMap userns.IDMap) filepath.WalkFunc {
128 return func(path string, info os.FileInfo, err error) error {
129 if err != nil {
130 return err
131 }
132 stat := info.Sys().(*syscall.Stat_t)
133 h, cerr := idMap.ToHost(userns.User{Uid: stat.Uid, Gid: stat.Gid})
134 if cerr != nil {
135 return cerr
136 }
137 // be sure the lchown the path as to not de-reference the symlink to a host file
138 if cerr = os.Lchown(path, int(h.Uid), int(h.Gid)); cerr != nil {
139 return cerr
140 }
141 // we must retain special permissions such as setuid, setgid and sticky bits
142 if mode := info.Mode(); mode&os.ModeSymlink == 0 && mode&(os.ModeSetuid|os.ModeSetgid|os.ModeSticky) != 0 {
143 return os.Chmod(path, mode)
144 }
145 return nil
146 }
147}

Callers 1

remapRootFSFunction · 0.85

Calls 3

ToHostMethod · 0.80
SysMethod · 0.45
ModeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…