mirror of
https://github.com/restic/restic.git
synced 2026-06-17 22:24:17 +00:00
restic: extract UidGidInt into separate files
Extract UidGidInt to simplify moving the locking code to the repository.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user