MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / copyMetadata

Function copyMetadata

pkg/init/cmd/init/init.go:22–39  ·  view source on GitHub ↗

pivot_root, which runc uses normally will not work on a ramfs or tmpfs root filesystem You can work around this by forcing it to use move, but it is more convenient to create a new tmpfs root without this issue. Try to do this using as little RAM as possible by moving files one by one. Equivalent to

(info os.FileInfo, path string)

Source from the content-addressed store, hash-verified

20
21// copies ownership and timestamps; assume you created with the right mode
22func copyMetadata(info os.FileInfo, path string) error {
23 // would rather use fd than path but Go makes this very difficult at present
24 stat := info.Sys().(*syscall.Stat_t)
25 if err := unix.Lchown(path, int(stat.Uid), int(stat.Gid)); err != nil {
26 return err
27 }
28 timespec := []unix.Timespec{unix.Timespec(stat.Atim), unix.Timespec(stat.Mtim)}
29 if err := unix.UtimesNanoAt(unix.AT_FDCWD, path, timespec, unix.AT_SYMLINK_NOFOLLOW); err != nil {
30 return err
31 }
32 // after chown suid bits may be dropped; re-set on non symlink files
33 if info.Mode()&os.ModeSymlink == 0 {
34 if err := os.Chmod(path, info.Mode()); err != nil {
35 return err
36 }
37 }
38 return nil
39}
40
41func copyFS(newRoot string) error {
42 // find the device of the root filesystem so we can avoid changing filesystem

Callers 1

copyFSFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected