Project

General

Profile

Bug #7373

FileUtils#chmod verbose gives error when mode is string

Added by asterite (Ary Borenszweig) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
Backport:
[ruby-core:49427]

Description

I can see the wrong code in trunk, even though it happened in 1.9.3p194: https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1037 )

asterite @ ~ $ irb
irb(main):001:0> require 'fileutils'
=> true
irb(main):002:0> FileUtils.chmod '+x', 'foo'
=> ["foo"]
irb(main):003:0> FileUtils.chmod '+x', 'foo', verbose: true
ArgumentError: invalid value for Integer(): "+x"
from /Users/asterite/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:967:in sprintf'
from /Users/asterite/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/fileutils.rb:967:in
chmod'
from (irb):3
from /Users/asterite/.rbenv/versions/1.9.3-p194/bin/irb:12:in `'

This is because chmod in verbose mode assumes the mode is a number, and tries to format it in octal:

fu_output_message sprintf('chmod %o %s', mode, list.join(' ')) if options[:verbose]

The same problem is present in chmod_R.

Sorry I don't include a patch, I'm not sure how to solve it. Maybe check if mode is a number and then use %o, else use %s.

Also available in: Atom PDF