24
24
#
25
25
# require 'fileutils'
26
26
#
27
- # FileUtils.cd(dir, options)
28
- # FileUtils.cd(dir, options) {|dir| block }
27
+ # FileUtils.cd(dir, ** options)
28
+ # FileUtils.cd(dir, ** options) {|dir| block }
29
29
# FileUtils.pwd()
30
- # FileUtils.mkdir(dir, options)
31
- # FileUtils.mkdir(list, options)
32
- # FileUtils.mkdir_p(dir, options)
33
- # FileUtils.mkdir_p(list, options)
34
- # FileUtils.rmdir(dir, options)
35
- # FileUtils.rmdir(list, options)
36
- # FileUtils.ln(target, link, options)
37
- # FileUtils.ln(targets, dir, options)
38
- # FileUtils.ln_s(target, link, options)
39
- # FileUtils.ln_s(targets, dir, options)
40
- # FileUtils.ln_sf(target, link, options)
41
- # FileUtils.cp(src, dest, options)
42
- # FileUtils.cp(list, dir, options)
43
- # FileUtils.cp_r(src, dest, options)
44
- # FileUtils.cp_r(list, dir, options)
45
- # FileUtils.mv(src, dest, options)
46
- # FileUtils.mv(list, dir, options)
47
- # FileUtils.rm(list, options)
48
- # FileUtils.rm_r(list, options)
49
- # FileUtils.rm_rf(list, options)
50
- # FileUtils.install(src, dest, options)
51
- # FileUtils.chmod(mode, list, options)
52
- # FileUtils.chmod_R(mode, list, options)
53
- # FileUtils.chown(user, group, list, options)
54
- # FileUtils.chown_R(user, group, list, options)
55
- # FileUtils.touch(list, options)
30
+ # FileUtils.mkdir(dir, ** options)
31
+ # FileUtils.mkdir(list, ** options)
32
+ # FileUtils.mkdir_p(dir, ** options)
33
+ # FileUtils.mkdir_p(list, ** options)
34
+ # FileUtils.rmdir(dir, ** options)
35
+ # FileUtils.rmdir(list, ** options)
36
+ # FileUtils.ln(target, link, ** options)
37
+ # FileUtils.ln(targets, dir, ** options)
38
+ # FileUtils.ln_s(target, link, ** options)
39
+ # FileUtils.ln_s(targets, dir, ** options)
40
+ # FileUtils.ln_sf(target, link, ** options)
41
+ # FileUtils.cp(src, dest, ** options)
42
+ # FileUtils.cp(list, dir, ** options)
43
+ # FileUtils.cp_r(src, dest, ** options)
44
+ # FileUtils.cp_r(list, dir, ** options)
45
+ # FileUtils.mv(src, dest, ** options)
46
+ # FileUtils.mv(list, dir, ** options)
47
+ # FileUtils.rm(list, ** options)
48
+ # FileUtils.rm_r(list, ** options)
49
+ # FileUtils.rm_rf(list, ** options)
50
+ # FileUtils.install(src, dest, ** options)
51
+ # FileUtils.chmod(mode, list, ** options)
52
+ # FileUtils.chmod_R(mode, list, ** options)
53
+ # FileUtils.chown(user, group, list, ** options)
54
+ # FileUtils.chown_R(user, group, list, ** options)
55
+ # FileUtils.touch(list, ** options)
56
56
#
57
- # The <tt>options</tt> parameter is a hash of options, taken from the list
58
- # <tt>:force</tt>, <tt>:noop</tt>, <tt>:preserve</tt>, and <tt>:verbose</tt>.
59
- # <tt>:noop</tt> means that no changes are made. The other three are obvious.
60
- # Each method documents the options that it honours.
57
+ # Possible <tt>options</tt> are:
58
+ #
59
+ # <tt>:force</tt> :: forced operation (rewrite files if exist, remove
60
+ # directories if not empty, etc.);
61
+ # <tt>:verbose</tt> :: print command to be run, in bash syntax, before
62
+ # performing it;
63
+ # <tt>:preserve</tt> :: preserve object's group, user and modification
64
+ # time on copying;
65
+ # <tt>:noop</tt> :: no changes are made (usable in combination with
66
+ # <tt>:verbose</tt> which will print the command to run)
67
+ #
68
+ # Each method documents the options that it honours. See also ::commands,
69
+ # ::options and ::options_of methods to introspect which command have which
70
+ # options.
61
71
#
62
72
# All methods that have the concept of a "source" file or directory can take
63
73
# either one file or a list of files in that argument. See the method
64
74
# documentation for examples.
65
75
#
66
- # There are some `low level' methods, which do not accept any option :
76
+ # There are some `low level' methods, which do not accept keyword arguments :
67
77
#
68
78
# FileUtils.copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
69
79
# FileUtils.copy_file(src, dest, preserve = false, dereference = true)
@@ -119,7 +129,7 @@ def pwd
119
129
#
120
130
# FileUtils.cd('/') # change directory
121
131
#
122
- # FileUtils.cd('/', : verbose => true) # change directory and report it
132
+ # FileUtils.cd('/', verbose: true) # change directory and report it
123
133
#
124
134
# FileUtils.cd('/') do # change directory
125
135
# # ... # do something
@@ -164,9 +174,9 @@ def remove_trailing_slash(dir) #:nodoc:
164
174
# Creates one or more directories.
165
175
#
166
176
# FileUtils.mkdir 'test'
167
- # FileUtils.mkdir %w( tmp data )
168
- # FileUtils.mkdir 'notexist', : noop => true # Does not really create.
169
- # FileUtils.mkdir 'tmp', : mode => 0700
177
+ # FileUtils.mkdir %w(tmp data)
178
+ # FileUtils.mkdir 'notexist', noop: true # Does not really create.
179
+ # FileUtils.mkdir 'tmp', mode: 0700
170
180
#
171
181
def mkdir ( list , mode : nil , noop : nil , verbose : nil )
172
182
list = fu_list ( list )
@@ -185,7 +195,7 @@ def mkdir(list, mode: nil, noop: nil, verbose: nil)
185
195
#
186
196
# FileUtils.mkdir_p '/usr/local/lib/ruby'
187
197
#
188
- # causes to make following directories, if it does not exist.
198
+ # causes to make following directories, if they do not exist.
189
199
#
190
200
# * /usr
191
201
# * /usr/local
@@ -249,7 +259,7 @@ def fu_mkdir(path, mode) #:nodoc:
249
259
# FileUtils.rmdir 'somedir'
250
260
# FileUtils.rmdir %w(somedir anydir otherdir)
251
261
# # Does not really remove directory; outputs message.
252
- # FileUtils.rmdir 'somedir', : verbose => true, : noop => true
262
+ # FileUtils.rmdir 'somedir', verbose: true, noop: true
253
263
#
254
264
def rmdir ( list , parents : nil , noop : nil , verbose : nil )
255
265
list = fu_list ( list )
@@ -278,7 +288,7 @@ def rmdir(list, parents: nil, noop: nil, verbose: nil)
278
288
#
279
289
# In the first form, creates a hard link +link+ which points to +target+.
280
290
# If +link+ already exists, raises Errno::EEXIST.
281
- # But if the : force option is set, overwrites +link+.
291
+ # But if the + force+ option is set, overwrites +link+.
282
292
#
283
293
# FileUtils.ln 'gcc', 'cc', verbose: true
284
294
# FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs'
@@ -304,23 +314,23 @@ def ln(src, dest, force: nil, noop: nil, verbose: nil)
304
314
alias link ln
305
315
module_function :link
306
316
307
- #
308
- # :call-seq:
309
- # FileUtils.cp_lr(src, dest, noop: nil, verbose: nil, dereference_root: true, remove_destination: false)
310
317
#
311
318
# Hard link +src+ to +dest+. If +src+ is a directory, this method links
312
319
# all its contents recursively. If +dest+ is a directory, links
313
320
# +src+ to +dest/src+.
314
321
#
315
322
# +src+ can be a list of files.
316
323
#
317
- # # Installing the library "mylib" under the site_ruby directory.
318
- # FileUtils.rm_r site_ruby + '/mylib', :force => true
324
+ # If +dereference_root+ is true, this method dereference tree root.
325
+ #
326
+ # If +remove_destination+ is true, this method removes each destination file before copy.
327
+ #
328
+ # FileUtils.rm_r site_ruby + '/mylib', force: true
319
329
# FileUtils.cp_lr 'lib/', site_ruby + '/mylib'
320
330
#
321
331
# # Examples of linking several files to target directory.
322
332
# FileUtils.cp_lr %w(mail.rb field.rb debug/), site_ruby + '/tmail'
323
- # FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', : noop => true, : verbose => true
333
+ # FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', noop: true, verbose: true
324
334
#
325
335
# # If you want to link all contents of a directory instead of the
326
336
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
@@ -345,7 +355,7 @@ def cp_lr(src, dest, noop: nil, verbose: nil,
345
355
#
346
356
# In the first form, creates a symbolic link +link+ which points to +target+.
347
357
# If +link+ already exists, raises Errno::EEXIST.
348
- # But if the : force option is set, overwrites +link+.
358
+ # But if the <tt> force</tt> option is set, overwrites +link+.
349
359
#
350
360
# FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
351
361
# FileUtils.ln_s 'verylongsourcefilename.c', 'c', force: true
@@ -411,7 +421,7 @@ def link_entry(src, dest, dereference_root = false, remove_destination = false)
411
421
#
412
422
# FileUtils.cp 'eval.c', 'eval.c.org'
413
423
# FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
414
- # FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', : verbose => true
424
+ # FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', verbose: true
415
425
# FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink
416
426
#
417
427
def cp ( src , dest , preserve : nil , noop : nil , verbose : nil )
@@ -433,13 +443,17 @@ def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
433
443
#
434
444
# +src+ can be a list of files.
435
445
#
446
+ # If +dereference_root+ is true, this method dereference tree root.
447
+ #
448
+ # If +remove_destination+ is true, this method removes each destination file before copy.
449
+ #
436
450
# # Installing Ruby library "mylib" under the site_ruby
437
- # FileUtils.rm_r site_ruby + '/mylib', : force
451
+ # FileUtils.rm_r site_ruby + '/mylib', force: true
438
452
# FileUtils.cp_r 'lib/', site_ruby + '/mylib'
439
453
#
440
454
# # Examples of copying several files to target directory.
441
455
# FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
442
- # FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', : noop => true, : verbose => true
456
+ # FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', noop: true, verbose: true
443
457
#
444
458
# # If you want to copy all contents of a directory instead of the
445
459
# # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
@@ -511,10 +525,10 @@ def copy_stream(src, dest)
511
525
# disk partition, the file is copied then the original file is removed.
512
526
#
513
527
# FileUtils.mv 'badname.rb', 'goodname.rb'
514
- # FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', : force => true # no error
528
+ # FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', force: true # no error
515
529
#
516
530
# FileUtils.mv %w(junk.txt dust.txt), '/home/foo/.trash/'
517
- # FileUtils.mv Dir.glob('test*.rb'), 'test', : noop => true, : verbose => true
531
+ # FileUtils.mv Dir.glob('test*.rb'), 'test', noop: true, verbose: true
518
532
#
519
533
def mv ( src , dest , force : nil , noop : nil , verbose : nil , secure : nil )
520
534
fu_output_message "mv#{ force ? ' -f' : '' } #{ [ src , dest ] . flatten . join ' ' } " if verbose
@@ -553,7 +567,7 @@ def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil)
553
567
#
554
568
# FileUtils.rm %w( junk.txt dust.txt )
555
569
# FileUtils.rm Dir.glob('*.so')
556
- # FileUtils.rm 'NotExistFile', : force => true # never raises exception
570
+ # FileUtils.rm 'NotExistFile', force: true # never raises exception
557
571
#
558
572
def rm ( list , force : nil , noop : nil , verbose : nil )
559
573
list = fu_list ( list )
@@ -572,7 +586,7 @@ def rm(list, force: nil, noop: nil, verbose: nil)
572
586
#
573
587
# Equivalent to
574
588
#
575
- # FileUtils.rm(list, : force => true)
589
+ # FileUtils.rm(list, force: true)
576
590
#
577
591
def rm_f ( list , noop : nil , verbose : nil )
578
592
rm list , force : true , noop : noop , verbose : verbose
@@ -588,18 +602,18 @@ def rm_f(list, noop: nil, verbose: nil)
588
602
# StandardError when :force option is set.
589
603
#
590
604
# FileUtils.rm_r Dir.glob('/tmp/*')
591
- # FileUtils.rm_r 'some_dir', : force => true
605
+ # FileUtils.rm_r 'some_dir', force: true
592
606
#
593
607
# WARNING: This method causes local vulnerability
594
608
# if one of parent directories or removing directory tree are world
595
609
# writable (including /tmp, whose permission is 1777), and the current
596
610
# process has strong privilege such as Unix super user (root), and the
597
611
# system has symbolic link. For secure removing, read the documentation
598
- # of # remove_entry_secure carefully, and set :secure option to true.
599
- # Default is :secure=> false.
612
+ # of remove_entry_secure carefully, and set :secure option to true.
613
+ # Default is <tt>secure: false</tt> .
600
614
#
601
- # NOTE: This method calls # remove_entry_secure if :secure option is set.
602
- # See also # remove_entry_secure.
615
+ # NOTE: This method calls remove_entry_secure if :secure option is set.
616
+ # See also remove_entry_secure.
603
617
#
604
618
def rm_r ( list , force : nil , noop : nil , verbose : nil , secure : nil )
605
619
list = fu_list ( list )
@@ -618,10 +632,10 @@ def rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil)
618
632
#
619
633
# Equivalent to
620
634
#
621
- # FileUtils.rm_r(list, : force => true)
635
+ # FileUtils.rm_r(list, force: true)
622
636
#
623
637
# WARNING: This method causes local vulnerability.
624
- # Read the documentation of # rm_r first.
638
+ # Read the documentation of rm_r first.
625
639
#
626
640
def rm_rf ( list , noop : nil , verbose : nil , secure : nil )
627
641
rm_r list , force : true , noop : noop , verbose : verbose , secure : secure
@@ -635,7 +649,7 @@ def rm_rf(list, noop: nil, verbose: nil, secure: nil)
635
649
# This method removes a file system entry +path+. +path+ shall be a
636
650
# regular file, a directory, or something. If +path+ is a directory,
637
651
# remove it recursively. This method is required to avoid TOCTTOU
638
- # (time-of-check-to-time-of-use) local security vulnerability of # rm_r.
652
+ # (time-of-check-to-time-of-use) local security vulnerability of rm_r.
639
653
# #rm_r causes security hole when:
640
654
#
641
655
# * Parent directory is world writable (including /tmp).
@@ -754,7 +768,7 @@ def fu_stat_identical_entry?(a, b) #:nodoc:
754
768
# +path+ might be a regular file, a directory, or something.
755
769
# If +path+ is a directory, remove it recursively.
756
770
#
757
- # See also # remove_entry_secure.
771
+ # See also remove_entry_secure.
758
772
#
759
773
def remove_entry ( path , force = false )
760
774
Entry_ . new ( path ) . postorder_traverse do |ent |
@@ -838,8 +852,8 @@ def compare_stream(a, b)
838
852
# mode to +mode+. If +dest+ is a directory, destination is +dest+/+src+.
839
853
# This method removes destination before copy.
840
854
#
841
- # FileUtils.install 'ruby', '/usr/local/bin/ruby', : mode => 0755, : verbose => true
842
- # FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', : verbose => true
855
+ # FileUtils.install 'ruby', '/usr/local/bin/ruby', mode: 0755, verbose: true
856
+ # FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', verbose: true
843
857
#
844
858
def install ( src , dest , mode : nil , owner : nil , group : nil , preserve : nil ,
845
859
noop : nil , verbose : nil )
@@ -969,12 +983,12 @@ def mode_to_s(mode) #:nodoc:
969
983
# Absolute mode is
970
984
# FileUtils.chmod 0755, 'somecommand'
971
985
# FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb)
972
- # FileUtils.chmod 0755, '/usr/bin/ruby', : verbose => true
986
+ # FileUtils.chmod 0755, '/usr/bin/ruby', verbose: true
973
987
#
974
988
# Symbolic mode is
975
989
# FileUtils.chmod "u=wrx,go=rx", 'somecommand'
976
990
# FileUtils.chmod "u=wr,go=rr", %w(my.rb your.rb his.rb her.rb)
977
- # FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', : verbose => true
991
+ # FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', verbose: true
978
992
#
979
993
# "a" :: is user, group, other mask.
980
994
# "u" :: is user's mask.
@@ -1034,7 +1048,7 @@ def chmod_R(mode, list, noop: nil, verbose: nil, force: nil)
1034
1048
# the attribute.
1035
1049
#
1036
1050
# FileUtils.chown 'root', 'staff', '/usr/local/bin/ruby'
1037
- # FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), : verbose => true
1051
+ # FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), verbose: true
1038
1052
#
1039
1053
def chown ( user , group , list , noop : nil , verbose : nil )
1040
1054
list = fu_list ( list )
@@ -1058,7 +1072,7 @@ def chown(user, group, list, noop: nil, verbose: nil)
1058
1072
# method does not change the attribute.
1059
1073
#
1060
1074
# FileUtils.chown_R 'www', 'www', '/var/www/htdocs'
1061
- # FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', : verbose => true
1075
+ # FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', verbose: true
1062
1076
#
1063
1077
def chown_R ( user , group , list , noop : nil , verbose : nil , force : nil )
1064
1078
list = fu_list ( list )
@@ -1607,8 +1621,11 @@ def fu_output_message(msg) #:nodoc:
1607
1621
tbl
1608
1622
}
1609
1623
1624
+ public
1625
+
1610
1626
#
1611
- # Returns an Array of method names which have any options.
1627
+ # Returns an Array of names of high-level methods that accept any keyword
1628
+ # arguments.
1612
1629
#
1613
1630
# p FileUtils.commands #=> ["chmod", "cp", "cp_r", "install", ...]
1614
1631
#
@@ -1647,22 +1664,24 @@ def self.options_of(mid)
1647
1664
end
1648
1665
1649
1666
#
1650
- # Returns an Array of method names which have the option +opt+.
1667
+ # Returns an Array of methods names which have the option +opt+.
1651
1668
#
1652
1669
# p FileUtils.collect_method(:preserve) #=> ["cp", "cp_r", "copy", "install"]
1653
1670
#
1654
1671
def self . collect_method ( opt )
1655
1672
OPT_TABLE . keys . select { |m | OPT_TABLE [ m ] . include? ( opt ) }
1656
1673
end
1657
1674
1658
- LOW_METHODS = singleton_methods ( false ) - collect_method ( :noop ) . map ( &:intern )
1659
- module LowMethods
1675
+ private
1676
+
1677
+ LOW_METHODS = singleton_methods ( false ) - collect_method ( :noop ) . map ( &:intern ) # :nodoc:
1678
+ module LowMethods # :nodoc: internal use only
1660
1679
private
1661
1680
def _do_nothing ( *) end
1662
1681
::FileUtils ::LOW_METHODS . map { |name | alias_method name , :_do_nothing }
1663
1682
end
1664
1683
1665
- METHODS = singleton_methods ( ) - [ :private_module_function ,
1684
+ METHODS = singleton_methods ( ) - [ :private_module_function , # :nodoc:
1666
1685
:commands , :options , :have_option? , :options_of , :collect_method ]
1667
1686
1668
1687
#
0 commit comments