mirror of
https://github.com/restic/restic.git
synced 2026-07-02 05:24:17 +00:00
7015da44ad
Extract UidGidInt to simplify moving the locking code to the repository.
26 lines
561 B
Go
26 lines
561 B
Go
//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
|
|
}
|