* lib/fileutils.rb (FileUtils.chmod{,_R}): Enhance the symbolic

mode parser to support the permission symbols u/g/o and multiple
  actions as defined in SUS, so that chmod("g=o+w", file) works as
  expected.  Invalid symbolic modes are now rejected with
  ArgumentError.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2013-07-04 17:22:08 +00:00
parent 45116b6a6d
commit a0011cd54d
3 changed files with 94 additions and 46 deletions

View file

@ -932,6 +932,12 @@ class TestFileUtils
check_singleton :chmod
touch 'tmp/a'
chmod "u=wrx,g=rx,o=x", 'tmp/a'
assert_equal 0751, File.stat('tmp/a').mode & 07777
chmod "g+w-x", 'tmp/a'
assert_equal 0761, File.stat('tmp/a').mode & 07777
chmod "o+r,g=o+w,o-r,u-o", 'tmp/a' # 761 => 763 => 773 => 771 => 671
assert_equal 0671, File.stat('tmp/a').mode & 07777
chmod "u=wrx,g=,o=", 'tmp/a'
assert_equal 0700, File.stat('tmp/a').mode & 0777
chmod "u=rx,go=", 'tmp/a'
@ -956,6 +962,26 @@ class TestFileUtils
assert_equal 0500, File.stat('tmp/a').mode & 07777
end
assert_raises_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
chmod "a", 'tmp/a'
}
assert_raises_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
chmod "x+a", 'tmp/a'
}
assert_raises_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
chmod "u+z", 'tmp/a'
}
assert_raises_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
chmod ",+x", 'tmp/a'
}
assert_raises_with_message(ArgumentError, /invalid\b.*\bfile mode/) {
chmod "755", 'tmp/a'
}
end if have_file_perm?