@@ -1579,6 +1579,7 @@ def mode_to_s(mode) #:nodoc:
1579
1579
#
1580
1580
# FileUtils.chmod('u=wrx,go=rx', 'src1.txt')
1581
1581
# FileUtils.chmod('u=wrx,go=rx', '/usr/bin/ruby')
1582
+ #
1582
1583
# Keyword arguments:
1583
1584
#
1584
1585
# - <tt>noop: true</tt> - does not change permissions; returns +nil+.
@@ -1606,12 +1607,7 @@ def chmod(mode, list, noop: nil, verbose: nil)
1606
1607
end
1607
1608
module_function :chmod
1608
1609
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.
1615
1611
#
1616
1612
def chmod_R ( mode , list , noop : nil , verbose : nil , force : nil )
1617
1613
list = fu_list ( list )
@@ -1631,15 +1627,69 @@ def chmod_R(mode, list, noop: nil, verbose: nil, force: nil)
1631
1627
end
1632
1628
module_function :chmod_R
1633
1629
1630
+ # Changes the owner and group on the entries at the paths given in +list+
1631
+ # to the given +user+ and +group+:
1634
1632
#
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:
1640
1687
#
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 .
1643
1693
#
1644
1694
def chown ( user , group , list , noop : nil , verbose : nil )
1645
1695
list = fu_list ( list )
0 commit comments