Skip to content

Commit

Permalink
fixup! users/localentries: Use more go-style errors handling for errno
Browse files Browse the repository at this point in the history
  • Loading branch information
3v1n0 committed Jan 16, 2025
1 parent 58cc388 commit b664389
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions internal/users/localentries/getgrent_c.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ func GetGroupByName(name string) (Group, error) {
cGroup := C.getgrnam(C.CString(name))
if cGroup == nil {
err := errno.Get()
if errors.Is(err, errno.ErrNoEnt) || errors.Is(err, errno.ErrSrch) ||
errors.Is(err, errno.ErrBadf) || errors.Is(err, errno.ErrPerm) {
if err == nil ||
errors.Is(err, errno.ErrNoEnt) ||
errors.Is(err, errno.ErrSrch) ||
errors.Is(err, errno.ErrBadf) ||
errors.Is(err, errno.ErrPerm) {
return Group{}, ErrGroupNotFound
}
return Group{}, fmt.Errorf("getgrnam: %v", err)
Expand Down
7 changes: 5 additions & 2 deletions internal/users/localentries/getpwent_c.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ func GetPasswdByName(name string) (Passwd, error) {
cPasswd := C.getpwnam(C.CString(name))
if cPasswd == nil {
err := errno.Get()
if errors.Is(err, errno.ErrNoEnt) || errors.Is(err, errno.ErrSrch) ||
errors.Is(err, errno.ErrBadf) || errors.Is(err, errno.ErrPerm) {
if err == nil ||
errors.Is(err, errno.ErrNoEnt) ||
errors.Is(err, errno.ErrSrch) ||
errors.Is(err, errno.ErrBadf) ||
errors.Is(err, errno.ErrPerm) {
return Passwd{}, ErrUserNotFound
}
return Passwd{}, fmt.Errorf("getpwnam: %v", err)
Expand Down

0 comments on commit b664389

Please sign in to comment.