2019-01-14 12:53:19 -05:00
|
|
|
package manager
|
|
|
|
|
|
|
|
import (
|
2019-01-28 12:50:05 -05:00
|
|
|
"path/filepath"
|
2019-01-14 12:53:19 -05:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2019-01-28 12:50:05 -05:00
|
|
|
// This is made slightly more complex due to needing to be case insensitive.
|
2019-01-14 12:53:19 -05:00
|
|
|
func trimExeSuffix(s string) (string, error) {
|
2019-01-28 12:50:05 -05:00
|
|
|
ext := filepath.Ext(s)
|
|
|
|
if ext == "" {
|
|
|
|
return "", errors.Errorf("path %q lacks required file extension", s)
|
|
|
|
}
|
|
|
|
|
2019-01-14 12:53:19 -05:00
|
|
|
exe := ".exe"
|
2019-01-28 12:50:05 -05:00
|
|
|
if !strings.EqualFold(ext, exe) {
|
|
|
|
return "", errors.Errorf("path %q lacks required %q suffix", s, exe)
|
2019-01-14 12:53:19 -05:00
|
|
|
}
|
2019-01-28 12:50:05 -05:00
|
|
|
return strings.TrimSuffix(s, ext), nil
|
2019-01-14 12:53:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func addExeSuffix(s string) string {
|
|
|
|
return s + ".exe"
|
|
|
|
}
|