github.com/containers/podman/v4@v4.9.4/pkg/machine/machine_unix.go (about)

     1  //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
     2  // +build darwin dragonfly freebsd linux netbsd openbsd
     3  
     4  package machine
     5  
     6  import (
     7  	"errors"
     8  	"strings"
     9  )
    10  
    11  // ParseVolumeFromPath is a oneshot parsing of a provided volume.  It follows the "rules" of
    12  // the singular parsing functions
    13  func ParseVolumeFromPath(v string) (source, target, options string, readonly bool, err error) {
    14  	split := strings.SplitN(v, ":", 3)
    15  	switch len(split) {
    16  	case 1:
    17  		source = split[0]
    18  		target = split[0]
    19  	case 2:
    20  		source = split[0]
    21  		target = split[1]
    22  	case 3:
    23  		source = split[0]
    24  		target = split[1]
    25  		options = split[2]
    26  	default:
    27  		return "", "", "", false, errors.New("invalid volume provided")
    28  	}
    29  
    30  	// I suppose an option not intended for read-only could interfere here but I do not see a better way
    31  	if strings.Contains(options, "ro") {
    32  		readonly = true
    33  	}
    34  	return
    35  }