github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/url/parse_local.go (about) 1 package url 2 3 import ( 4 "fmt" 5 6 "github.com/mutagen-io/mutagen/pkg/filesystem" 7 "github.com/mutagen-io/mutagen/pkg/url/forwarding" 8 ) 9 10 // parseLocal parses a local URL. It simply assumes the URL refers to a local 11 // path or forwarding endpoint specification. 12 func parseLocal(raw string, kind Kind) (*URL, error) { 13 // If this is a synchronization URL, then ensure that its path is 14 // normalized. 15 if kind == Kind_Synchronization { 16 if normalized, err := filesystem.Normalize(raw); err != nil { 17 return nil, fmt.Errorf("unable to normalize path: %w", err) 18 } else { 19 raw = normalized 20 } 21 } 22 23 // If this is a forwarding URL, then parse it to ensure that it's valid. If 24 // it's a Unix domain socket endpoint, then ensure that the socket path is 25 // normalized. 26 if kind == Kind_Forwarding { 27 // Perform parsing. 28 protocol, address, err := forwarding.Parse(raw) 29 if err != nil { 30 return nil, fmt.Errorf("invalid forwarding endpoint URL: %w", err) 31 } 32 33 // Normalize and reformat the endpoint URL if necessary. 34 if protocol == "unix" { 35 if normalized, err := filesystem.Normalize(address); err != nil { 36 return nil, fmt.Errorf("unable to normalize socket path: %w", err) 37 } else { 38 raw = protocol + ":" + normalized 39 } 40 } 41 } 42 43 // Create the URL. 44 return &URL{ 45 Kind: kind, 46 Protocol: Protocol_Local, 47 Path: raw, 48 }, nil 49 }