Skip to content

Commit b374462

Browse files
committed
Make parseAPTConfigLine public
We already have a way to go from a repository to a line, via `Repository.APTConfigLine`. There is a valid usecase to have the reverse, go from a line to a Repository: for instance some software will expect such a line as input/output (Ansible's apt_repository's repo for instance). Given that it's unlikely that the implementation of it will see breaking changes, I don't see any reason to keep it private.
1 parent 0d7233b commit b374462

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

repos.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (r *Repository) APTConfigLine() string {
107107

108108
var aptConfigLineRegexp = regexp.MustCompile(`^(# )?(deb|deb-src)(?: \[(.*)\])? ([^ ]+) ([^ ]+) ([^#\n]+)(?: +# *(.*))?$`)
109109

110-
func parseAPTConfigLine(line string) *Repository {
110+
func ParseAPTConfigLine(line string) *Repository {
111111
match := aptConfigLineRegexp.FindAllStringSubmatch(line, -1)
112112
if len(match) == 0 || len(match[0]) < 6 {
113113
return nil
@@ -134,7 +134,7 @@ func parseAPTConfigFile(configPath string) (RepositoryList, error) {
134134
res := RepositoryList{}
135135
for scanner.Scan() {
136136
line := scanner.Text()
137-
repo := parseAPTConfigLine(line)
137+
repo := ParseAPTConfigLine(line)
138138
if repo != nil {
139139
repo.configFile = configPath
140140
res = append(res, repo)
@@ -185,9 +185,9 @@ func AddRepository(repo *Repository, configFolderPath string) error {
185185

186186
// Add to the "managed.list" file
187187
managedPath := filepath.Join(configFolderPath, "sources.list.d", "managed.list")
188-
f, err := os.OpenFile(managedPath, os.O_APPEND|os.O_WRONLY, 0644)
188+
f, err := os.OpenFile(managedPath, os.O_APPEND|os.O_WRONLY, 0o644)
189189
if os.IsNotExist(err) {
190-
f, err = os.OpenFile(managedPath, os.O_CREATE|os.O_WRONLY, 0644)
190+
f, err = os.OpenFile(managedPath, os.O_CREATE|os.O_WRONLY, 0o644)
191191
}
192192
if err != nil {
193193
return fmt.Errorf("opening %s: %s", managedPath, err)
@@ -226,7 +226,7 @@ func RemoveRepository(repo *Repository, configFolderPath string) error {
226226
newContent := ""
227227
for scanner.Scan() {
228228
line := scanner.Text()
229-
r := parseAPTConfigLine(line)
229+
r := ParseAPTConfigLine(line)
230230
if r != nil && r.Equals(repo) {
231231
// Filter repo configs that match the repo to be removed
232232
continue
@@ -269,7 +269,7 @@ func EditRepository(old *Repository, newRepo *Repository, configFolderPath strin
269269
newContent := ""
270270
for scanner.Scan() {
271271
line := scanner.Text()
272-
r := parseAPTConfigLine(line)
272+
r := ParseAPTConfigLine(line)
273273
if r.Equals(old) {
274274
// Write the new config to replace the old one
275275
newContent += newRepo.APTConfigLine() + "\n"
@@ -291,7 +291,7 @@ func replaceFile(path string, newContent []byte) error {
291291
backupPath := path + ".save"
292292

293293
// Create the new version of the file
294-
err := os.WriteFile(newPath, newContent, 0600)
294+
err := os.WriteFile(newPath, newContent, 0o600)
295295
if err != nil {
296296
return fmt.Errorf("creating replacement file for %s: %s", newPath, err)
297297
}

0 commit comments

Comments
 (0)