From nobody@FreeBSD.org  Mon Jun  4 08:24:55 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id B6F7E106568B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  4 Jun 2012 08:24:55 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id A12698FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Mon,  4 Jun 2012 08:24:55 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q548OtLB021737
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 4 Jun 2012 08:24:55 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q548OtiC021731;
	Mon, 4 Jun 2012 08:24:55 GMT
	(envelope-from nobody)
Message-Id: <201206040824.q548OtiC021731@red.freebsd.org>
Date: Mon, 4 Jun 2012 08:24:55 GMT
From: Mitsuru Y <mitsuruy@reallyenglish.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: patches for sysutils/rubygem-chef
X-Send-Pr-Version: www-3.1
X-GNATS-Notify: renchap@cocoa-x.com

>Number:         168656
>Category:       ports
>Synopsis:       patches for sysutils/rubygem-chef
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    swills
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 04 08:30:12 UTC 2012
>Closed-Date:    Wed Apr 16 13:48:31 UTC 2014
>Last-Modified:  Wed Apr 16 13:48:31 UTC 2014
>Originator:     Mitsuru Y
>Release:        8.2-RELEASE
>Organization:
Really English Broadband
>Environment:
8.2-RELEASE
>Description:
patches for sysutils/rubygem-chef include

- install man pages
- fix implanted path "/etc"
- new package provider using pkg_upgrade in sysutils/bsdadminscripts
  and OPTION to use it as the default package provider
- use pidfile defined in the configfile
- fix a bug in locking pidfile which allows multiple chef-clients run
- Chef::Handler::ErrorReport is disabled: CHEF-2694
- use "onestatus" instead of "status"

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

diff -ruN rubygem-chef.old/Makefile rubygem-chef/Makefile
--- rubygem-chef.old/Makefile	2012-05-08 15:22:40.000000000 +0900
+++ rubygem-chef/Makefile	2012-05-10 12:35:47.000000000 +0900
@@ -7,7 +7,7 @@
 
 PORTNAME=	chef
 PORTVERSION=	0.10.8
-PORTREVISION=	1
+PORTREVISION=	2
 CATEGORIES=	sysutils
 MASTER_SITES=	RG
 
@@ -34,6 +34,7 @@
 USE_RUBYGEMS=		yes
 USE_RUBY_FEATURES=	iconv
 RUBYGEM_AUTOPLIST=	yes
+REINPLACE_ARGS=		-i ""
 
 PLIST_FILES=	bin/chef-client \
 		bin/chef-solo \
@@ -43,4 +44,52 @@
 SUB_LIST=	RUBY=${RUBY}
 USE_RC_SUBR=	chef_client
 
