Skip to content

Commit e71cd3d

Browse files
committed
Fix options rendering in APTConfigLine breaking its output
Without that added space, the line generated is actually invalid. Take for instance Docker's apt repository: parsing its apt config line `deb [signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian bookworm stable` will yield a well-formed repository. However, re-generating the line with APTConfigLine from that Repository will yield `deb [signed-by=/etc/apt/keyrings/docker.asc]https://download.docker.com/linux/debian bookworm stable` (note the missing space). This will result in errors such as: ``` Error: Malformed entry 1 in list file /etc/apt/sources.list.d/stable.list ([option] not assignment) Error: The list of sources could not be read. ```
1 parent 0d7233b commit e71cd3d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

repos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (r *Repository) APTConfigLine() string {
9696
res += "deb "
9797
}
9898
if strings.TrimSpace(r.Options) != "" {
99-
res += "[" + r.Options + "]"
99+
res += "[" + r.Options + "] "
100100
}
101101
res += r.URI + " " + r.Distribution + " " + r.Components
102102
if strings.TrimSpace(r.Comment) != "" {

repos_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,25 @@ func TestAddAndRemoveRepository(t *testing.T) {
123123
require.False(t, repos.Contains(repo1), "Configuration contains: %#v", repo1)
124124
require.True(t, repos.Contains(repo2), "Configuration contains: %#v", repo2)
125125
}
126+
127+
func TestAPTConfigLine(t *testing.T) {
128+
r := &Repository{
129+
Enabled: true,
130+
SourceRepo: false,
131+
Options: "signed-by=/etc/apt/keyrings/docker.asc",
132+
URI: "https://download.docker.com/linux/debian",
133+
Distribution: "bookworm",
134+
Components: "stable",
135+
Comment: "Docker's Apt repository.",
136+
}
137+
138+
got := r.APTConfigLine()
139+
expected := "deb [signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian bookworm stable # Docker's Apt repository."
140+
require.True(t, got == expected)
141+
142+
r.Enabled = false
143+
r.SourceRepo = true
144+
got = r.APTConfigLine()
145+
expected = "# deb-src [signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian bookworm stable # Docker's Apt repository."
146+
require.True(t, got == expected)
147+
}

0 commit comments

Comments
 (0)