diff --git a/internal/restic/lock.go b/internal/restic/lock.go index 13a422e71..e27990aed 100644 --- a/internal/restic/lock.go +++ b/internal/restic/lock.go @@ -126,7 +126,7 @@ func (l *Lock) fillUserInfo() error { } l.Username = usr.Username - l.UID, l.GID, err = uidGidInt(*usr) + l.UID, l.GID, err = uidGidInt(usr) return err } diff --git a/internal/restic/lock_unix.go b/internal/restic/lock_unix.go index dbf23fc6c..c11bc4ca7 100644 --- a/internal/restic/lock_unix.go +++ b/internal/restic/lock_unix.go @@ -9,25 +9,21 @@ import ( "strconv" "syscall" - "github.com/restic/restic/internal/errors" - "github.com/restic/restic/internal/debug" + "github.com/restic/restic/internal/errors" ) // uidGidInt returns uid, gid of the user as a number. -func uidGidInt(u user.User) (uid, gid uint32, err error) { - var ui, gi int64 - ui, err = strconv.ParseInt(u.Uid, 10, 32) +func uidGidInt(u *user.User) (uid, gid uint32, err error) { + ui, err := strconv.ParseUint(u.Uid, 10, 32) if err != nil { - return uid, gid, errors.Wrap(err, "ParseInt") + return 0, 0, errors.Errorf("invalid UID %q", u.Uid) } - gi, err = strconv.ParseInt(u.Gid, 10, 32) + gi, err := strconv.ParseUint(u.Gid, 10, 32) if err != nil { - return uid, gid, errors.Wrap(err, "ParseInt") + return 0, 0, errors.Errorf("invalid GID %q", u.Gid) } - uid = uint32(ui) - gid = uint32(gi) - return + return uint32(ui), uint32(gi), nil } // checkProcess will check if the process retaining the lock diff --git a/internal/restic/lock_windows.go b/internal/restic/lock_windows.go index 5697b6efb..ee24e3bca 100644 --- a/internal/restic/lock_windows.go +++ b/internal/restic/lock_windows.go @@ -8,7 +8,7 @@ import ( ) // uidGidInt always returns 0 on Windows, since uid isn't numbers -func uidGidInt(u user.User) (uid, gid uint32, err error) { +func uidGidInt(u *user.User) (uid, gid uint32, err error) { return 0, 0, nil } diff --git a/internal/restic/snapshot.go b/internal/restic/snapshot.go index 9eb7ab3ab..7f8d4164b 100644 --- a/internal/restic/snapshot.go +++ b/internal/restic/snapshot.go @@ -154,7 +154,7 @@ func (sn *Snapshot) fillUserInfo() error { sn.Username = usr.Username // set userid and groupid - sn.UID, sn.GID, err = uidGidInt(*usr) + sn.UID, sn.GID, err = uidGidInt(usr) return err }