@@ -1579,6 +1579,7 @@ def mode_to_s(mode) #:nodoc:
15791579 #
15801580 # FileUtils.chmod('u=wrx,go=rx', 'src1.txt')
15811581 # FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby')
1582+ #
15821583 # Keyword arguments:
15831584 #
15841585 # - <tt>noop: true</tt> - does not change permissions; returns +nil+.
@@ -1606,12 +1607,7 @@ def chmod(mode, list, noop: nil, verbose: nil)
16061607 end
16071608 module_function :chmod
16081609
1609- #
1610- # Changes permission bits on the named files (in +list+)
1611- # to the bit pattern represented by +mode+.
1612- #
1613- # FileUtils.chmod_R 0700, "/tmp/app.#{$$}"
1614- # FileUtils.chmod_R "u=wrx", "/tmp/app.#{$$}"
1610+ # Like FileUtils.chmod, but changes permissions recursively.
16151611 #
16161612 def chmod_R ( mode , list , noop : nil , verbose : nil , force : nil )
16171613 list = fu_list ( list )
@@ -1631,15 +1627,69 @@ def chmod_R(mode, list, noop: nil, verbose: nil, force: nil)
16311627 end
16321628 module_function :chmod_R
16331629
1630+ # Changes the owner and group on the entries at the paths given in +list+
1631+ # to the given +user+ and +group+:
16341632 #
1635- # Changes owner and group on the named files (in +list+)
1636- # to the user +user+ and the group +group+. +user+ and +group+
1637- # may be an ID (Integer/String) or a name (String).
1638- # If +user+ or +group+ is nil, this method does not change
1639- # the attribute.
1633+ # - Modifies each entry that is a regular file using
1634+ # {File.chown}[https://docs.ruby-lang.org/en/master/File.html#method-c-chown].
1635+ # - Modifies each entry that is a symbolic link using
1636+ # {File.lchown}[https://docs.ruby-lang.org/en/master/File.html#method-c-lchown].
1637+ #
1638+ # Each path may be either a string or a
1639+ # {Pathname}[https://docs.ruby-lang.org/en/master/Pathname.html].
1640+ #
1641+ # User and group:
1642+ #
1643+ # - Argument +user+ may be a user name or a user id;
1644+ # if +nil+ or +-1+, the user is not changed.
1645+ # - Argument +group+ may be a group name or a group id;
1646+ # if +nil+ or +-1+, the group is not changed.
1647+ # - The user must be a member of the group.
1648+ #
1649+ # Examples:
1650+ #
1651+ # # One string path.
1652+ # # User and group as string names.
1653+ # File.stat('src0.txt').uid # => 1004
1654+ # File.stat('src0.txt').gid # => 1004
1655+ # FileUtils.chown('user2', 'group1', 'src0.txt')
1656+ # File.stat('src0.txt').uid # => 1006
1657+ # File.stat('src0.txt').gid # => 1005
1658+ #
1659+ # # User and group as uid and gid.
1660+ # FileUtils.chown(1004, 1004, 'src0.txt')
1661+ # File.stat('src0.txt').uid # => 1004
1662+ # File.stat('src0.txt').gid # => 1004
1663+ #
1664+ # # Array of string paths.
1665+ # FileUtils.chown(1006, 1005, ['src0.txt', 'src0.dat'])
1666+ #
1667+ # # Pathname path.
1668+ # require 'pathname'
1669+ # path = Pathname.new('src0.txt')
1670+ # FileUtils.chown('user2', 'group1', path)
1671+ #
1672+ # # Directory (not recursive).
1673+ # FileUtils.chown('user2', 'group1', '.')
1674+ #
1675+ # Keyword arguments:
1676+ #
1677+ # - <tt>noop: true</tt> - does not change permissions; returns +nil+.
1678+ # - <tt>verbose: true</tt> - prints an equivalent command:
1679+ #
1680+ # FileUtils.chown('user2', 'group1', 'src0.txt', noop: true, verbose: true)
1681+ # FileUtils.chown(1004, 1004, 'src0.txt', noop: true, verbose: true)
1682+ # FileUtils.chown(1006, 1005, ['src0.txt', 'src0.dat'], noop: true, verbose: true)
1683+ # FileUtils.chown('user2', 'group1', path, noop: true, verbose: true)
1684+ # FileUtils.chown('user2', 'group1', '.', noop: true, verbose: true)
1685+ #
1686+ # Output:
16401687 #
1641- # FileUtils.chown 'root', 'staff', '/usr/local/bin/ruby'
1642- # FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), verbose: true
1688+ # chown user2:group1 src0.txt
1689+ # chown 1004:1004 src0.txt
1690+ # chown 1006:1005 src0.txt src0.dat
1691+ # chown user2:group1 src0.txt
1692+ # chown user2:group1 .
16431693 #
16441694 def chown ( user , group , list , noop : nil , verbose : nil )
16451695 list = fu_list ( list )
0 commit comments