github.com/criteo/command-launcher@v0.0.0-20230407142452-fb616f546e98/internal/helper/paths.go (about)

     1  package helper
     2  
     3  import (
     4  	"path"
     5  	"regexp"
     6  	"runtime"
     7  	"strings"
     8  )
     9  
    10  // Check if the path is an absolute path
    11  //
    12  // The standard go function does not support Windows :(
    13  func IsAbsolutePath(pathname string) bool {
    14  	// Path package does not support correctly windows
    15  	abs := path.IsAbs(strings.ReplaceAll(pathname, "\\", "/"))
    16  	if !abs && len(pathname) > 2 && runtime.GOOS == "windows" {
    17  		abs, _ = regexp.Match("[[:alpha:]]", []byte{pathname[0]})
    18  		abs = abs && pathname[1] == ':'
    19  	}
    20  
    21  	return abs
    22  }