Skip to content

Commit b07314e

Browse files
author
Guillaume J. Charmes
committed
Remove import os/user
1 parent eed00a4 commit b07314e

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

utils/utils.go

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"net/http"
1515
"os"
1616
"os/exec"
17-
"os/user"
1817
"path/filepath"
1918
"runtime"
2019
"strconv"
@@ -802,7 +801,7 @@ func StripComments(input []byte, commentMarker []byte) []byte {
802801
var output []byte
803802
for _, currentLine := range lines {
804803
var commentIndex = bytes.Index(currentLine, commentMarker)
805-
if ( commentIndex == -1 ) {
804+
if commentIndex == -1 {
806805
output = append(output, currentLine...)
807806
} else {
808807
output = append(output, currentLine[:commentIndex]...)
@@ -867,18 +866,26 @@ func ParseRepositoryTag(repos string) (string, string) {
867866
return repos, ""
868867
}
869868

869+
type User struct {
870+
Uid string // user id
871+
Gid string // primary group id
872+
Username string
873+
Name string
874+
HomeDir string
875+
}
876+
870877
// UserLookup check if the given username or uid is present in /etc/passwd
871878
// and returns the user struct.
872879
// If the username is not found, an error is returned.
873-
func UserLookup(uid string) (*user.User, error) {
880+
func UserLookup(uid string) (*User, error) {
874881
file, err := ioutil.ReadFile("/etc/passwd")
875882
if err != nil {
876883
return nil, err
877884
}
878885
for _, line := range strings.Split(string(file), "\n") {
879886
data := strings.Split(line, ":")
880887
if len(data) > 5 && (data[0] == uid || data[2] == uid) {
881-
return &user.User{
888+
return &User{
882889
Uid: data[2],
883890
Gid: data[3],
884891
Username: data[0],
@@ -890,13 +897,13 @@ func UserLookup(uid string) (*user.User, error) {
890897
return nil, fmt.Errorf("User not found in /etc/passwd")
891898
}
892899

893-
type DependencyGraph struct{
900+
type DependencyGraph struct {
894901
nodes map[string]*DependencyNode
895902
}
896903

897-
type DependencyNode struct{
898-
id string
899-
deps map[*DependencyNode]bool
904+
type DependencyNode struct {
905+
id string
906+
deps map[*DependencyNode]bool
900907
}
901908

902909
func NewDependencyGraph() DependencyGraph {
@@ -917,7 +924,7 @@ func (graph *DependencyGraph) NewNode(id string) string {
917924
return id
918925
}
919926
nd := &DependencyNode{
920-
id: id,
927+
id: id,
921928
deps: map[*DependencyNode]bool{},
922929
}
923930
graph.addNode(nd)
@@ -979,7 +986,7 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
979986
// If at least one dep hasn't been processed yet, we can't
980987
// add it.
981988
ok := true
982-
for dep, _ := range node.deps {
989+
for dep := range node.deps {
983990
if !processed[dep] {
984991
ok = false
985992
break
@@ -991,7 +998,7 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
991998
}
992999
}
9931000
Debugf("Round %d: found %d available nodes", len(result), len(tmp_processed))
994-
// If no progress has been made this round,
1001+
// If no progress has been made this round,
9951002
// that means we have circular dependencies.
9961003
if len(tmp_processed) == 0 {
9971004
return nil, fmt.Errorf("Could not find a solution to this dependency graph")
@@ -1004,4 +1011,4 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
10041011
result = append(result, round)
10051012
}
10061013
return result, nil
1007-
}
1014+
}

0 commit comments

Comments
 (0)