# File lib/puppet/provider/package/portupgrade.rb, line 106
106:     def latest
107:       Puppet.debug "portupgrade.latest() - Latest check called on #{@resource[:name]}"
108:       # search for latest version available, or return current version.
109:       # cmdline = "portversion -v <portorigin>", returns "<portname> <code> <stuff>"
110:       # or "** No matching package found: <portname>"
111:         cmdline = ["-v", @resource[:name]]
112: 
113:       begin
114:         output = portversion(*cmdline)
115:         rescue Puppet::ExecutionFailure
116:           raise Puppet::Error.new(output)
117:         end
118: 
119:         # Check: output format.
120:         if output =~ /^\S+-([^-\s]+)\s+(\S)\s+(.*)/
121:         #         $1 = installed version, $2 = comparison, $3 other data
122:         # latest installed
123:         installedversion = $1
124:         comparison = $2
125:         otherdata = $3
126: 
127:         # Only return a new version number when it's clear that there is a new version
128:         # all others return the current version so no unexpected 'upgrades' occur.      
129:         case comparison
130:         when "=", ">"
131:           Puppet.debug "portupgrade.latest() - Installed package is latest (#{installedversion})"
132:           return installedversion
133:             when "<"
134:             #         "portpkg-1.7_5  <  needs updating (port has 1.14)"
135:             # "portpkg-1.7_5  <  needs updating (port has 1.14) (=> 'newport/pkg')
136:             if otherdata =~ /\(port has (\S+)\)/
137:               newversion = $1
138:               Puppet.debug "portupgrade.latest() - Installed version needs updating to (#{newversion})"
139:               return newversion
140:                 else
141:                   Puppet.debug "portupgrade.latest() - Unable to determine new version from (#{otherdata})"
142:                   return installedversion
143:                 end
144:             when "?", "!", "#"
145:               Puppet.debug "portupgrade.latest() - Comparison Error reported from portversion (#{output})"
146:               return installedversion
147:             else
148:               Puppet.debug "portupgrade.latest() - Unknown code from portversion output (#{output})"
149:               return installedversion
150:             end
151: 
152:         else
153:         #         error: output not parsed correctly, error out with nil.
154:         # Seriously - this section should never be called in a perfect world.
155:         # as verification that the port is installed has already happened in query.
156:         if output =~ /^\*\* No matching package /
157:           raise Puppet::ExecutionFailure, "Could not find package #{@resource[:name]}"
158:             else
159:             #         Any other error (dump output to log)
160:             raise Puppet::ExecutionFailure, "Unexpected output from portversion: #{output}"
161:             end
162: 
163:             # Just in case we still are running, return nil
164:             return nil
165:         end
166: 
167:         # At this point normal operation has finished and we shouldn't have been called.
168:         # Error out and let the admin deal with it.
169:         raise Puppet::Error, "portversion.latest() - fatal error with portversion: #{output}"
170:         return nil
171: 
172:     end