util: refactor ProcessOptions into an internal function

this is needed to add tests for the function without accessing the
file system.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2024-03-21 11:17:36 +01:00
parent 49ab250cf9
commit 50d764b0e6

View File

@ -22,11 +22,17 @@ type defaultMountOptions struct {
nodev bool
}
type getDefaultMountOptionsFn func(path string) (defaultMountOptions, error)
// ProcessOptions parses the options for a bind or tmpfs mount and ensures that
// they are sensible and follow convention. The isTmpfs variable controls
// whether extra, tmpfs-specific options will be allowed.
// The sourcePath variable, if not empty, contains a bind mount source.
func ProcessOptions(options []string, isTmpfs bool, sourcePath string) ([]string, error) {
return processOptionsInternal(options, isTmpfs, sourcePath, getDefaultMountOptions)
}
func processOptionsInternal(options []string, isTmpfs bool, sourcePath string, getDefaultMountOptions getDefaultMountOptionsFn) ([]string, error) {
var (
foundWrite, foundSize, foundProp, foundMode, foundExec, foundSuid, foundDev, foundCopyUp, foundBind, foundZ, foundU, foundOverlay, foundIdmap, foundCopy, foundNoSwap, foundNoDereference bool
)