Issue #7373 has been reported by asterite (Ary Borenszweig). ---------------------------------------- Bug #7373: FileUtils#chmod verbose gives error when mode is string https://bugs.ruby-lang.org/issues/7373 Author: asterite (Ary Borenszweig) Status: Open Priority: Normal Assignee: Category: lib Target version: ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0] I can see the wrong code in trunk, even though it happened in 1.9.3p194: https://github.com/ruby/ruby/blob/trunk/lib/fileut... ) 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 `<main>' 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.
on 2012-11-16 16:16
on 2012-11-25 02:42
Issue #7373 has been updated by mame (Yusuke Endoh).
Status changed from Open to Assigned
Assignee set to mame (Yusuke Endoh)
Target version set to 2.0.0
Thank you.
I'll apply the following patch unless there is objection.
diff --git a/lib/fileutils.rb b/lib/fileutils.rb
index af2d19a..57ab0cf 100644
--- a/lib/fileutils.rb
+++ b/lib/fileutils.rb
@@ -996,6 +996,10 @@ private
mode.is_a?(String) ? symbolic_modes_to_i(mode, path) : mode
end
+ def mode_to_s(mode) #:nodoc:
+ mode.is_a?(String) ? mode : "%o" % mode
+ end
+
public
#
@@ -1034,7 +1038,7 @@ public
def chmod(mode, list, options = {})
fu_check_options options, OPT_TABLE['chmod']
list = fu_list(list)
- fu_output_message sprintf('chmod %o %s', mode, list.join(' ')) if
options[:verbose]
+ fu_output_message sprintf('chmod %s %s', mode_to_s(mode),
list.join(' ')) if options[:verbose]
return if options[:noop]
list.each do |path|
Entry_.new(path).chmod(fu_mode(mode, path))
@@ -1055,9 +1059,9 @@ public
def chmod_R(mode, list, options = {})
fu_check_options options, OPT_TABLE['chmod_R']
list = fu_list(list)
- fu_output_message sprintf('chmod -R%s %o %s',
+ fu_output_message sprintf('chmod -R%s %s %s',
(options[:force] ? 'f' : ''),
- mode, list.join(' ')) if
options[:verbose]
+ mode_to_s(mode), list.join(' ')) if
options[:verbose]
return if options[:noop]
list.each do |root|
Entry_.new(root).traverse do |ent|
--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Bug #7373: FileUtils#chmod verbose gives error when mode is string
https://bugs.ruby-lang.org/issues/7373#change-33835
Author: asterite (Ary Borenszweig)
Status: Assigned
Priority: Normal
Assignee: mame (Yusuke Endoh)
Category: lib
Target version: 2.0.0
ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410)
[x86_64-darwin12.0.0]
I can see the wrong code in trunk, even though it happened in 1.9.3p194:
https://github.com/ruby/ruby/blob/trunk/lib/fileut... )
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 `<main>'
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.
on 2013-02-02 04:57
Issue #7373 has been updated by mame (Yusuke Endoh). Status changed from Assigned to Closed Applied at r39011. -- Yusuke Endoh <mame@tsg.ne.jp> ---------------------------------------- Bug #7373: FileUtils#chmod verbose gives error when mode is string https://bugs.ruby-lang.org/issues/7373#change-35776 Author: asterite (Ary Borenszweig) Status: Closed Priority: Normal Assignee: mame (Yusuke Endoh) Category: lib Target version: 2.0.0 ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0] I can see the wrong code in trunk, even though it happened in 1.9.3p194: https://github.com/ruby/ruby/blob/trunk/lib/fileut... ) 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 `<main>' 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.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.