fix: testing for flag files on windows (#1249)

* fix: testing for flag files on windows
* fix build script on windows/msys
This commit is contained in:
nils måsén 2022-04-18 19:38:19 +02:00 committed by GitHub
parent 2f4d58776d
commit 56368a7207
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View file

@ -1,6 +1,7 @@
package flags
import (
"errors"
"io/ioutil"
"os"
"strings"
@ -468,9 +469,13 @@ func getSecretFromFile(flags *pflag.FlagSet, secret string) {
}
func isFile(s string) bool {
_, err := os.Stat(s)
if os.IsNotExist(err) {
firstColon := strings.IndexRune(s, ':')
if firstColon != 1 && firstColon != -1 {
// If the string contains a ':', but it's not the second character, it's probably not a file
// and will cause a fatal error on windows if stat'ed
// This still allows for paths that start with 'c:\' etc.
return false
}
return true
_, err := os.Stat(s)
return !errors.Is(err, os.ErrNotExist)
}