-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quadlet container mount - support non key=val options
Some keys, e.g. ro do not have values. The current implementation crashed looking for the = sign Externalize findMountType in a new package Parse mount command using FindMountType Rebuild parameter string using csv Add test case and adjust the test framework Signed-off-by: Ygal Blum <[email protected]>
- Loading branch information
Showing
5 changed files
with
133 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package specgenutilexternal | ||
|
||
import ( | ||
"encoding/csv" | ||
"errors" | ||
"strings" | ||
) | ||
|
||
var ( | ||
errInvalidSyntax = errors.New("incorrect mount format: should be --mount type=<bind|glob|tmpfs|volume>,[src=<host-dir|volume-name>,]target=<ctr-dir>[,options]") | ||
) | ||
|
||
// FindMountType parses the input and extracts the type of the mount type and | ||
// the remaining non-type tokens. | ||
func FindMountType(input string) (mountType string, tokens []string, err error) { | ||
// Split by comma, iterate over the slice and look for | ||
// "type=$mountType". Everything else is appended to tokens. | ||
found := false | ||
csvReader := csv.NewReader(strings.NewReader(input)) | ||
records, err := csvReader.ReadAll() | ||
if err != nil { | ||
return "", nil, err | ||
} | ||
if len(records) != 1 { | ||
return "", nil, errInvalidSyntax | ||
} | ||
for _, s := range records[0] { | ||
kv := strings.Split(s, "=") | ||
if found || !(len(kv) == 2 && kv[0] == "type") { | ||
tokens = append(tokens, s) | ||
continue | ||
} | ||
mountType = kv[1] | ||
found = true | ||
} | ||
if !found { | ||
err = errInvalidSyntax | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters