Skip to content

Commit f41a5ef

Browse files
authored
Merge pull request #225 from thaJeztah/user_dry
user: make code a bit more DRY
2 parents 8d586cf + 61f382a commit f41a5ef

1 file changed

Lines changed: 4 additions & 25 deletions

File tree

user/user.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ func parseParts(parts [][]byte, v ...any) {
9797
}
9898

9999
func ParsePasswdFile(path string) ([]User, error) {
100-
passwd, err := os.Open(path)
101-
if err != nil {
102-
return nil, err
103-
}
104-
defer passwd.Close()
105-
return ParsePasswd(passwd)
100+
return ParsePasswdFileFilter(path, nil)
106101
}
107102

108103
func ParsePasswd(passwd io.Reader) ([]User, error) {
@@ -154,13 +149,7 @@ func ParsePasswdFilter(r io.Reader, filter func(User) bool) ([]User, error) {
154149
}
155150

156151
func ParseGroupFile(path string) ([]Group, error) {
157-
group, err := os.Open(path)
158-
if err != nil {
159-
return nil, err
160-
}
161-
162-
defer group.Close()
163-
return ParseGroup(group)
152+
return ParseGroupFileFilter(path, nil)
164153
}
165154

166155
func ParseGroup(group io.Reader) ([]Group, error) {
@@ -498,12 +487,7 @@ func GetAdditionalGroupsPath(additionalGroups []string, groupPath string) ([]int
498487
}
499488

500489
func ParseSubIDFile(path string) ([]SubID, error) {
501-
subid, err := os.Open(path)
502-
if err != nil {
503-
return nil, err
504-
}
505-
defer subid.Close()
506-
return ParseSubID(subid)
490+
return ParseSubIDFileFilter(path, nil)
507491
}
508492

509493
func ParseSubID(subid io.Reader) ([]SubID, error) {
@@ -551,12 +535,7 @@ func ParseSubIDFilter(r io.Reader, filter func(SubID) bool) ([]SubID, error) {
551535
}
552536

553537
func ParseIDMapFile(path string) ([]IDMap, error) {
554-
r, err := os.Open(path)
555-
if err != nil {
556-
return nil, err
557-
}
558-
defer r.Close()
559-
return ParseIDMap(r)
538+
return ParseIDMapFileFilter(path, nil)
560539
}
561540

562541
func ParseIDMap(r io.Reader) ([]IDMap, error) {

0 commit comments

Comments
 (0)