@@ -18,7 +18,6 @@ package differs
18
18
19
19
import (
20
20
"io/ioutil"
21
- "os"
22
21
"path/filepath"
23
22
"regexp"
24
23
"strings"
@@ -124,32 +123,21 @@ func addToMap(packages map[string]map[string]util.PackageInfo, pack string, path
124
123
125
124
func getPythonVersion (pathToLayer string ) ([]string , error ) {
126
125
matches := []string {}
126
+ pattern := regexp .MustCompile ("^python[0-9]+\\ .[0-9]+$" )
127
127
128
- // Debian based distros
129
- libPath := filepath .Join (pathToLayer , "usr/local/lib" )
130
- libContents , err := ioutil .ReadDir (libPath )
131
- if err != nil {
132
- logrus .Warnf ("Could not find /usr/local/lib to determine Python version, trying /usr/lib: %s" , err )
133
- libContents = []os.FileInfo {}
134
- }
135
-
136
- // Fedora, CentOS, RHEL, ...
137
- libPath = filepath .Join (pathToLayer , "usr/lib" )
138
- libContents2 , err2 := ioutil .ReadDir (libPath )
139
- if err2 != nil {
128
+ libPaths := []string {"usr/local/lib" , "usr/lib" }
129
+ for _ , lp := range libPaths {
130
+ libPath := filepath .Join (pathToLayer , lp )
131
+ libContents , err := ioutil .ReadDir (libPath )
140
132
if err != nil {
141
- logrus .Errorf ("Could not find /usr/lib nor /usr/local/lib to determine Python version: %s " , err2 )
142
- return matches , err
133
+ logrus .Debugf ("Could not find %s to determine Python version" , err )
134
+ continue
143
135
}
144
- logrus .Warnf ("Could not find /usr/lib to determine Python version, using /usr/local/lib: %s" , err2 )
145
- libContents2 = []os.FileInfo {}
146
- }
147
-
148
- for _ , file := range append (libContents , libContents2 ... ) {
149
- pattern := regexp .MustCompile ("^python[0-9]+\\ .[0-9]+$" )
150
- match := pattern .FindString (file .Name ())
151
- if match != "" {
152
- matches = append (matches , match )
136
+ for _ , file := range libContents {
137
+ match := pattern .FindString (file .Name ())
138
+ if match != "" {
139
+ matches = append (matches , match )
140
+ }
153
141
}
154
142
}
155
143
return matches , nil
0 commit comments