ruby-changes:26959
From: mame <ko1@a...>
Date: Sat, 2 Feb 2013 12:09:40 +0900 (JST)
Subject: [ruby-changes:26959] mame:r39011 (trunk): * lib/fileutils.rb: chmod/chmod_R with a string mode (e.g., "+x")
mame 2013-02-02 12:07:17 +0900 (Sat, 02 Feb 2013) New Revision: 39011 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39011 Log: * lib/fileutils.rb: chmod/chmod_R with a string mode (e.g., "+x") caused error in verbose mode. * test/fileutils/test_fileutils.rb: add a test for above. Modified files: trunk/ChangeLog trunk/lib/fileutils.rb trunk/test/fileutils/test_fileutils.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 39010) +++ ChangeLog (revision 39011) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Feb 2 12:05:18 2013 Yusuke Endoh <mame@t...> + + * lib/fileutils.rb: chmod/chmod_R with a string mode (e.g., "+x") + caused error in verbose mode. + + * test/fileutils/test_fileutils.rb: add a test for above. + Sat Feb 2 11:44:42 2013 Yusuke Endoh <mame@t...> * lib/English.rb: Remove some confusing words from rdoc. [Bug #7406] Index: lib/fileutils.rb =================================================================== --- lib/fileutils.rb (revision 39010) +++ lib/fileutils.rb (revision 39011) @@ -996,6 +996,10 @@ private https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L996 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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1038 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 https://github.com/ruby/ruby/blob/trunk/lib/fileutils.rb#L1059 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| Index: test/fileutils/test_fileutils.rb =================================================================== --- test/fileutils/test_fileutils.rb (revision 39010) +++ test/fileutils/test_fileutils.rb (revision 39011) @@ -972,6 +972,27 @@ class TestFileUtils https://github.com/ruby/ruby/blob/trunk/test/fileutils/test_fileutils.rb#L972 chmod_R 0700, 'tmp/dir' # to remove end if have_file_perm? + def test_chmod_verbose + check_singleton :chmod + + r, w = IO.pipe + stderr_back = $stderr + read, $stderr = IO.pipe + th = Thread.new { read.read } + + touch 'tmp/a' + chmod 0700, 'tmp/a', verbose: true + assert_equal 0700, File.stat('tmp/a').mode & 0777 + chmod 0500, 'tmp/a', verbose: true + assert_equal 0500, File.stat('tmp/a').mode & 0777 + + $stderr.close + lines = th.value.lines.map {|l| l.chomp } + assert_equal(["chmod 700 tmp/a", "chmod 500 tmp/a"], lines) + ensure + $stderr = stderr_back if stderr_back + end if have_file_perm? + # FIXME: How can I test this method? def test_chown check_singleton :chown -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/