@@ -1705,15 +1705,7 @@ def chown(user, group, list, noop: nil, verbose: nil)
17051705 end
17061706 module_function :chown
17071707
1708- #
1709- # Changes owner and group on the named files (in +list+)
1710- # to the user +user+ and the group +group+ recursively.
1711- # +user+ and +group+ may be an ID (Integer/String) or
1712- # a name (String). If +user+ or +group+ is nil, this
1713- # method does not change the attribute.
1714- #
1715- # FileUtils.chown_R 'www', 'www', '/var/www/htdocs'
1716- # FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', verbose: true
1708+ # Like FileUtils.chown, but changes owner and group recursively.
17171709 #
17181710 def chown_R ( user , group , list , noop : nil , verbose : nil , force : nil )
17191711 list = fu_list ( list )
@@ -1764,12 +1756,44 @@ def fu_get_gid(group) #:nodoc:
17641756 end
17651757 private_module_function :fu_get_gid
17661758
1759+ # Updates modification times (mtime) and access times (atime)
1760+ # of the entries given by the paths in +list+;
1761+ # by default, creates an empty file for any path to a non-existent entry:
17671762 #
1768- # Updates modification time (mtime) and access time (atime) of file(s) in
1769- # +list+. Files are created if they don't exist.
1763+ # # Single string path.
1764+ # f = File.new('src0.txt') # Existing file.
1765+ # f.atime # => 2022-06-10 11:11:21.200277 -0700
1766+ # f.mtime # => 2022-06-10 11:11:21.200277 -0700
1767+ # FileUtils.touch('src0.txt')
1768+ # f = File.new('src0.txt')
1769+ # f.atime # => 2022-06-11 08:28:09.8185343 -0700
1770+ # f.mtime # => 2022-06-11 08:28:09.8185343 -0700
17701771 #
1771- # FileUtils.touch 'timestamp'
1772- # FileUtils.touch Dir.glob('*.c'); system 'make'
1772+ # # Array of string paths.
1773+ # FileUtils.touch(['src0.txt', 'src0.dat'])
1774+ #
1775+ # # Pathname.
1776+ # require 'pathname'
1777+ # path = Pathname.new('src0.txt')
1778+ # FileUtils.touch(path)
1779+ #
1780+ # Keyword arguments:
1781+ #
1782+ # - <tt>mtime: <i>time</i></tt> - sets the entry's mtime to the given time,
1783+ # instead of the current time.
1784+ # - <tt>nocreate: true</tt> - raises an exception if the entry does not exist.
1785+ # - <tt>noop: true</tt> - does not touch entries; returns +nil+.
1786+ # - <tt>verbose: true</tt> - prints an equivalent command:
1787+ #
1788+ # FileUtils.touch('src0.txt', noop: true, verbose: true)
1789+ # FileUtils.touch(['src0.txt', 'src0.dat'], noop: true, verbose: true)
1790+ # FileUtils.touch(path, noop: true, verbose: true)
1791+ #
1792+ # Output:
1793+ #
1794+ # touch src0.txt
1795+ # touch src0.txt src0.dat
1796+ # touch src0.txt
17731797 #
17741798 def touch ( list , noop : nil , verbose : nil , mtime : nil , nocreate : nil )
17751799 list = fu_list ( list )
@@ -2272,50 +2296,49 @@ def fu_output_message(msg) #:nodoc:
22722296
22732297 public
22742298
2299+ # Returns an array of the string names of \FileUtils methods
2300+ # that accept one or more keyword arguments;
22752301 #
2276- # Returns an Array of names of high-level methods that accept any keyword
2277- # arguments.
2278- #
2279- # p FileUtils.commands #=> ["chmod", "cp", "cp_r", "install", ...]
2302+ # FileUtils.commands.sort.take(3) # => ["cd", "chdir", "chmod"]
22802303 #
22812304 def self . commands
22822305 OPT_TABLE . keys
22832306 end
22842307
2308+ # Returns an array of the string keyword names:
22852309 #
2286- # Returns an Array of option names.
2287- #
2288- # p FileUtils.options #=> ["noop", "force", "verbose", "preserve", "mode"]
2310+ # FileUtils.options.take(3) # => ["noop", "verbose", "force"]
22892311 #
22902312 def self . options
22912313 OPT_TABLE . values . flatten . uniq . map { |sym | sym . to_s }
22922314 end
22932315
2316+ # Returns +true+ if method +mid+ accepts the given option +opt+, +false+ otherwise;
2317+ # the arguments may be strings or symbols:
22942318 #
2295- # Returns true if the method +mid+ have an option +opt+.
2296- #
2297- # p FileUtils.have_option?(:cp, :noop) #=> true
2298- # p FileUtils.have_option?(:rm, :force) #=> true
2299- # p FileUtils.have_option?(:rm, :preserve) #=> false
2319+ # FileUtils.have_option?(:chmod, :noop) # => true
2320+ # FileUtils.have_option?('chmod', 'secure') # => false
23002321 #
23012322 def self . have_option? ( mid , opt )
23022323 li = OPT_TABLE [ mid . to_s ] or raise ArgumentError , "no such method: #{ mid } "
23032324 li . include? ( opt )
23042325 end
23052326
2327+ # Returns an array of the string keyword name for method +mid+;
2328+ # the argument may be a string or a symbol:
23062329 #
2307- # Returns an Array of option names of the method +mid+.
2308- #
2309- # p FileUtils.options_of(:rm) #=> ["noop", "verbose", "force"]
2330+ # FileUtils.options_of(:rm) # => ["force", "noop", "verbose"]
2331+ # FileUtils.options_of('mv') # => ["force", "noop", "verbose", "secure"]
23102332 #
23112333 def self . options_of ( mid )
23122334 OPT_TABLE [ mid . to_s ] . map { |sym | sym . to_s }
23132335 end
23142336
2337+ # Returns an array of the string method names of the methods
2338+ # that accept the given keyword option +opt+;
2339+ # the argument must be a symbol:
23152340 #
2316- # Returns an Array of methods names which have the option +opt+.
2317- #
2318- # p FileUtils.collect_method(:preserve) #=> ["cp", "cp_r", "copy", "install"]
2341+ # FileUtils.collect_method(:preserve) # => ["cp", "copy", "cp_r", "install"]
23192342 #
23202343 def self . collect_method ( opt )
23212344 OPT_TABLE . keys . select { |m | OPT_TABLE [ m ] . include? ( opt ) }
0 commit comments