diff --git a/lib/fileutils.rb b/lib/fileutils.rb index b527e89c0f..875ce50daf 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -917,11 +917,8 @@ module FileUtils private_module_function :apply_mask def symbolic_modes_to_i(mode_sym, path) #:nodoc: - mode = if File::Stat === path - path.mode - else - File.stat(path).mode - end + path = File.stat(path) unless File::Stat === path + mode = path.mode mode_sym.split(/,/).inject(mode & 07777) do |current_mode, clause| target, *actions = clause.split(/([=+-])/) raise ArgumentError, "invalid file mode: #{mode_sym}" if actions.empty? @@ -938,7 +935,7 @@ module FileUtils when "x" mask | 0111 when "X" - if FileTest.directory? path + if path.directory? mask | 0111 else mask diff --git a/test/fileutils/test_fileutils.rb b/test/fileutils/test_fileutils.rb index ca435ed1ff..82c6389558 100644 --- a/test/fileutils/test_fileutils.rb +++ b/test/fileutils/test_fileutils.rb @@ -1182,6 +1182,8 @@ class TestFileUtils < Test::Unit::TestCase assert_filemode 04500, 'tmp/j' install 'tmp/j', 'tmp/k', :mode => "+s" assert_filemode 06500, 'tmp/k' + install 'tmp/a', 'tmp/l', :mode => "o+X" + assert_filemode 0644, 'tmp/l' end if have_file_perm? def test_chmod