(name string, group bool)
| 31 | } |
| 32 | |
| 33 | func lookupUserAndGroup(name string, group bool) (string, string, error) { |
| 34 | // Look up either the the user or the group, returning the other kind as |
| 35 | // blank. This might seem an odd maneuver, but it matches what Chown |
| 36 | // wants as input and hides the ugly nested if:s down here. |
| 37 | |
| 38 | if group { |
| 39 | gr, err := lookupWithoutDomain(name, func(name string) (string, error) { |
| 40 | gr, err := user.LookupGroup(name) |
| 41 | if err == nil { |
| 42 | return gr.Gid, nil |
| 43 | } |
| 44 | return "", err |
| 45 | }) |
| 46 | if err != nil { |
| 47 | return "", "", fmt.Errorf("lookup group %v: %w", name, err) |
| 48 | } |
| 49 | return "", gr, nil |
| 50 | } |
| 51 | |
| 52 | us, err := lookupWithoutDomain(name, func(name string) (string, error) { |
| 53 | us, err := user.Lookup(name) |
| 54 | if err == nil { |
| 55 | return us.Uid, nil |
| 56 | } |
| 57 | return "", err |
| 58 | }) |
| 59 | if err != nil { |
| 60 | return "", "", fmt.Errorf("lookup user %v: %w", name, err) |
| 61 | } |
| 62 | return us, "", nil |
| 63 | } |
| 64 | |
| 65 | func lookupWithoutDomain(name string, lookup func(s string) (string, error)) (string, error) { |
| 66 | // Try to look up the user by name. The username will be either a plain |
no test coverage detected