diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/fileutils.rb | 10 | ||||
-rw-r--r-- | test/fileutils/test_fileutils.rb | 21 |
3 files changed, 35 insertions, 3 deletions
@@ -1,3 +1,10 @@ +Sat Feb 2 12:05:18 2013 Yusuke Endoh <mame@tsg.ne.jp> + + * 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@tsg.ne.jp> * lib/English.rb: Remove some confusing words from rdoc. [Bug #7406] diff --git a/lib/fileutils.rb b/lib/fileutils.rb index af2d19ac61..57ab0cf77a 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| diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index 7de032145c..c1104f31ca 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -972,6 +972,27 @@ class TestFileUtils 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 |