OLD | NEW |
1 // Copyright 2013 Canonical Ltd. | 1 // Copyright 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package tools | 4 package tools |
5 | 5 |
6 import ( | 6 import ( |
7 "errors" | 7 "errors" |
8 "strings" | 8 "strings" |
9 | 9 |
10 "launchpad.net/juju-core/environs/storage" | 10 "launchpad.net/juju-core/environs/storage" |
(...skipping 29 matching lines...) Expand all Loading... |
40 } | 40 } |
41 var list coretools.List | 41 var list coretools.List |
42 var foundAnyTools bool | 42 var foundAnyTools bool |
43 for _, name := range names { | 43 for _, name := range names { |
44 if !strings.HasPrefix(name, toolPrefix) || !strings.HasSuffix(na
me, toolSuffix) { | 44 if !strings.HasPrefix(name, toolPrefix) || !strings.HasSuffix(na
me, toolSuffix) { |
45 continue | 45 continue |
46 } | 46 } |
47 var t coretools.Tools | 47 var t coretools.Tools |
48 vers := name[len(toolPrefix) : len(name)-len(toolSuffix)] | 48 vers := name[len(toolPrefix) : len(name)-len(toolSuffix)] |
49 if t.Version, err = version.ParseBinary(vers); err != nil { | 49 if t.Version, err = version.ParseBinary(vers); err != nil { |
| 50 logger.Debugf("failed to parse version %q: %v", vers, er
r) |
50 continue | 51 continue |
51 } | 52 } |
52 foundAnyTools = true | 53 foundAnyTools = true |
53 // Major version must match specified value. | 54 // Major version must match specified value. |
54 if t.Version.Major != majorVersion { | 55 if t.Version.Major != majorVersion { |
55 continue | 56 continue |
56 } | 57 } |
57 // If specified minor version value supplied, minor version must
match. | 58 // If specified minor version value supplied, minor version must
match. |
58 if minorVersion >= 0 && t.Version.Minor != minorVersion { | 59 if minorVersion >= 0 && t.Version.Minor != minorVersion { |
59 continue | 60 continue |
60 } | 61 } |
61 logger.Debugf("found %s", vers) | 62 logger.Debugf("found %s", vers) |
62 if t.URL, err = stor.URL(name); err != nil { | 63 if t.URL, err = stor.URL(name); err != nil { |
63 return nil, err | 64 return nil, err |
64 } | 65 } |
65 list = append(list, &t) | 66 list = append(list, &t) |
66 } | 67 } |
67 if len(list) == 0 { | 68 if len(list) == 0 { |
68 if foundAnyTools { | 69 if foundAnyTools { |
69 return nil, coretools.ErrNoMatches | 70 return nil, coretools.ErrNoMatches |
70 } | 71 } |
71 return nil, ErrNoTools | 72 return nil, ErrNoTools |
72 } | 73 } |
73 return list, nil | 74 return list, nil |
74 } | 75 } |
OLD | NEW |