Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quadlet - do not look for line continuation in comment lines #21556

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pkg/systemd/parser/unitfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,14 @@ func (f *UnitFile) Parse(data string) error {
var line string
line, data = nextLine(data, 0)

// Handle multi-line continuations
// Note: This doesn't support comments in the middle of the continuation, which systemd does
if lineIsKeyValuePair(line) {
for len(data) > 0 && line[len(line)-1] == '\\' {
line, data = nextLine(origdata, len(line)+1)
nLines++
if !lineIsComment(line) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about quadlet, so this may be a stupid question: why is this not:

    if lineIsComment(line) {
        next iteration
    }

Is there metadata in comments? Special handling of some sort? It makes me super uncomfortable to see in-loop handling of comments instead of just immediate discard.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. In its current behavior, Quadlet copies the comments from the input file into the generated .service file. For this reason it handles such lines and does not skip them.
Since I didn't want to change the behavior, I just made it disregard any possible line continuation character in comments

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The passing on of comments is nice, because they will then end up in the generated service file which can sometimes be shown by systemd.

// Handle multi-line continuations
// Note: This doesn't support comments in the middle of the continuation, which systemd does
if lineIsKeyValuePair(line) {
for len(data) > 0 && line[len(line)-1] == '\\' {
line, data = nextLine(origdata, len(line)+1)
nLines++
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/e2e/quadlet/comment-with-continuation.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## assert-podman-final-args localhost/imagename:latest
## assert-podman-args --publish 9091:9091
## assert-podman-args "--name=greatName"

[Unit]
Wants=network-online.target
After=network-online.target

# -e HOST_WHITELIST= `#optional` \

[Container]
# Image=localhost/otherimagename:latest
Image=localhost/imagename:latest
ContainerName=greatName
# HostName=my-hostname
Label=io.containers.autoupdate=registry
Environment=PUID=1000 PGID=100 SEED_RATIO=1.3 TZ=Europe/Prague
Volume=./.config:/config
Volume=./downloads:/downloads
# -v /path/to/watch/folder:/watch \
PublishPort=9091:9091
1 change: 1 addition & 0 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ BOGUS=foo
Entry("basepodman.container", "basepodman.container", 0, ""),
Entry("capabilities.container", "capabilities.container", 0, ""),
Entry("capabilities2.container", "capabilities2.container", 0, ""),
Entry("comment-with-continuation.container", "comment-with-continuation.container", 0, ""),
Entry("devices.container", "devices.container", 0, ""),
Entry("disableselinux.container", "disableselinux.container", 0, ""),
Entry("dns-options.container", "dns-options.container", 0, ""),
Expand Down
Loading