Skip to content

Commit 289fc49

Browse files
authored
Merge pull request #43 from nobu/bug/instll-modeX
Fix `#install` with "X" mode option
2 parents 44d133b + 2ea54ad commit 289fc49

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/fileutils.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -917,11 +917,8 @@ def apply_mask(mode, user_mask, op, mode_mask) #:nodoc:
917917
private_module_function :apply_mask
918918

919919
def symbolic_modes_to_i(mode_sym, path) #:nodoc:
920-
mode = if File::Stat === path
921-
path.mode
922-
else
923-
File.stat(path).mode
924-
end
920+
path = File.stat(path) unless File::Stat === path
921+
mode = path.mode
925922
mode_sym.split(/,/).inject(mode & 07777) do |current_mode, clause|
926923
target, *actions = clause.split(/([=+-])/)
927924
raise ArgumentError, "invalid file mode: #{mode_sym}" if actions.empty?
@@ -938,7 +935,7 @@ def symbolic_modes_to_i(mode_sym, path) #:nodoc:
938935
when "x"
939936
mask | 0111
940937
when "X"
941-
if FileTest.directory? path
938+
if path.directory?
942939
mask | 0111
943940
else
944941
mask

test/fileutils/test_fileutils.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,32 @@ def test_install_group_option
11601160
}
11611161
end
11621162

1163+
def test_install_mode_option
1164+
File.open('tmp/a', 'w') {|f| f.puts 'aaa' }
1165+
install 'tmp/a', 'tmp/b', :mode => "u=wrx,g=rx,o=x"
1166+
assert_filemode 0751, 'tmp/b'
1167+
install 'tmp/b', 'tmp/c', :mode => "g+w-x"
1168+
assert_filemode 0761, 'tmp/c'
1169+
install 'tmp/c', 'tmp/d', :mode => "o+r,g=o+w,o-r,u-o" # 761 => 763 => 773 => 771 => 671
1170+
assert_filemode 0671, 'tmp/d'
1171+
install 'tmp/d', 'tmp/e', :mode => "go=u"
1172+
assert_filemode 0666, 'tmp/e'
1173+
install 'tmp/e', 'tmp/f', :mode => "u=wrx,g=,o="
1174+
assert_filemode 0700, 'tmp/f'
1175+
install 'tmp/f', 'tmp/g', :mode => "u=rx,go="
1176+
assert_filemode 0500, 'tmp/g'
1177+
install 'tmp/g', 'tmp/h', :mode => "+wrx"
1178+
assert_filemode 0777, 'tmp/h'
1179+
install 'tmp/h', 'tmp/i', :mode => "u+s,o=s"
1180+
assert_filemode 04770, 'tmp/i'
1181+
install 'tmp/i', 'tmp/j', :mode => "u-w,go-wrx"
1182+
assert_filemode 04500, 'tmp/j'
1183+
install 'tmp/j', 'tmp/k', :mode => "+s"
1184+
assert_filemode 06500, 'tmp/k'
1185+
install 'tmp/a', 'tmp/l', :mode => "o+X"
1186+
assert_filemode 0644, 'tmp/l'
1187+
end if have_file_perm?
1188+
11631189
def test_chmod
11641190
check_singleton :chmod
11651191

0 commit comments

Comments
 (0)