mirror of
https://github.com/octoleo/restic.git
synced 2024-11-29 16:23:59 +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:
parent
d7322a5f36
commit
0666c4d244
9
internal/restic/mknod_unix.go
Normal file
9
internal/restic/mknod_unix.go
Normal 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))
|
||||||
|
}
|
@ -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 {
|
||||||
|
@ -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().
|
||||||
|
@ -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 }
|
||||||
|
@ -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 }
|
||||||
|
@ -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 }
|
||||||
|
@ -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 }
|
||||||
|
@ -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 }
|
||||||
|
@ -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 }
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user