<commit_before>case node['platform_family']
when 'debian'
  include_recipe 'apt'

  apt_repository 'thoughtworks' do
    uri 'http://download01.thoughtworks.com/go/debian'
    components ['contrib/']
  end

  package_options = '--force-yes'
when 'rhel'
  include_recipe 'yum'

  yum_repository 'thoughtworks' do
    baseurl 'http://download01.thoughtworks.com/go/yum/no-arch'
    gpgcheck false
  end
end

include_recipe 'java'

package 'unzip'

package "go-server" do
  version node['go']['version']
  options package_options
  notifies :start, 'service[go-server]', :immediately
end

# If we're upgrading an existing Go Server then leave the configuration and such intact. 
# If it's a new node, and a SVN backup URL is specified then restore/overwrite any existing configuration.

# Detection isn't based on the <license> element as Go-Community edition has no license. 
# We look for at least one <pipelines> element, with the assumption that if you have a backup you have at least one pipeline.

if (::File.exists?('/etc/go/cruise-config.xml') and ::File.readlines('/etc/go/cruise-config.xml').grep(/<pipelines/).length > 0) 
  skip_backup = true
  Chef::Log.warn("Existing configuration detected. Restore skipped.")
else
  Chef::Log.warn("New install detected.")
  skip_backup = false
  restore_go_config = false
  if (node['go']['backup_path'] && !node['go']['backup_path'].strip.empty?) 
    Chef::Log.warn("Backup URL specified. Configuration will be restored.")
    restore_go_config = true
  end
end

if node['go']['backup_retrieval_type'] =~ /subversion|svn/i
# Grab the backup out of Subversion
  subversion "restore-go-config" do
    Chef::Log.info("Restoring configuration from #{node['go']['backup_path']}")
    repository node['go']['backup_path']
    destination "#{Chef::Config[:file_cache_path]}/go-config-restore"
    action :force_export
    notifies :stop, 'service[go-server-control]', :immediately
    not_if {skip_backup}
    only_if {restore_go_config}
  end
elsif node['go']['backup_retrieval_type'] =~ /local/i and ::File.directory?(node['go']['backup_path'])
  directory "#Chef::Config[:file_cache_path]}/go-config-restore/go-config/current" do<commit_msg>fix error in restore functionality<commit_after>case node['platform_family']
when 'debian'
  include_recipe 'apt'

  apt_repository 'thoughtworks' do
    uri 'http://download01.thoughtworks.com/go/debian'
    components ['contrib/']
  end

  package_options = '--force-yes'
when 'rhel'
  include_recipe 'yum'

  yum_repository 'thoughtworks' do
    baseurl 'http://download01.thoughtworks.com/go/yum/no-arch'
    gpgcheck false
  end
end

include_recipe 'java'

package 'unzip'

package "go-server" do
  version node['go']['version']
  options package_options
  notifies :start, 'service[go-server]', :immediately
end

# If we're upgrading an existing Go Server then leave the configuration and such intact. 
# If it's a new node, and a SVN backup URL is specified then restore/overwrite any existing configuration.

# Detection isn't based on the <license> element as Go-Community edition has no license. 
# We look for at least one <pipelines> element, with the assumption that if you have a backup you have at least one pipeline.

if (::File.exists?('/etc/go/cruise-config.xml') and ::File.readlines('/etc/go/cruise-config.xml').grep(/<pipelines/).length > 0) 
  skip_backup = true
  Chef::Log.warn("Existing configuration detected. Restore skipped.")
else
  Chef::Log.warn("New install detected.")
  skip_backup = false
  restore_go_config = false
  if (node['go']['backup_path'] && !node['go']['backup_path'].strip.empty?) 
    Chef::Log.warn("Backup URL specified. Configuration will be restored.")
    restore_go_config = true
  end
end

if node['go']['backup_retrieval_type'] =~ /subversion|svn/i
# Grab the backup out of Subversion
  subversion "restore-go-config" do
    Chef::Log.info("Restoring configuration from #{node['go']['backup_path']}")
    repository node['go']['backup_path']
    destination "#{Chef::Config[:file_cache_path]}/go-config-restore"
    action :force_export
    notifies :stop, 'service[go-server-control]', :immediately
    not_if {skip_backup}
    only_if {restore_go_config}
  end
elsif node['go']['backup_retrieval_type'] =~ /local/i and ::File.directory?(node['go']['backup_path'])
  directory "#{Chef::Config[:file_cache_path]}/go-config-restore/go-config/current" do
{'fraction_non_alphanumeric': 0.13450159308147475, 'fraction_numerical': 0.002275830678197542, 'mean_word_length': 4.821192052980132, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '609725', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1379, 'n_words': 373}