+MAN1=	knife-configure.1 knife-cookbook-site.1 knife-status.1 \
+	knife-search.1 knife-bootstrap.1 knife-index.1 knife-client.1 \
+	knife-ssh.1 knife-node.1 shef.1 knife.1 knife-data-bag.1 \
+	knife-environment.1 knife-tag.1 knife-exec.1 knife-role.1 \
+	knife-cookbook.1
+MAN8=	chef-solr.8 chef-server-webui.8 chef-expander.8 chef-server.8 \
+	chef-solo.8 chef-expanderctl.8 chef-client.8
+
+OPTIONS=	PKGUPGRADE "Use pkgupgrade as a default package provider" Off
+OPTIONSFILE=	${PORT_DBDIR}/rubygem-${PORTNAME}/options
+
+.include <bsd.port.options.mk>
+
+.if defined(WITH_PKGUPGRADE)
+RUN_DEPENDS+=	bsdadminscripts>0:${PORTSDIR}/sysutils/bsdadminscripts
+.endif
+
+post-install:
+	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-daemon.rb.patch
+	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-provider-service-freebsd.rb.patch
+.if defined(WITH_PKGUPGRADE)
+	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-provider-package-pkgupgrade.rb.patch
+	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-providers.rb.patch
+	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-resources.rb.patch
+	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-resource-pkgupgrade_package.rb.patch
+	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-platform.patch
+.endif
+	@${PATCH} -p0 -d ${PREFIX}/${GEM_LIB_DIR} < ${PATCHDIR}/lib-chef-handler-error_report.patch
+	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/application/solo.rb
+	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/application/client.rb
+	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/encrypted_data_bag_item.rb
+	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/shef.rb
+	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/config.rb
+	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/knife/core/ui.rb
+	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/knife/core/bootstrap_context.rb
+	@${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' ${PREFIX}/${GEM_LIB_DIR}/lib/chef/knife/configure.rb
+	@${FIND} ${PREFIX}/${GEM_LIB_DIR}/distro/common -type f -exec ${REINPLACE_CMD} -e 's@/etc@${PREFIX}/etc@' {} \;
+	@${FIND} ${PREFIX}/${GEM_LIB_DIR} -name "*.orig" -delete
+.if !defined(NO_INSTALL_MANPAGES)
+.for n in 1 8
+.for f in ${MAN${n}}
+	${CP} ${PREFIX}/${GEM_LIB_DIR}/distro/common/man/man${n}/${f} ${PREFIX}/man/man${n}
+	${CHMOD} ${MANMODE} ${PREFIX}/man/man${n}/${f}
+	${CHOWN} ${MANOWN}:${MANGRP} ${PREFIX}/man/man${n}/${f}
+.endfor
+.endfor
+.endif
+
 .include <bsd.port.mk>
diff -ruN rubygem-chef.old/files/chef_client.in rubygem-chef/files/chef_client.in
--- rubygem-chef.old/files/chef_client.in	2012-05-08 15:22:40.000000000 +0900
+++ rubygem-chef/files/chef_client.in	2012-05-10 17:14:31.000000000 +0900
@@ -25,6 +25,12 @@
 : ${chef_client_splay="0"}
 : ${chef_client_logfile="/var/log/chef-client.log"}
 : ${chef_client_loglevel="info"}
+if [ -f "$chef_client_configfile" ]
+	then
+		pidfile=`awk '/^[ \t]*pid_file[ \t]+/ { print $2 }' ${chef_clien
+t_configfile}`
+fi
+: ${chef_client_pidfile=$pidfile}
 : ${chef_client_pidfile="/var/run/chef-client.pid"}
 
 if [ -n "$chef_client_nodename" ]
diff -ruN rubygem-chef.old/files/lib-chef-daemon.rb.patch rubygem-chef/files/lib-chef-daemon.rb.patch
--- rubygem-chef.old/files/lib-chef-daemon.rb.patch	1970-01-01 09:00:00.000000000 +0900
+++ rubygem-chef/files/lib-chef-daemon.rb.patch	2012-05-10 12:36:46.000000000 +0900
@@ -0,0 +1,102 @@
+--- lib/chef/daemon.rb.dist	2012-04-27 16:37:08.000000000 +0900
++++ lib/chef/daemon.rb	2012-05-08 14:31:26.000000000 +0900
+@@ -32,26 +32,24 @@
+       #
+       def daemonize(name)
+         @name = name
+-        pid = pid_from_file
+-        unless running?
+-          remove_pid_file()
+-          Chef::Log.info("Daemonizing..")
+-          begin
+-            exit if fork
+-            Process.setsid
+-            exit if fork
+-            Chef::Log.info("Forked, in #{Process.pid}. Priveleges: #{Process.euid} #{Process.egid}")
+-            File.umask Chef::Config[:umask]
+-            $stdin.reopen("/dev/null")
+-            $stdout.reopen("/dev/null", "a")
+-            $stderr.reopen($stdout)
+-            save_pid_file
+-            at_exit { remove_pid_file }
+-          rescue NotImplementedError => e
+-            Chef::Application.fatal!("There is no fork: #{e.message}")
++        Chef::Log.info("Daemonizing..")
++        begin
++          exit if fork
++          Process.setsid
++          exit if fork
++          Chef::Log.info("Forked, in #{Process.pid}. Priveleges: #{Process.euid} #{Process.egid}")
++          File.umask Chef::Config[:umask]
++          $stdin.reopen("/dev/null")
++          $stdout.reopen("/dev/null", "a")
++          $stderr.reopen($stdout)
++          read_pid_file
++          if running?
++            Chef::Application.fatal!("Chef(#{$0}) is already running pid #{@pid}")
+           end
+-        else
+-          Chef::Application.fatal!("Chef is already running pid #{pid}")
++          save_pid_file
++          at_exit { remove_pid_file }
++        rescue NotImplementedError => e
++          Chef::Application.fatal!("There is no fork: #{e.message}")
+         end
+       end
+   
+@@ -62,16 +60,14 @@
+       # False if Chef is not running
+       #
+       def running?
+-        if pid_from_file.nil?
++        if @pid.nil?
+           false
+         else
+-          Process.kill(0, pid_from_file)
++          Process.kill(0, @pid)
+           true
+         end
+       rescue Errno::ESRCH, Errno::ENOENT
+         false
+-      rescue Errno::EACCES => e
+-        Chef::Application.fatal!("You don't have access to the PID file at #{pid_file}: #{e.message}")
+       end
+       
+       # Gets the pid file for @name
+@@ -89,10 +85,19 @@
+       # nil::
+       #   Returned if the pid_file does not exist.
+       #
+-      def pid_from_file
+-        File.read(pid_file).chomp.to_i
+-      rescue Errno::ENOENT, Errno::EACCES
+-        nil
++      def read_pid_file
++        @fh = File.open(pid_file, File::RDWR|File::CREAT, 0644)
++        @fh.flock(File::LOCK_EX | File::LOCK_NB) || Chef::Application.fatal!("Couldn't lock pidfile #{pid_file}")
++        pid = @fh.read.chomp
++        if pid =~ /^\d+/
++          @pid = pid.to_i
++        else
++          @pid = nil
++        end        
++      rescue Errno::EACCES => e
++        Chef::Application.fatal!("You don't have access to the PID file at #{pid_file}: #{e.message}")
++      rescue Errno::ENOENT
++        @pid = nil
+       end
+     
+       # Store the PID on the filesystem
+@@ -107,7 +112,11 @@
+         end
+       
+         begin
+-          File.open(file, "w") { |f| f.write(Process.pid.to_s) }
++          @fh.rewind
++          @fh.write("#{Process.pid.to_s}\n")
++          @fh.flush
++          @fh.truncate(@fh.pos)
++          @fh.close
+         rescue Errno::EACCES => e
+           Chef::Application.fatal!("Couldn't write to pidfile #{file}, permission denied: #{e.message}")
+         end
diff -ruN rubygem-chef.old/files/lib-chef-handler-error_report.patch rubygem-chef/files/lib-chef-handler-error_report.patch
--- rubygem-chef.old/files/lib-chef-handler-error_report.patch	1970-01-01 09:00:00.000000000 +0900
+++ rubygem-chef/files/lib-chef-handler-error_report.patch	2012-03-29 17:03:30.000000000 +0900
@@ -0,0 +1,16 @@
+diff --git a/chef/lib/chef/handler/error_report.rb b/chef/lib/chef/handler/error_report.rb
+index dc47ed5..d1ed412 100644
+--- lib/chef/handler/error_report.rb
++++ lib/chef/handler/error_report.rb
+@@ -24,8 +24,9 @@ class Chef
+     class ErrorReport < ::Chef::Handler
+ 
+       def report
+-        Chef::FileCache.store("failed-run-data.json", Chef::JSONCompat.to_json_pretty(data))
+-        Chef::Log.fatal("Saving node information to #{Chef::FileCache.load("failed-run-data.json", false)}")
++        # Chef::FileCache.store("failed-run-data.json", Chef::JSONCompat.to_json_pretty(data))
++        # Chef::Log.fatal("Saving node information to #{Chef::FileCache.load("failed-run-data.json", false)}")
++        Chef::Log.info("Chef::Handler::ErrorReport is disabled: CHEF-2694")
+       end
+ 
+     end
diff -ruN rubygem-chef.old/files/lib-chef-platform.patch rubygem-chef/files/lib-chef-platform.patch
--- rubygem-chef.old/files/lib-chef-platform.patch	1970-01-01 09:00:00.000000000 +0900
+++ rubygem-chef/files/lib-chef-platform.patch	2012-01-23 07:28:40.000000000 +0900
@@ -0,0 +1,11 @@
+--- lib/chef/platform.rb.orig	2010-11-02 15:48:57.000000000 +0900
++++ lib/chef/platform.rb	2010-11-02 15:49:12.000000000 +0900
+@@ -50,7 +50,7 @@
+           :freebsd => {
+             :default => {
+               :group   => Chef::Provider::Group::Pw,
+-              :package => Chef::Provider::Package::Freebsd,
++              :package => Chef::Provider::Package::PkgUpgrade,
+               :service => Chef::Provider::Service::Freebsd,
+               :user    => Chef::Provider::User::Pw,
+               :cron    => Chef::Provider::Cron
diff -ruN rubygem-chef.old/files/lib-chef-provider-package-pkgupgrade.rb.patch rubygem-chef/files/lib-chef-provider-package-pkgupgrade.rb.patch
--- rubygem-chef.old/files/lib-chef-provider-package-pkgupgrade.rb.patch	1970-01-01 09:00:00.000000000 +0900
+++ rubygem-chef/files/lib-chef-provider-package-pkgupgrade.rb.patch	2012-01-23 07:28:40.000000000 +0900
@@ -0,0 +1,402 @@
+--- /dev/null	2011-11-21 16:48:43.000000000 +0900
++++ lib/chef/provider/package/pkgupgrade.rb	2011-11-21 16:04:09.951953315 +0900
+@@ -0,0 +1,399 @@
++#
++# Author:: Mitsuru Y (<mitsuruy@reallyenglish.com>)
++# Copyright:: Copyright (c) 2011 Real English Broadband
++# License:: Apache License, Version 2.0
++#
++# Licensed under the Apache License, Version 2.0 (the "License");
++# you may not use this file except in compliance with the License.
++# You may obtain a copy of the License at
++#
++#     http://www.apache.org/licenses/LICENSE-2.0
++#
++# Unless required by applicable law or agreed to in writing, software
++# distributed under the License is distributed on an "AS IS" BASIS,
++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++# See the License for the specific language governing permissions and
++# limitations under the License.
++#
++
++require 'chef/provider/package'
++require 'chef/mixin/command'
++require 'chef/resource/package'
++require 'singleton'
++require 'chef/mixin/get_source_from_package'
++
++class Hash
++  def safe_invert
++    result = Hash.new{|h,key| h[key] = [] }
++    self.each{|key, value|
++      result[value] << key
++    }
++    result
++  end
++end
++
++class Chef
++  class Provider
++    class Package
++      class PkgUpgrade < Chef::Provider::Package
++
++        # Cache for our installed and available packages
++
++        class PkgCache
++          include Chef::Mixin::Command
++          include Singleton
++
++          def initialize
++            @pkg_index = Hash.new
++            @pkg_index[:name] = Hash.new
++            @pkg_index[:version] = Hash.new
++            @pkg_index[:origin] = Hash.new
++            @pkg_pkgdb = Hash.new
++            @pkg_pkgdb[:name] = Hash.new
++            @pkg_pkgdb[:version] = Hash.new
++
++# Next time @pkgdb is accessed:
++#  :all       - Trigger updates pkg's cache - this data is slow to gather.
++#  :installed - Trigger updates only the local pkg db.
++#               Used between client runs for a quick refresh.
++#  :none      - Do nothing, a call to one of the reload methods is required.
++            @next_refresh = :all
++
++
++            # these are for subsequent runs if we are on an interval
++            Chef::Client.when_run_starts do
++              PkgCache.instance.reload
++            end
++          end
++
++          # Cache management
++          #
++
++          def refresh
++            case @next_refresh
++            when :none
++              return nil
++            when :installed
++              reset_installed
++              # fast
++              refresh_pkgdb
++            when :all
++              reset
++              # medium
++              refresh_pkgdb
++              refresh_index 
++            else
++              raise ArgumentError, "Unexpected value in next_refresh: #{@next_refresh}"
++            end
++
++            # A reload method must be called before the cache is altered
++            @next_refresh = :none
++          end
++
++          def refresh_index
++            Chef::Log.debug("#{@new_resource} refresh index")
++            run_command_with_systems_locale(
++              :command => "uma fetch ftpindex"
++            )
++            indexfile = ""
++            status = popen4("uma env") do |pid, stdin, stdout, stderr|
++              stdout.each do |env_var|
++                env_var.chomp!
++                if env_var =~ /^PKG_INDEX='(.*)'/
++                  indexfile = $1
++                end
++              end
++            end
++            IO.foreach(indexfile) do |line|
++              indexline = line.split("|")
++              dir = indexline[0]
++              origin = indexline[1].sub(/^\/usr\/ports\//,'')
++              pkg_name = pkgversion(dir)
++              version = pkg_name[1]
++              if version
++                @pkg_index[:name][origin] = pkg_name[0]
++                @pkg_index[:version][origin] = pkg_name[1]
++              end
++            end
++            @pkg_index[:origin] = @pkg_index[:name].safe_invert
++          end
++        
++          def refresh_pkgdb
++            Chef::Log.debug("#{@new_resource} refresh pkgdb")
++            status = popen4("pkg_info -Ea") do |pid, stdin, stdout, stderr|
++              stdout.each do |pkgname|
++                pkgname.chomp!
++                pkg_name = pkgversion(pkgname)
++                version = pkg_name[1]
++                status = popen4("pkg_info -qo #{pkgname}") do |pid, stdin, stdout, stderr|
++                  stdout.each do |line|
++                    origin = line.chomp
++                    @pkg_pkgdb[:name][origin] = pkg_name[0]
++                    @pkg_pkgdb[:version][origin] = pkg_name[1]
++                  end
++                end
++              end
++            end
++          end
++        
++          def pkgversion(pkgname)
++            if /\s/ =~ pkgname
++              return nil
++        #    raise ArgumentError, "Must not contain whitespace."
++            end
++        
++            if /^(.+)-([^-]+)$/ !~ pkgname
++              return nil
++        #    raise ArgumentError, "Not in due form: <name>-<version>"
++            end
++            name = $1
++            version = splitversion($2)
++            return [name, version]
++          end
++        
++          def splitversion(pkgversion)
++            if /[\s-]/ =~ pkgversion    
++              return nil
++        #    raise ArgumentError, "#{pkgversion}: Must not contain a '-' or whitespace."
++            end
++        
++            if /^([^_,]+)(?:_(\d+))?(?:,(\d+))?$/ !~ pkgversion
++              return nil
++        #   raise ArgumentError, "#{pkgversion}: Not in due form: '<version>[_<revision>][,<epoch>]'."
++             end
++        
++             version = $1
++             revision = $2 ? $2.to_i : 0
++             epoch = $3 ? $3.to_i : 0
++
++             return pkgversion
++#             return [version, revision, epoch]
++          end
++
++          def reload
++            @next_refresh = :all
++          end
++
++          def reload_installed
++            @next_refresh = :installed
++          end
++
++          def reset
++            @pkg_index[:name].clear
++            @pkg_index[:version].clear
++            @pkg_index[:origin].clear
++            @pkg_pkgdb[:name].clear
++            @pkg_pkgdb[:version].clear
++          end
++
++          def reset_installed
++            @pkg_pkgdb[:name].clear
++            @pkg_pkgdb[:version].clear
++          end
++
++          # Querying the cache
++          #
++
++          def available_version(package_name)
++            refresh
++            origin = nil
++            if package_name =~ /\//
++              origin = package_name
++            else
++              origin = @pkg_pkgdb[:name].index(package_name)
++              unless origin  # not installed
++                origins = @pkg_index[:origin][package_name]
++                case origins.size
++                when 1
++                  origin = origins.first
++                when 0
++                  raise Chef::Exceptions::Package, "Package #{@new_resource} not found."
++                else
++                  origins.each do |o|
++                    if o =~ /^[^\/]*\/#{package_name}$/
++                      Chef::Log.warn("#{@new_resource} more than one match and use guessed origin. consider specifying origin. ")
++                      origin = o
++                      break
++                    end
++                  end
++                  unless origin
++                    raise Chef::Exceptions::Package, "Package #{@new_resource} matches multiple packages which origins are #{origins.join(' ')}."
++                  end
++                end
++              end
++            end
++            if origin
++              @pkg_index[:version][origin]
++            else
++              nil
++            end
++          end
++          alias :candidate_version :available_version
++
++          def installed_version(package_name)
++            refresh
++            if package_name =~ /\//
++              origin = package_name
++            else
++              origin = @pkg_pkgdb[:name].index(package_name)
++            end
++            if origin
++              @pkg_pkgdb[:version][origin]
++            else
++              nil
++            end
++          end
++
++        end # PkgCache
++
++        include Chef::Mixin::GetSourceFromPackage
++
++        def initialize(new_resource, run_context)
++          super
++
++          @pkg = PkgCache.instance
++        end
++
++        # Extra attributes
++        #
++
++        def flush_cache
++          if @new_resource.respond_to?("flush_cache")
++            @new_resource.flush_cache
++          else
++            { :before => false, :after => false }
++          end
++        end
++
++        def agree_license
++          if @new_resource.respond_to?("agree_license")
++            if @new_resource.agree_license
++              "yes | "
++            else
++              ""
++            end
++          else
++            ""
++          end
++        end
++
++        # Standard Provider methods for Parent
++        #
++
++        def load_current_resource
++          if flush_cache[:before]
++            @pkg.reload
++          end
++
++          @current_resource = Chef::Resource::Package.new(@new_resource.name)
++          @current_resource.package_name(@new_resource.package_name)
++
++          if @new_resource.source
++            case @new_resource.source
++            when /^\//
++              unless ::File.exists?(@new_resource.source)
++                raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
++              end
++            end
++
++#            Chef::Log.debug("#{@new_resource} checking rpm status")
++#            status = popen4("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}") do |pid, stdin, stdout, stderr|
++#              stdout.each do |line|
++#                case line
++#                when /([\w\d_.-]+)\s([\w\d_.-]+)/
++#                  @current_resource.package_name($1)
++#                  @new_resource.version($2)
++#                end
++#              end
++#            end
++          end
++
++          if @new_resource.version
++            new_resource = "#{@new_resource.package_name}-#{@new_resource.version}"
++          else
++            new_resource = "#{@new_resource.package_name}"
++          end
++
++          Chef::Log.debug("#{@new_resource} checking package info for #{new_resource}")
++
++          installed_version = @pkg.installed_version(@new_resource.package_name)
++          @current_resource.version(installed_version)
++
++          @candidate_version = @pkg.candidate_version(@new_resource.package_name)
++
++          Chef::Log.debug("#{@new_resource} installed version: #{installed_version || "(none)"} candidate version: " +
++                          "#{@candidate_version || "(none)"}")
++
++          @current_resource
++        end
++
++        def install_package(name, version)
++          if @new_resource.source && name =~ /^\//
++            run_command_with_systems_locale(
++              :command => "#{agree_license} pkg_add #{expand_options(@new_resource.options)} #{@new_resource.source}"
++            ) 
++          else
++            if name =~ /\//
++              run_command_with_systems_locale(
++                :command => "#{agree_license} pkg_upgrade --clean #{expand_options(@new_resource.options)} #{name}"
++              )
++            else
++              run_command_with_systems_locale(
++                :command => "#{agree_license} pkg_upgrade --clean #{expand_options(@new_resource.options)} #{name}-#{version}"
++              )
++            end
++          end
++          if flush_cache[:after]
++            @pkg.reload
++          else
++            @pkg.reload_installed
++          end
++        end
++
++        # Keep upgrades from trying to install an older candidate version. Can happen when a new
++        # version is installed then removed from a repository, now the older available version
++        # shows up as a viable install candidate.
++        #
++        # Can be done in upgrade_package but an upgraded from->to log message slips out
++        #
++        # Hacky - better overall solution? Custom compare in Package provider?
++#        def action_upgrade
++          # Ensure the candidate is newer
++#          if RPMVersion.parse(candidate_version) > RPMVersion.parse(@current_resource.version)
++#            super
++          # Candidate is older
++#          else
++#            Chef::Log.debug("#{@new_resource} is at the latest version - nothing to do")
++#          end
++#        end
++
++        def upgrade_package(name, version)
++          install_package(name, version)
++        end
++
++        def remove_package(name, version)
++          if version
++            run_command_with_systems_locale(
++             :command => "pkg_delete #{expand_options(@new_resource.options)} #{name}-#{version}"
++            )
++          else
++            run_command_with_systems_locale(
++             :command => "pkg_delete #{expand_options(@new_resource.options)} #{name}-#{@current_resource.version}"
++            )
++          end
++          if flush_cache[:after]
++            @pkg.reload
++          else
++            @pkg.reload_installed
++          end
++        end
++
++        def purge_package(name, version)
++          remove_package(name, version)
++        end
++
++
++      end
++    end
++  end
++end
diff -ruN rubygem-chef.old/files/lib-chef-provider-service-freebsd.rb.patch rubygem-chef/files/lib-chef-provider-service-freebsd.rb.patch
--- rubygem-chef.old/files/lib-chef-provider-service-freebsd.rb.patch	1970-01-01 09:00:00.000000000 +0900
+++ rubygem-chef/files/lib-chef-provider-service-freebsd.rb.patch	2012-01-23 07:28:40.000000000 +0900
@@ -0,0 +1,13 @@
+diff --git a/chef/lib/chef/provider/service/freebsd.rb b/chef/lib/chef/provider/service/freebsd.rb
+index 209f1ca..ab72382 100644
+--- lib/chef/provider/service/freebsd.rb
++++ lib/chef/provider/service/freebsd.rb
+@@ -42,7 +42,7 @@ class Chef
+             Chef::Log.debug("#{@new_resource} supports status, checking state")
+ 
+             begin
+-              if run_command(:command => "#{@init_command} status") == 0
++              if run_command(:command => "#{@init_command} onestatus") == 0
+                 @current_resource.running true
+               end
+             rescue Chef::Exceptions::Exec
diff -ruN rubygem-chef.old/files/lib-chef-providers.rb.patch rubygem-chef/files/lib-chef-providers.rb.patch
--- rubygem-chef.old/files/lib-chef-providers.rb.patch	1970-01-01 09:00:00.000000000 +0900
+++ rubygem-chef/files/lib-chef-providers.rb.patch	2012-01-23 07:28:40.000000000 +0900
@@ -0,0 +1,10 @@
+--- lib/chef/providers.rb.org	2011-11-21 17:43:12.194699060 +0900
++++ lib/chef/providers.rb	2011-11-21 15:56:58.023058089 +0900
+@@ -54,6 +54,7 @@
+ require 'chef/provider/package/freebsd'
+ require 'chef/provider/package/macports'
+ require 'chef/provider/package/pacman'
++require 'chef/provider/package/pkgupgrade'
+ require 'chef/provider/package/portage'
+ require 'chef/provider/package/rpm'
+ require 'chef/provider/package/rubygems'
diff -ruN rubygem-chef.old/files/lib-chef-resource-pkgupgrade_package.rb.patch rubygem-chef/files/lib-chef-resource-pkgupgrade_package.rb.patch
--- rubygem-chef.old/files/lib-chef-resource-pkgupgrade_package.rb.patch	1970-01-01 09:00:00.000000000 +0900
+++ rubygem-chef/files/lib-chef-resource-pkgupgrade_package.rb.patch	2012-01-23 07:28:40.000000000 +0900
@@ -0,0 +1,57 @@
+--- /dev/null	2011-11-21 16:47:43.000000000 +0900
++++ lib/chef/resource/pkgupgrade_package.rb	2011-11-21 15:59:15.255820421 +0900
+@@ -0,0 +1,54 @@
++#
++# Author:: Mitsuru Y (<mitsuruy@reallyenglish.com>)
++# Copyright:: Copyright (c) 2011 Real English Broadband, Inc.
++# License:: Apache License, Version 2.0
++#
++# Licensed under the Apache License, Version 2.0 (the "License");
++# you may not use this file except in compliance with the License.
++# You may obtain a copy of the License at
++# 
++#     http://www.apache.org/licenses/LICENSE-2.0
++# 
++# Unless required by applicable law or agreed to in writing, software
++# distributed under the License is distributed on an "AS IS" BASIS,
++# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++# See the License for the specific language governing permissions and
++# limitations under the License.
++#
++
++require 'chef/resource/package'
++require 'chef/provider/package/pkgupgrade'
++
++class Chef
++  class Resource
++    class PkgupgradePackage < Chef::Resource::Package
++
++      def initialize(name, run_context=nil)
++        super
++        @resource_name = :pkgupgrade_package
++        @provider = Chef::Provider::Package::PkgUpgrade
++        @flush_cache = { :before => false, :after => false }
++        @allow_downgrade = false
++      end
++
++      def flush_cache(args={})
++        if args.is_a? Array
++          args.each { |arg| @flush_cache[arg] = true }
++        elsif args.any?
++          @flush_cache = args
++        else
++          @flush_cache
++        end
++      end
++
++      def agree_license(arg=nil)
++        set_or_return(
++          :allow_downgrade,
++          arg,
++          :kind_of => [ TrueClass, FalseClass ]
++        )
++      end
++
++    end
++  end
++end
diff -ruN rubygem-chef.old/files/lib-chef-resources.rb.patch rubygem-chef/files/lib-chef-resources.rb.patch
--- rubygem-chef.old/files/lib-chef-resources.rb.patch	1970-01-01 09:00:00.000000000 +0900
+++ rubygem-chef/files/lib-chef-resources.rb.patch	2012-01-23 07:28:40.000000000 +0900
@@ -0,0 +1,10 @@
+--- lib/chef/resources.rb.org	2011-11-21 16:54:27.103624659 +0900
++++ lib/chef/resources.rb	2011-11-21 15:57:49.055841192 +0900
+@@ -46,6 +46,7 @@
+ require 'chef/resource/package'
+ require 'chef/resource/pacman_package'
+ require 'chef/resource/perl'
++require 'chef/resource/pkgupgrade_package'
+ require 'chef/resource/portage_package'
+ require 'chef/resource/python'
+ require 'chef/resource/remote_directory'


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->ruby 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Jun 4 12:44:29 UTC 2012 
Responsible-Changed-Why:  
ruby@ wants this port PRs (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=168656 
State-Changed-From-To: open->feedback 
State-Changed-By: edwin 
State-Changed-When: Mon Jun 4 12:44:32 UTC 2012 
State-Changed-Why:  
Awaiting maintainers feedback (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=168656 

From: Edwin Groothuis <edwin@FreeBSD.org>
To: renchap@cocoa-x.com
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/168656: patches for sysutils/rubygem-chef
Date: Mon, 4 Jun 2012 12:44:31 UT

 Maintainer of sysutils/rubygem-chef,
 
 Please note that PR ports/168656 has just been submitted.
 
 If it contains a patch for an upgrade, an enhancement or a bug fix
 you agree on, reply to this email stating that you approve the patch
 and a committer will take care of it.
 
 The full text of the PR can be found at:
     http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/168656
 
 -- 
 Edwin Groothuis via the GNATS Auto Assign Tool
 edwin@FreeBSD.org
Responsible-Changed-From-To: ruby->swills 
Responsible-Changed-By: swills 
Responsible-Changed-When: Tue Jun 5 20:02:56 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=168656 

From: Renaud Chaput <renchap@cocoa-x.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/168656: patches for sysutils/rubygem-chef
Date: Fri, 8 Jun 2012 21:05:06 +0200

 Hi Mitsuru,
 
 Thanks for your PR.
 Did you created and submitted your patches upstream ? I would prefer
 them to be in the Chef source code, to avoid maintening them in the
 port tree, and handling their evolution at each new Chef version.
 
 Here is the procedure :
 http://wiki.opscode.com/display/chef/How+to+Contribute
 
 A quick reviews of your changes :
 > install man pages
 Thanks for this one, it is welcomed to the port.
 
 > fix implanted path "/etc"
 I agree that we should fix this, but I am not sure your way is the best
 way on the long term. I will speak with Chef devs to check if they have
 a better idea (maybe allow both paths, if they exists ?)
 
 > new package provider using pkg_upgrade in sysutils/bsdadminscripts
 > and OPTION to use it as the default package provider
 Your pkg_upgrade provider is a good idea, and I am sure it will be
 welcomed upstream
 
 > use pidfile defined in the configfile
 Will fix it on the port ASAP
 
 > fix a bug in locking pidfile which allows multiple chef-clients run
 You should send your patch upstream, should be integrated quickly
 
 > Chef::Handler::ErrorReport is disabled: CHEF-2694
 I dont want to change the behaviour from upstream for all users of the
 port, because some people might use the failed-run-data.json. IMO this
 should also be fixed upstream
 
 > use "onestatus" instead of "status"
 Nice catch. But you should submit a patch upstream for this one too.
 
 If you dont want/dont have time to submit your patches, mail me and I
 will at least do it for the critical bugs, if you want.
 
 Regards,
 
 Renaud
 
 Le Mon, 4 Jun 2012 12:44:31 UT,
 Edwin Groothuis <edwin@FreeBSD.org> a =C3=A9crit :
 
 > Maintainer of sysutils/rubygem-chef,
 >=20
 > Please note that PR ports/168656 has just been submitted.
 >=20
 > If it contains a patch for an upgrade, an enhancement or a bug fix
 > you agree on, reply to this email stating that you approve the patch
 > and a committer will take care of it.
 >=20
 > The full text of the PR can be found at:
 >     http://www.freebsd.org/cgi/query-pr.cgi?pr=3Dports/168656
 >=20

From: Mitsuru Yoshida <mitsuruy@reallyenglish.com>
To: bug-followup@FreeBSD.org, Renaud Chaput <renchap@cocoa-x.com>
Cc:  
Subject: Re: ports/168656: patches for sysutils/rubygem-chef
Date: Tue, 19 Jun 2012 18:04:58 +0900

 Hi Renaud,
 
 >> new package provider using pkg_upgrade in sysutils/bsdadminscripts
 >> and OPTION to use it as the default package provider
 > Your pkg_upgrade provider is a good idea, and I am sure it will be
 > welcomed upstream
 It has already been sent for months. see CHEF-2810.
 
 >> fix a bug in locking pidfile which allows multiple chef-clients run
 > You should send your patch upstream, should be integrated quickly
 >
 >> use "onestatus" instead of "status"
 > Nice catch. But you should submit a patch upstream for this one too.
 I have sent patches. see CHEF-3209 and CHEF-3211.
 I also found a new bug in provider/service/freebsd.rb. see CHEF-3210.
 
 >> Chef::Handler::ErrorReport is disabled: CHEF-2694
 > I dont want to change the behaviour from upstream for all users of the
 > port, because some people might use the failed-run-data.json. IMO this
 > should also be fixed upstream
 It may not suitable to be a global solution. I maintain it in our local repo.
 
 Regards,
 
 -- 
 --Mitsuru
Responsible-Changed-From-To: swills->jgh 
Responsible-Changed-By: jgh 
Responsible-Changed-When: Mon Jan 14 05:28:08 UTC 2013 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=168656 

http://www.freebsd.org/cgi/query-pr.cgi?pr=168656 
State-Changed-From-To: closed->open 
State-Changed-By: jgh 
State-Changed-When: Wed Jan 22 00:42:41 UTC 2014 
State-Changed-Why:  
closed in error 

http://www.freebsd.org/cgi/query-pr.cgi?pr=168656 
Responsible-Changed-From-To: jgh->swills 
Responsible-Changed-By: swills 
Responsible-Changed-When: Wed Mar 12 13:46:39 UTC 2014 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=168656 
State-Changed-From-To: open->closed 
State-Changed-By: swills 
State-Changed-When: Wed Apr 16 13:48:30 UTC 2014 
State-Changed-Why:  
Closing, all the issues in this PR have been resolved by later updates, 
I think. Please let me know if I'm mistaken. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=168656 
>Unformatted:
