New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Tempfile.new #88

Merged
merged 2 commits into from Sep 1, 2016

Conversation

Projects
None yet
4 participants
@jeremymv2
Contributor

jeremymv2 commented Sep 1, 2016

Description

This PR fixes the call to Tempfile.new

Issues Resolved

Since Ruby 2.2.0 bundled in newer versions of chef-client, Tempfile.new errors with:

    ================================================================================
    Error executing action `fetch` on resource 'compliance_profile[linux]'
    ================================================================================

    ArgumentError
    -------------
    wrong number of arguments (given 3, expected 0..2)

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/audit/libraries/profile.rb:64:in `new'

This is because Tempfile.new has just ignored the 'wb+' option - not so any more.

https://bugs.ruby-lang.org/issues/10690

This PR fixes how the Tempfile object is instantiated.

As documented here: http://ruby-doc.org/stdlib-2.3.1/libdoc/tempfile/rdoc/Tempfile.html#method-c-new Tempfile.new will open the file with "w+" by default; then using bindmode=>true we get binary mode.

~/Devel/ChefProject/tmp$ ruby test_fileutils.rb

Frame number: 0/1

From: /Users/jmiller/Devel/ChefProject/tmp/test_fileutils.rb @ line 5 :

    1: require 'tempfile'
    2: require 'pry'
    3: tf = Tempfile.new('foo', Dir.tmpdir, :binmode => true)
    4: binding.pry
 => 5: puts tf

[1] pry(main)> tf.binmode?
=> true
[2] pry(main)> File.writable?(tf.path)
=> true
[3] pry(main)>

[List any existing issues this PR resolves]

Check List

@chris-rock chris-rock merged commit afbcd7e into chef-cookbooks:master Sep 1, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@iennae iennae removed the in progress label Sep 1, 2016

@chris-rock

This comment has been minimized.

Collaborator

chris-rock commented Sep 1, 2016

Thanks @jeremymv2

@jeremymv2 jeremymv2 deleted the jeremymv2:fix_wrong_number_of_arguments branch Sep 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment