Merge pull request #1822 from dotcloud/remove_os_user

Remove os user
This commit is contained in:
Guillaume J. Charmes 2013-09-06 16:30:54 -07:00
commit c8f885a4d0
1 changed files with 19 additions and 12 deletions

View File

@ -14,7 +14,6 @@ import (
"net/http"
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"
"strconv"
@ -802,7 +801,7 @@ func StripComments(input []byte, commentMarker []byte) []byte {
var output []byte
for _, currentLine := range lines {
var commentIndex = bytes.Index(currentLine, commentMarker)
if ( commentIndex == -1 ) {
if commentIndex == -1 {
output = append(output, currentLine...)
} else {
output = append(output, currentLine[:commentIndex]...)
@ -867,10 +866,18 @@ func ParseRepositoryTag(repos string) (string, string) {
return repos, ""
}
type User struct {
Uid string // user id
Gid string // primary group id
Username string
Name string
HomeDir string
}
// UserLookup check if the given username or uid is present in /etc/passwd
// and returns the user struct.
// If the username is not found, an error is returned.
func UserLookup(uid string) (*user.User, error) {
func UserLookup(uid string) (*User, error) {
file, err := ioutil.ReadFile("/etc/passwd")
if err != nil {
return nil, err
@ -878,7 +885,7 @@ func UserLookup(uid string) (*user.User, error) {
for _, line := range strings.Split(string(file), "\n") {
data := strings.Split(line, ":")
if len(data) > 5 && (data[0] == uid || data[2] == uid) {
return &user.User{
return &User{
Uid: data[2],
Gid: data[3],
Username: data[0],
@ -979,7 +986,7 @@ func (graph *DependencyGraph) GenerateTraversalMap() ([][]string, error) {
// If at least one dep hasn't been processed yet, we can't
// add it.
ok := true
for dep, _ := range node.deps {
for dep := range node.deps {
if !processed[dep] {
ok = false
break