class Chef::Provider::Subversion
Constants
- SVN_INFO_PATTERN
Public Instance Methods
checkout_command()
click to toggle source
# File lib/chef/provider/subversion.rb, line 104 def checkout_command c = scm :checkout, new_resource.svn_arguments, verbose, authentication, proxy, "-r#{revision_int}", new_resource.repository, new_resource.destination logger.info "#{new_resource} checked out #{new_resource.repository} at revision #{new_resource.revision} to #{new_resource.destination}" c end
current_revision_matches_target_revision?()
click to toggle source
# File lib/chef/provider/subversion.rb, line 145 def current_revision_matches_target_revision? (!current_resource.revision.nil?) && (revision_int.strip.to_i == current_resource.revision.strip.to_i) end
define_resource_requirements()
click to toggle source
# File lib/chef/provider/subversion.rb, line 46 def define_resource_requirements requirements.assert(:all_actions) do |a| # Make sure the parent dir exists, or else fail. # for why run, print a message explaining the potential error. parent_directory = ::File.dirname(new_resource.destination) a.assertion { ::TargetIO::File.directory?(parent_directory) } a.failure_message(Chef::Exceptions::MissingParentDirectory, "Cannot clone #{new_resource} to #{new_resource.destination}, the enclosing directory #{parent_directory} does not exist") a.whyrun("Directory #{parent_directory} does not exist, assuming it would have been created") end end
export_command()
click to toggle source
# File lib/chef/provider/subversion.rb, line 111 def export_command args = ["--force"] args << new_resource.svn_arguments << verbose << authentication << proxy << "-r#{revision_int}" << new_resource.repository << new_resource.destination c = scm :export, *args logger.info "#{new_resource} exported #{new_resource.repository} at revision #{new_resource.revision} to #{new_resource.destination}" c end
find_current_revision()
click to toggle source
# File lib/chef/provider/subversion.rb, line 136 def find_current_revision return nil unless ::TargetIO::File.exist?(::File.join(new_resource.destination, ".svn")) command = scm(:info) svn_info = shell_out!(command, **run_options(cwd: cwd, returns: [0, 1])).stdout extract_revision_info(svn_info) end
load_current_resource()
click to toggle source
# File lib/chef/provider/subversion.rb, line 36 def load_current_resource @current_resource = Chef::Resource::Subversion.new(new_resource.name) unless %i{export force_export}.include?(Array(new_resource.action).first) if current_revision = find_current_revision current_resource.revision current_revision end end end
revision_int()
click to toggle source
If the specified revision isn’t an integer (“HEAD” for example), look up the revision id by asking the server If the specified revision is an integer, trust it.
# File lib/chef/provider/subversion.rb, line 123 def revision_int @revision_int ||= if /^\d+$/.match?(new_resource.revision) new_resource.revision else command = scm(:info, new_resource.repository, new_resource.svn_info_args, authentication, "-r#{new_resource.revision}") svn_info = shell_out!(command, **run_options(cwd: cwd, returns: [0, 1])).stdout extract_revision_info(svn_info) end end
Also aliased as: revision_slug
run_options(run_opts = {})
click to toggle source
# File lib/chef/provider/subversion.rb, line 149 def run_options(run_opts = {}) env = {} if new_resource.user run_opts[:user] = new_resource.user env["HOME"] = get_homedir(new_resource.user) end run_opts[:group] = new_resource.group if new_resource.group run_opts[:timeout] = new_resource.timeout if new_resource.timeout env.merge!(new_resource.environment) if new_resource.environment run_opts[:environment] = env unless env.empty? run_opts end
sync_command()
click to toggle source
# File lib/chef/provider/subversion.rb, line 98 def sync_command c = scm :update, new_resource.svn_arguments, verbose, authentication, proxy, "-r#{revision_int}", new_resource.destination logger.trace "#{new_resource} updated working copy #{new_resource.destination} to revision #{new_resource.revision}" c end
Private Instance Methods
assert_target_directory_valid!()
click to toggle source
# File lib/chef/provider/subversion.rb, line 225 def assert_target_directory_valid! target_parent_directory = ::File.dirname(new_resource.destination) unless ::TargetIO::File.directory?(target_parent_directory) msg = "Cannot clone #{new_resource} to #{new_resource.destination}, the enclosing directory #{target_parent_directory} does not exist" raise Chef::Exceptions::MissingParentDirectory, msg end end
authentication()
click to toggle source
If a username is configured for the SCM, return the command-line switches for that. Note that we don’t need to return the password switch, since Capistrano will check for that prompt in the output and will respond appropriately.
# File lib/chef/provider/subversion.rb, line 192 def authentication return "" unless new_resource.svn_username result = "--username #{new_resource.svn_username} " result << "--password #{new_resource.svn_password} " result end
cwd()
click to toggle source
# File lib/chef/provider/subversion.rb, line 164 def cwd new_resource.destination end
extract_revision_info(svn_info)
click to toggle source
# File lib/chef/provider/subversion.rb, line 172 def extract_revision_info(svn_info) repo_attrs = svn_info.lines.inject({}) do |attrs, line| if line =~ SVN_INFO_PATTERN property, value = $1, $2 attrs[property] = value end attrs end rev = (repo_attrs["Last Changed Rev"] || repo_attrs["Revision"]) rev.strip! if rev raise "Could not parse `svn info` data: #{svn_info}" if repo_attrs.empty? logger.trace "#{new_resource} resolved revision #{new_resource.revision} to #{rev}" rev end
get_homedir(user)
click to toggle source
Returns the home directory of the user @param [String] user must be a string. @return [String] the home directory of the user.
# File lib/chef/provider/subversion.rb, line 237 def get_homedir(user) require "etc" unless defined?(Etc) case user when Integer TargetIO::Etc.getpwuid(user).dir else TargetIO::Etc.getpwnam(user.to_s).dir end end
proxy()
click to toggle source
# File lib/chef/provider/subversion.rb, line 200 def proxy repo_uri = URI.parse(new_resource.repository) proxy_uri = Chef::Config.proxy_uri(repo_uri.scheme, repo_uri.host, repo_uri.port) return "" if proxy_uri.nil? result = "--config-option servers:global:http-proxy-host=#{proxy_uri.host} " result << "--config-option servers:global:http-proxy-port=#{proxy_uri.port} " result end
scm(*args)
click to toggle source
# File lib/chef/provider/subversion.rb, line 210 def scm(*args) binary = svn_binary binary = "\"#{binary}\"" if /\s/.match?(binary) [binary, *args].compact.join(" ") end
svn_binary()
click to toggle source
# File lib/chef/provider/subversion.rb, line 220 def svn_binary new_resource.svn_binary || (ChefUtils.windows? ? "svn.exe" : "svn") end
target_dir_non_existent_or_empty?()
click to toggle source
# File lib/chef/provider/subversion.rb, line 216 def target_dir_non_existent_or_empty? !::TargetIO::File.exist?(new_resource.destination) || TargetIO::Dir.entries(new_resource.destination).sort == [".", ".."] end
verbose()
click to toggle source
# File lib/chef/provider/subversion.rb, line 168 def verbose "-q" end