mirror of
https://github.com/containers/podman.git
synced 2025-05-22 01:27:07 +08:00

When committing containers to create new images, accept a container config blob being passed in the body of the API request by adding a Config field to our API structures. Populate it from the body of requests that we receive, and use its contents as the body of requests that we make. Make the libpod commit endpoint split changes values at newlines, just like the compat endpoint does. Pass both the config blob and the "changes" slice to buildah's Commit() API, so that it can handle cases where they overlap or conflict. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// DecodeChanges reads one or more changes from a slice and cleans them up,
|
|
// since what we've advertised as being acceptable in the past isn't really.
|
|
func DecodeChanges(changes []string) []string {
|
|
result := make([]string, 0, len(changes))
|
|
for _, possiblyMultilineChange := range changes {
|
|
for _, change := range strings.Split(possiblyMultilineChange, "\n") {
|
|
// In particular, we document that we accept values
|
|
// like "CMD=/bin/sh", which is not valid Dockerfile
|
|
// syntax, so we can't just pass such a value directly
|
|
// to a parser that's going to rightfully reject it.
|
|
// If we trim the string of whitespace at both ends,
|
|
// and the first occurrence of "=" is before the first
|
|
// whitespace, replace that "=" with whitespace.
|
|
change = strings.TrimSpace(change)
|
|
if change == "" {
|
|
continue
|
|
}
|
|
firstEqualIndex := strings.Index(change, "=")
|
|
firstSpaceIndex := strings.IndexFunc(change, unicode.IsSpace)
|
|
if firstEqualIndex != -1 && (firstSpaceIndex == -1 || firstEqualIndex < firstSpaceIndex) {
|
|
change = change[:firstEqualIndex] + " " + change[firstEqualIndex+1:]
|
|
}
|
|
result = append(result, change)
|
|
}
|
|
}
|
|
return result
|
|
}
|