2017-09-29 06:32:26 -04:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package fsutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
|
2017-09-30 12:16:08 -04:00
|
|
|
"github.com/containerd/continuity/sysx"
|
2017-09-29 06:32:26 -04:00
|
|
|
"github.com/pkg/errors"
|
2018-10-05 05:05:42 -04:00
|
|
|
"github.com/tonistiigi/fsutil/types"
|
2017-09-29 06:32:26 -04:00
|
|
|
)
|
|
|
|
|
2018-10-05 05:05:42 -04:00
|
|
|
func rewriteMetadata(p string, stat *types.Stat) error {
|
2017-09-29 06:32:26 -04:00
|
|
|
for key, value := range stat.Xattrs {
|
|
|
|
sysx.Setxattr(p, key, value, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.Lchown(p, int(stat.Uid), int(stat.Gid)); err != nil {
|
2020-11-17 05:31:07 -05:00
|
|
|
return errors.WithStack(err)
|
2017-09-29 06:32:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if os.FileMode(stat.Mode)&os.ModeSymlink == 0 {
|
|
|
|
if err := os.Chmod(p, os.FileMode(stat.Mode)); err != nil {
|
2020-11-17 05:31:07 -05:00
|
|
|
return errors.WithStack(err)
|
2017-09-29 06:32:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := chtimes(p, stat.ModTime); err != nil {
|
2020-11-17 05:31:07 -05:00
|
|
|
return err
|
2017-09-29 06:32:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleTarTypeBlockCharFifo is an OS-specific helper function used by
|
|
|
|
// createTarFile to handle the following types of header: Block; Char; Fifo
|
2018-10-05 05:05:42 -04:00
|
|
|
func handleTarTypeBlockCharFifo(path string, stat *types.Stat) error {
|
2017-09-29 06:32:26 -04:00
|
|
|
mode := uint32(stat.Mode & 07777)
|
|
|
|
if os.FileMode(stat.Mode)&os.ModeCharDevice != 0 {
|
|
|
|
mode |= syscall.S_IFCHR
|
|
|
|
} else if os.FileMode(stat.Mode)&os.ModeNamedPipe != 0 {
|
|
|
|
mode |= syscall.S_IFIFO
|
|
|
|
} else {
|
|
|
|
mode |= syscall.S_IFBLK
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := syscall.Mknod(path, mode, int(mkdev(stat.Devmajor, stat.Devminor))); err != nil {
|
2020-11-17 05:31:07 -05:00
|
|
|
return errors.WithStack(err)
|
2017-09-29 06:32:26 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|