MCPcopy Create free account
hub / github.com/docker/cli / copyFilePermissions

Function copyFilePermissions

cli/config/configfile/file_unix.go:12–35  ·  view source on GitHub ↗

copyFilePermissions copies file ownership and permissions from "src" to "dst", ignoring any error during the process.

(src, dst string)

Source from the content-addressed store, hash-verified

10// copyFilePermissions copies file ownership and permissions from "src" to "dst",
11// ignoring any error during the process.
12func copyFilePermissions(src, dst string) {
13 var (
14 mode os.FileMode = 0o600
15 uid, gid int
16 )
17
18 fi, err := os.Stat(src)
19 if err != nil {
20 return
21 }
22 if fi.Mode().IsRegular() {
23 mode = fi.Mode()
24 }
25 if err := os.Chmod(dst, mode); err != nil {
26 return
27 }
28
29 uid = int(fi.Sys().(*syscall.Stat_t).Uid)
30 gid = int(fi.Sys().(*syscall.Stat_t).Gid)
31
32 if uid > 0 && gid > 0 {
33 _ = os.Chown(dst, uid, gid)
34 }
35}

Callers 1

SaveMethod · 0.70

Calls 1

ModeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…