diff --git a/internal/restic/lock_unix.go b/internal/restic/lock_unix.go index ca1c74df2..71f43fd36 100644 --- a/internal/restic/lock_unix.go +++ b/internal/restic/lock_unix.go @@ -4,29 +4,11 @@ package restic import ( "os" - "os/user" - "strconv" "syscall" "github.com/restic/restic/internal/debug" - "github.com/restic/restic/internal/errors" ) -// UidGidInt returns uid, gid of the user as a number. -// -//nolint:revive // capitalization is correct as is -func UidGidInt(u *user.User) (uid, gid uint32, err error) { - ui, err := strconv.ParseUint(u.Uid, 10, 32) - if err != nil { - return 0, 0, errors.Errorf("invalid UID %q", u.Uid) - } - gi, err := strconv.ParseUint(u.Gid, 10, 32) - if err != nil { - return 0, 0, errors.Errorf("invalid GID %q", u.Gid) - } - return uint32(ui), uint32(gi), nil -} - // checkProcess will check if the process retaining the lock // exists and responds to SIGHUP signal. // Returns true if the process exists and responds. diff --git a/internal/restic/lock_windows.go b/internal/restic/lock_windows.go index 3cd7c3517..442b08397 100644 --- a/internal/restic/lock_windows.go +++ b/internal/restic/lock_windows.go @@ -2,16 +2,10 @@ package restic import ( "os" - "os/user" "github.com/restic/restic/internal/debug" ) -// UidGidInt always returns 0 on Windows, since uid isn't numbers -func UidGidInt(_ *user.User) (uid, gid uint32, err error) { - return 0, 0, nil -} - // checkProcess will check if the process retaining the lock exists. // Returns true if the process exists. func (l *Lock) processExists() bool { diff --git a/internal/restic/uid_unix.go b/internal/restic/uid_unix.go new file mode 100644 index 000000000..4072562ef --- /dev/null +++ b/internal/restic/uid_unix.go @@ -0,0 +1,25 @@ +//go:build !windows + +package restic + +import ( + "os/user" + "strconv" + + "github.com/restic/restic/internal/errors" +) + +// UidGidInt returns uid, gid of the user as a number. +// +//nolint:revive // capitalization is correct as is +func UidGidInt(u *user.User) (uid, gid uint32, err error) { + ui, err := strconv.ParseUint(u.Uid, 10, 32) + if err != nil { + return 0, 0, errors.Errorf("invalid UID %q", u.Uid) + } + gi, err := strconv.ParseUint(u.Gid, 10, 32) + if err != nil { + return 0, 0, errors.Errorf("invalid GID %q", u.Gid) + } + return uint32(ui), uint32(gi), nil +} diff --git a/internal/restic/uid_windows.go b/internal/restic/uid_windows.go new file mode 100644 index 000000000..320092614 --- /dev/null +++ b/internal/restic/uid_windows.go @@ -0,0 +1,10 @@ +package restic + +import ( + "os/user" +) + +// UidGidInt always returns 0 on Windows, since uid isn't numbers +func UidGidInt(_ *user.User) (uid, gid uint32, err error) { + return 0, 0, nil +}