org-binbab/gem-vagrant-wrapper

is_wrapper function breaks when passed a binary filename

Closed this issue · 12 comments

For some reason, the wrapper is checking whether the binary under "/opt/vagrant/bin/vagrant" (on OS X) is a wrapper. When passed to the "grep" command, it errors out with:

ArgumentError: invalid byte sequence in UTF-8 /Library/Ruby/Gems/2.0.0/gems/vagrant-wrapper-2.0.2/lib/vagrant-wrapper.rb:179:in ==='
/Library/Ruby/Gems/2.0.0/gems/vagrant-wrapper-2.0.2/lib/vagrant-wrapper.rb:179:in each' /Library/Ruby/Gems/2.0.0/gems/vagrant-wrapper-2.0.2/lib/vagrant-wrapper.rb:179:in grep'
/Library/Ruby/Gems/2.0.0/gems/vagrant-wrapper-2.0.2/lib/vagrant-wrapper.rb:179:in is_wrapper?' /Library/Ruby/Gems/2.0.0/gems/vagrant-wrapper-2.0.2/lib/vagrant-wrapper.rb:147:in block in find_vagrant'
/Library/Ruby/Gems/2.0.0/gems/vagrant-wrapper-2.0.2/lib/vagrant-wrapper.rb:144:in each' /Library/Ruby/Gems/2.0.0/gems/vagrant-wrapper-2.0.2/lib/vagrant-wrapper.rb:144:in find_vagrant'
/Library/Ruby/Gems/2.0.0/gems/vagrant-wrapper-2.0.2/lib/vagrant-wrapper.rb:166:in exec_vagrant' /Library/Ruby/Gems/2.0.0/gems/vagrant-wrapper-2.0.2/lib/vagrant-wrapper.rb:70:in execute'`

Maybe it would be good to put a check to ensure the file is not a binary file prior to running grep on it? Or just catch the error and return "false".

Versions I'm running are:
rake 10.3.2
vagrant-wrapper 2.0.2
bundler 1.10.3
Vagrant 1.7.3
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
OS X 10.10.4

A lame workaround is to modify the function is_wrapper?() by adding a rescue for ArgumentError:

  def is_wrapper?(file)
    File.readlines(file).grep(/#{WRAPPER_MARK}/).any?
  rescue ArgumentError
    false
  end

This is happening on Ubuntu 12.04 as well.

The latest release of vagrant changed /opt/vagrant/bin/vagrant from a shell script to a binary, causing this problem.

👍 for me too, Arch Linux and Vagrant 1.7.3.

paging @binarybabel -- Can you see about fixing this sooner rather than later? It's frustrating.

@docwhat re: "paging binarybabel -- Can you see about fixing this sooner rather than later?"

This bug report is three days old, and as @sewhyte pointed out is caused by a recent change to vagrant.

Considering this is a free and open source project, do you honestly think snarky comments are a good way to ask for help?

@srkiNZ84 thanks for the report, and @sewhyte for the added info. An updated version of the gem should be available within the next 24 hours to address this issue.

I apologize. I didn't intend to be snarky.

I appreciate you work.

@binarybabel FYI, I'm hitting this too. My local fix (possibly more universal) was to modify readlines to binread thus:

  def is_wrapper?(file)
    File.binread(file) =~ /#{WRAPPER_MARK}/
  end

@BinaryBable I went ahead and submitted a PR for my fix. I'll probably reference my branch from our project until it's released. Happy merging!

Thanks @jkeiser for the PR. We had to evacuate temporarily due to wildfires in Cali and this issue admittedly slipped my mind. Your patch looks good, I should be able to publish a new gem today.

Thanks! I'm glad you are OK, sorry to hear about scary evacuations!

Version 2.0.3 is now life at rubygems.org