ReadGroupIdFile reads the file at the given path and attempts to retrieve the group ID stored in it.
(pdir string)
| 164 | // ReadGroupIdFile reads the file at the given path and attempts to retrieve the |
| 165 | // group ID stored in it. |
| 166 | func ReadGroupIdFile(pdir string) (uint32, error) { |
| 167 | path := filepath.Join(pdir, GroupIdFileName) |
| 168 | info, err := os.Stat(path) |
| 169 | if os.IsNotExist(err) { |
| 170 | return 0, nil |
| 171 | } |
| 172 | if info.IsDir() { |
| 173 | return 0, errors.Errorf("Group ID file at %s is a directory", path) |
| 174 | } |
| 175 | |
| 176 | contents, err := os.ReadFile(path) |
| 177 | if err != nil { |
| 178 | return 0, err |
| 179 | } |
| 180 | |
| 181 | groupId, err := strconv.ParseUint(strings.TrimSpace(string(contents)), 0, 32) |
| 182 | if err != nil { |
| 183 | return 0, err |
| 184 | } |
| 185 | return uint32(groupId), nil |
| 186 | } |