arkency / ruby-build-cookbook

Cookbook providing definition to install Ruby for user using ruby-build.
11 stars 1 forks source link

.bashrc might not exist or have less then 2 lines #5

Open paneq opened 11 years ago

paneq commented 11 years ago
  profile_file = "#{home_dir}/.bashrc"
  ruby_block "append ruby path #{ruby_dir}" do
    comment = "# Generated by chef"
    path_definition = "export PATH=$HOME/#{version}/bin:$PATH"

    block do
      original_content = File.open(profile_file, 'r').read
      lines = original_content.split("\n")
      if lines[0].start_with?(comment) && lines[1].start_with?("export PATH=")
        original_content = lines[2..-1].join("\n")
      end
      File.open(profile_file, 'w') do |f|
mlomnicki commented 11 years ago

I think Chef::Util::FileEdit may be helpful to fix this issue

https://github.com/opscode/chef/blob/master/spec/unit/util/file_edit_spec.rb

mlen commented 11 years ago

Fixed in a3e4a90476dde7d7dc132324092a9eed87f27ab7, however it doesn't use Chef::Util::FileEdit.