Merge pull request #3409 from greatroar/lchown-mknod

Make restic.{lchown,mknod} regular functions
This commit is contained in:
MichaelEischer 2021-06-12 18:22:38 +02:00 committed by GitHub
commit e8d20ea32c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 19 additions and 43 deletions

View file

@ -0,0 +1,9 @@
// +build !freebsd,!windows
package restic
import "golang.org/x/sys/unix"
func mknod(path string, mode uint32, dev uint64) (err error) {
return unix.Mknod(path, mode, int(dev))
}

View file

@ -188,8 +188,6 @@ func (node Node) restoreMetadata(path string) error {
if err := lchown(path, int(node.UID), int(node.GID)); err != nil {
// Like "cp -a" and "rsync -a" do, we only report lchown permission errors
// if we run as root.
// On Windows, Geteuid always returns -1, and we always report lchown
// permission errors.
if os.Geteuid() > 0 && os.IsPermission(err) {
debug.Log("not running as root, ignoring lchown permission error for %v: %v",
path, err)
@ -310,11 +308,11 @@ func (node Node) createSymlinkAt(path string) error {
}
func (node *Node) createDevAt(path string) error {
return mknod(path, syscall.S_IFBLK|0600, node.device())
return mknod(path, syscall.S_IFBLK|0600, node.Device)
}
func (node *Node) createCharDevAt(path string) error {
return mknod(path, syscall.S_IFCHR|0600, node.device())
return mknod(path, syscall.S_IFCHR|0600, node.Device)
}
func (node *Node) createFifoAt(path string) error {

View file

@ -8,10 +8,6 @@ func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespe
return nil
}
func (node Node) device() int {
return int(node.Device)
}
// AIX has a funny timespec type in syscall, with 32-bit nanoseconds.
// golang.org/x/sys/unix handles this cleanly, but we're stuck with syscall
// because os.Stat returns a syscall type in its os.FileInfo.Sys().

View file

@ -6,10 +6,6 @@ func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespe
return nil
}
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atimespec }
func (s statT) mtim() syscall.Timespec { return s.Mtimespec }
func (s statT) ctim() syscall.Timespec { return s.Ctimespec }

View file

@ -8,8 +8,8 @@ func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespe
return nil
}
func (node Node) device() uint64 {
return node.Device
func mknod(path string, mode uint32, dev uint64) (err error) {
return syscall.Mknod(path, mode, dev)
}
func (s statT) atim() syscall.Timespec { return s.Atimespec }

View file

@ -32,10 +32,6 @@ func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespe
return dir.Close()
}
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atim }
func (s statT) mtim() syscall.Timespec { return s.Mtim }
func (s statT) ctim() syscall.Timespec { return s.Ctim }

View file

@ -6,10 +6,6 @@ func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespe
return nil
}
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atimespec }
func (s statT) mtim() syscall.Timespec { return s.Mtimespec }
func (s statT) ctim() syscall.Timespec { return s.Ctimespec }

View file

@ -6,10 +6,6 @@ func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespe
return nil
}
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atim }
func (s statT) mtim() syscall.Timespec { return s.Mtim }
func (s statT) ctim() syscall.Timespec { return s.Ctim }

View file

@ -6,10 +6,6 @@ func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespe
return nil
}
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atim }
func (s statT) mtim() syscall.Timespec { return s.Mtim }
func (s statT) ctim() syscall.Timespec { return s.Ctim }

View file

@ -5,12 +5,11 @@ package restic
import (
"os"
"syscall"
"golang.org/x/sys/unix"
)
var mknod = unix.Mknod
var lchown = os.Lchown
func lchown(name string, uid, gid int) error {
return os.Lchown(name, uid, gid)
}
type statT syscall.Stat_t

View file

@ -6,15 +6,13 @@ import (
"github.com/restic/restic/internal/errors"
)
// mknod() creates a filesystem node (file, device
// special file, or named pipe) named pathname, with attributes
// specified by mode and dev.
var mknod = func(path string, mode uint32, dev int) (err error) {
// mknod is not supported on Windows.
func mknod(path string, mode uint32, dev uint64) (err error) {
return errors.New("device nodes cannot be created on windows")
}
// Windows doesn't need lchown
var lchown = func(path string, uid int, gid int) (err error) {
func lchown(path string, uid int, gid int) (err error) {
return nil
}
@ -22,10 +20,6 @@ func (node Node) restoreSymlinkTimestamps(path string, utimes [2]syscall.Timespe
return nil
}
func (node Node) device() int {
return int(node.Device)
}
// Getxattr retrieves extended attribute data associated with path.
func Getxattr(path, name string) ([]byte, error) {
return nil, nil