2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-01 17:23:57 +00:00

Make restic.{lchown,mknod} regular functions

This way, they can be inlined and dead code can be removed on Windows.
Also fixed some comments.
This commit is contained in:
greatroar 2021-05-27 21:29:51 +02:00
parent d7322a5f36
commit 0666c4d244
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 { 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 // Like "cp -a" and "rsync -a" do, we only report lchown permission errors
// if we run as root. // 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) { if os.Geteuid() > 0 && os.IsPermission(err) {
debug.Log("not running as root, ignoring lchown permission error for %v: %v", debug.Log("not running as root, ignoring lchown permission error for %v: %v",
path, err) path, err)
@ -310,11 +308,11 @@ func (node Node) createSymlinkAt(path string) error {
} }
func (node *Node) createDevAt(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 { 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 { 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 return nil
} }
func (node Node) device() int {
return int(node.Device)
}
// AIX has a funny timespec type in syscall, with 32-bit nanoseconds. // 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 // 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(). // 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 return nil
} }
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atimespec } func (s statT) atim() syscall.Timespec { return s.Atimespec }
func (s statT) mtim() syscall.Timespec { return s.Mtimespec } func (s statT) mtim() syscall.Timespec { return s.Mtimespec }
func (s statT) ctim() syscall.Timespec { return s.Ctimespec } 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 return nil
} }
func (node Node) device() uint64 { func mknod(path string, mode uint32, dev uint64) (err error) {
return node.Device return syscall.Mknod(path, mode, dev)
} }
func (s statT) atim() syscall.Timespec { return s.Atimespec } 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() return dir.Close()
} }
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atim } func (s statT) atim() syscall.Timespec { return s.Atim }
func (s statT) mtim() syscall.Timespec { return s.Mtim } func (s statT) mtim() syscall.Timespec { return s.Mtim }
func (s statT) ctim() syscall.Timespec { return s.Ctim } 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 return nil
} }
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atimespec } func (s statT) atim() syscall.Timespec { return s.Atimespec }
func (s statT) mtim() syscall.Timespec { return s.Mtimespec } func (s statT) mtim() syscall.Timespec { return s.Mtimespec }
func (s statT) ctim() syscall.Timespec { return s.Ctimespec } 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 return nil
} }
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atim } func (s statT) atim() syscall.Timespec { return s.Atim }
func (s statT) mtim() syscall.Timespec { return s.Mtim } func (s statT) mtim() syscall.Timespec { return s.Mtim }
func (s statT) ctim() syscall.Timespec { return s.Ctim } 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 return nil
} }
func (node Node) device() int {
return int(node.Device)
}
func (s statT) atim() syscall.Timespec { return s.Atim } func (s statT) atim() syscall.Timespec { return s.Atim }
func (s statT) mtim() syscall.Timespec { return s.Mtim } func (s statT) mtim() syscall.Timespec { return s.Mtim }
func (s statT) ctim() syscall.Timespec { return s.Ctim } func (s statT) ctim() syscall.Timespec { return s.Ctim }

View File

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

View File

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