WriteGroupIdFile writes the given group ID to the group_id file inside the given postings directory.
(pdir string, group_id uint32)
| 143 | // WriteGroupIdFile writes the given group ID to the group_id file inside the given |
| 144 | // postings directory. |
| 145 | func WriteGroupIdFile(pdir string, group_id uint32) error { |
| 146 | if group_id == 0 { |
| 147 | return errors.Errorf("ID written to group_id file must be a positive number") |
| 148 | } |
| 149 | |
| 150 | groupFile := filepath.Join(pdir, GroupIdFileName) |
| 151 | f, err := os.OpenFile(groupFile, os.O_CREATE|os.O_WRONLY, 0600) |
| 152 | if err != nil { |
| 153 | return nil |
| 154 | } |
| 155 | if _, err := f.WriteString(strconv.Itoa(int(group_id))); err != nil { |
| 156 | return err |
| 157 | } |
| 158 | if _, err := f.WriteString("\n"); err != nil { |
| 159 | return err |
| 160 | } |
| 161 | return f.Close() |
| 162 | } |
| 163 | |
| 164 | // ReadGroupIdFile reads the file at the given path and attempts to retrieve the |
| 165 | // group ID stored in it. |
no test coverage detected