Check for `.exe` case insensitively
On Windows `foo.exe`, `foo.eXe` and `foo.EXE` are equally executable.
package manager
import (
+ "path/filepath"
"strings"
"github.com/pkg/errors"
)
+// This is made slightly more complex due to needing to be case insensitive.
func trimExeSuffix(s string) (string, error) {
+ ext := filepath.Ext(s)
+ if ext == "" {
+ return "", errors.Errorf("path %q lacks required file extension", s)
+ }
+
exe := ".exe"
- if !strings.HasSuffix(s, exe) {
- return "", errors.Errorf("lacks required %q suffix", exe)
+ if !strings.EqualFold(ext, exe) {
+ return "", errors.Errorf("path %q lacks required %q suffix", s, exe)
}
- return strings.TrimSuffix(s, exe), nil
+ return strings.TrimSuffix(s, ext), nil
}
func addExeSuffix(s string) string {
