mirror of https://github.com/docker/cli.git
Check for `.exe` case insensitively
On Windows `foo.exe`, `foo.eXe` and `foo.EXE` are equally executable. Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
63f3ad181b
commit
1337895751
|
@ -1,17 +1,24 @@
|
||||||
package manager
|
package manager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// This is made slightly more complex due to needing to be case insensitive.
|
||||||
func trimExeSuffix(s string) (string, error) {
|
func trimExeSuffix(s string) (string, error) {
|
||||||
exe := ".exe"
|
ext := filepath.Ext(s)
|
||||||
if !strings.HasSuffix(s, exe) {
|
if ext == "" {
|
||||||
return "", errors.Errorf("lacks required %q suffix", exe)
|
return "", errors.Errorf("path %q lacks required file extension", s)
|
||||||
}
|
}
|
||||||
return strings.TrimSuffix(s, exe), nil
|
|
||||||
|
exe := ".exe"
|
||||||
|
if !strings.EqualFold(ext, exe) {
|
||||||
|
return "", errors.Errorf("path %q lacks required %q suffix", s, exe)
|
||||||
|
}
|
||||||
|
return strings.TrimSuffix(s, ext), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addExeSuffix(s string) string {
|
func addExeSuffix(s string) string {
|
||||||
|
|
Loading…
Reference in New Issue