Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #install with "X" mode option #43

Merged
merged 2 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -918,11 +918,8 @@ def apply_mask(mode, user_mask, op, mode_mask) #:nodoc:
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?
Expand All @@ -939,7 +936,7 @@ def symbolic_modes_to_i(mode_sym, path) #:nodoc:
when "x"
mask | 0111
when "X"
if FileTest.directory? path
if path.directory?
mask | 0111
else
mask
Expand Down
26 changes: 26 additions & 0 deletions test/fileutils/test_fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,32 @@ def test_install_group_option
}
end

def test_install_mode_option
File.open('tmp/a', 'w') {|f| f.puts 'aaa' }
install 'tmp/a', 'tmp/b', :mode => "u=wrx,g=rx,o=x"
assert_filemode 0751, 'tmp/b'
install 'tmp/b', 'tmp/c', :mode => "g+w-x"
assert_filemode 0761, 'tmp/c'
install 'tmp/c', 'tmp/d', :mode => "o+r,g=o+w,o-r,u-o" # 761 => 763 => 773 => 771 => 671
assert_filemode 0671, 'tmp/d'
install 'tmp/d', 'tmp/e', :mode => "go=u"
assert_filemode 0666, 'tmp/e'
install 'tmp/e', 'tmp/f', :mode => "u=wrx,g=,o="
assert_filemode 0700, 'tmp/f'
install 'tmp/f', 'tmp/g', :mode => "u=rx,go="
assert_filemode 0500, 'tmp/g'
install 'tmp/g', 'tmp/h', :mode => "+wrx"
assert_filemode 0777, 'tmp/h'
install 'tmp/h', 'tmp/i', :mode => "u+s,o=s"
assert_filemode 04770, 'tmp/i'
install 'tmp/i', 'tmp/j', :mode => "u-w,go-wrx"
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
check_singleton :chmod

Expand Down