fileutils 1.1.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0aee7f293ec6d29fa463553496d041a986ddfb407fe3ea8788da72a5e5be089
4
- data.tar.gz: 2e1a5e8678e34ef6cb8caf57c474035052da6985746212040eeae58d6b06f094
3
+ metadata.gz: 67fa33577498dff5705331ce6453a3c11ff34d209343310f647d4cb404158617
4
+ data.tar.gz: 4608e153f0c69749fbf7e4d456388c44fdba1a3a99f5b328c71c283ccd7ca5a3
5
5
  SHA512:
6
- metadata.gz: 98dc33148493bef27a911a73f78f825de57929ad8eb3e3e9c47c40dbadb139c74b044011f78129b651155e8c2478266af5713f4e491765a351270e2cdecc8db4
7
- data.tar.gz: 6209a27261211f2f724d51fd9abc0a6729023d0c7354f982c641d1b37670f7550b9a23b675cb8e49ada611cbdc794ceb5f7aa517bf4c9b71ed58ed3dc150d528
6
+ metadata.gz: db0b5ce907f782c5ba306ca0a8811c825ec1f97a47731ccc08b2ddc7e13160d7d40986afd1b744cef7b941b2bef2f1c1c4017eb8fc616e8695b506d5ce8cc8ae
7
+ data.tar.gz: ccbb52c0a277e03e29dfff22e5bb26b3dc30e7ede6db803f130047bb039cb12161d7f3ecafac5f0956959fde6276b16c68085f30be7c8edae019e7d313301b53
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # FileUtils
2
2
 
3
- [![Build Status](https://travis-ci.org/ruby/fileutils.svg?branch=master)](https://travis-ci.org/ruby/fileutils)
4
-
5
3
  Namespace for several file utility methods for copying, moving, removing, etc.
6
4
 
7
5
  ## Installation
data/Rakefile CHANGED
@@ -4,9 +4,16 @@ require "rake/testtask"
4
4
  JRuby.objectspace = true if RUBY_PLATFORM == 'java'
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
- t.libs << "test" << "test/lib"
8
- t.libs << "lib"
9
- t.test_files = FileList['test/**/test_*.rb']
7
+ t.libs << "test/lib"
8
+ t.ruby_opts << "-rhelper"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task :sync_tool do
13
+ require 'fileutils'
14
+ FileUtils.cp "../ruby/tool/lib/test/unit/core_assertions.rb", "./test/lib"
15
+ FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
16
+ FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
10
17
  end
11
18
 
12
19
  task :default => :test
@@ -1,25 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ source_version = ["", "lib/"].find do |dir|
4
+ begin
5
+ break File.open(File.join(__dir__, "#{dir}fileutils.rb")) {|f|
6
+ f.gets("\n VERSION = ")
7
+ f.gets[/\s*"(.+)"/, 1]
8
+ }
9
+ rescue Errno::ENOENT
10
+ end
11
+ end
12
+
3
13
  Gem::Specification.new do |s|
4
14
  s.name = "fileutils"
5
- s.version = '1.1.0'
15
+ s.version = source_version
6
16
  s.summary = "Several file utility methods for copying, moving, removing, etc."
7
17
  s.description = "Several file utility methods for copying, moving, removing, etc."
8
18
 
9
19
  s.require_path = %w{lib}
10
- s.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "fileutils.gemspec", "lib/fileutils.rb"]
20
+ s.files = ["LICENSE.txt", "README.md", "Rakefile", "fileutils.gemspec", "lib/fileutils.rb"]
11
21
  s.required_ruby_version = ">= 2.3.0"
12
22
 
13
23
  s.authors = ["Minero Aoki"]
14
24
  s.email = [nil]
15
25
  s.homepage = "https://github.com/ruby/fileutils"
16
- s.license = "BSD-2-Clause"
17
-
18
- if s.respond_to?(:metadata=)
19
- s.metadata = {
20
- "source_code_uri" => "https://github.com/ruby/fileutils"
21
- }
22
- end
26
+ s.licenses = ["Ruby", "BSD-2-Clause"]
23
27
 
24
- s.add_development_dependency 'rake'
28
+ s.metadata = {
29
+ "source_code_uri" => "https://github.com/ruby/fileutils"
30
+ }
25
31
  end
@@ -1,4 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'rbconfig'
5
+ rescue LoadError
6
+ # for make mjit-headers
7
+ end
8
+
2
9
  #
3
10
  # = fileutils.rb
4
11
  #
@@ -15,48 +22,58 @@
15
22
  #
16
23
  # require 'fileutils'
17
24
  #
18
- # FileUtils.cd(dir, options)
19
- # FileUtils.cd(dir, options) {|dir| block }
25
+ # FileUtils.cd(dir, **options)
26
+ # FileUtils.cd(dir, **options) {|dir| block }
20
27
  # FileUtils.pwd()
21
- # FileUtils.mkdir(dir, options)
22
- # FileUtils.mkdir(list, options)
23
- # FileUtils.mkdir_p(dir, options)
24
- # FileUtils.mkdir_p(list, options)
25
- # FileUtils.rmdir(dir, options)
26
- # FileUtils.rmdir(list, options)
27
- # FileUtils.ln(target, link, options)
28
- # FileUtils.ln(targets, dir, options)
29
- # FileUtils.ln_s(target, link, options)
30
- # FileUtils.ln_s(targets, dir, options)
31
- # FileUtils.ln_sf(target, link, options)
32
- # FileUtils.cp(src, dest, options)
33
- # FileUtils.cp(list, dir, options)
34
- # FileUtils.cp_r(src, dest, options)
35
- # FileUtils.cp_r(list, dir, options)
36
- # FileUtils.mv(src, dest, options)
37
- # FileUtils.mv(list, dir, options)
38
- # FileUtils.rm(list, options)
39
- # FileUtils.rm_r(list, options)
40
- # FileUtils.rm_rf(list, options)
41
- # FileUtils.install(src, dest, options)
42
- # FileUtils.chmod(mode, list, options)
43
- # FileUtils.chmod_R(mode, list, options)
44
- # FileUtils.chown(user, group, list, options)
45
- # FileUtils.chown_R(user, group, list, options)
46
- # FileUtils.touch(list, options)
28
+ # FileUtils.mkdir(dir, **options)
29
+ # FileUtils.mkdir(list, **options)
30
+ # FileUtils.mkdir_p(dir, **options)
31
+ # FileUtils.mkdir_p(list, **options)
32
+ # FileUtils.rmdir(dir, **options)
33
+ # FileUtils.rmdir(list, **options)
34
+ # FileUtils.ln(target, link, **options)
35
+ # FileUtils.ln(targets, dir, **options)
36
+ # FileUtils.ln_s(target, link, **options)
37
+ # FileUtils.ln_s(targets, dir, **options)
38
+ # FileUtils.ln_sf(target, link, **options)
39
+ # FileUtils.cp(src, dest, **options)
40
+ # FileUtils.cp(list, dir, **options)
41
+ # FileUtils.cp_r(src, dest, **options)
42
+ # FileUtils.cp_r(list, dir, **options)
43
+ # FileUtils.mv(src, dest, **options)
44
+ # FileUtils.mv(list, dir, **options)
45
+ # FileUtils.rm(list, **options)
46
+ # FileUtils.rm_r(list, **options)
47
+ # FileUtils.rm_rf(list, **options)
48
+ # FileUtils.install(src, dest, **options)
49
+ # FileUtils.chmod(mode, list, **options)
50
+ # FileUtils.chmod_R(mode, list, **options)
51
+ # FileUtils.chown(user, group, list, **options)
52
+ # FileUtils.chown_R(user, group, list, **options)
53
+ # FileUtils.touch(list, **options)
47
54
  #
48
- # The <tt>options</tt> parameter is a hash of options, taken from the list
49
- # <tt>:force</tt>, <tt>:noop</tt>, <tt>:preserve</tt>, and <tt>:verbose</tt>.
50
- # <tt>:noop</tt> means that no changes are made. The other three are obvious.
51
- # Each method documents the options that it honours.
55
+ # Possible <tt>options</tt> are:
56
+ #
57
+ # <tt>:force</tt> :: forced operation (rewrite files if exist, remove
58
+ # directories if not empty, etc.);
59
+ # <tt>:verbose</tt> :: print command to be run, in bash syntax, before
60
+ # performing it;
61
+ # <tt>:preserve</tt> :: preserve object's group, user and modification
62
+ # time on copying;
63
+ # <tt>:noop</tt> :: no changes are made (usable in combination with
64
+ # <tt>:verbose</tt> which will print the command to run)
65
+ #
66
+ # Each method documents the options that it honours. See also ::commands,
67
+ # ::options and ::options_of methods to introspect which command have which
68
+ # options.
52
69
  #
53
70
  # All methods that have the concept of a "source" file or directory can take
54
71
  # either one file or a list of files in that argument. See the method
55
72
  # documentation for examples.
56
73
  #
57
- # There are some `low level' methods, which do not accept any option:
74
+ # There are some `low level' methods, which do not accept keyword arguments:
58
75
  #
59
- # FileUtils.copy_entry(src, dest, preserve = false, dereference = false)
76
+ # FileUtils.copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
60
77
  # FileUtils.copy_file(src, dest, preserve = false, dereference = true)
61
78
  # FileUtils.copy_stream(srcstream, deststream)
62
79
  # FileUtils.remove_entry(path, force = false)
@@ -84,12 +101,8 @@
84
101
  # files/directories. This equates to passing the <tt>:noop</tt> and
85
102
  # <tt>:verbose</tt> flags to methods in FileUtils.
86
103
  #
87
-
88
- require 'rbconfig'
89
-
90
104
  module FileUtils
91
-
92
- VERSION = "1.1.0"
105
+ VERSION = "1.5.0"
93
106
 
94
107
  def self.private_module_function(name) #:nodoc:
95
108
  module_function name
@@ -110,12 +123,14 @@ module FileUtils
110
123
  #
111
124
  # Changes the current directory to the directory +dir+.
112
125
  #
113
- # If this method is called with block, resumes to the old
114
- # working directory after the block execution finished.
126
+ # If this method is called with block, resumes to the previous
127
+ # working directory after the block execution has finished.
128
+ #
129
+ # FileUtils.cd('/') # change directory
115
130
  #
116
- # FileUtils.cd('/', :verbose => true) # chdir and report it
131
+ # FileUtils.cd('/', verbose: true) # change directory and report it
117
132
  #
118
- # FileUtils.cd('/') do # chdir
133
+ # FileUtils.cd('/') do # change directory
119
134
  # # ... # do something
120
135
  # end # return to original directory
121
136
  #
@@ -158,9 +173,9 @@ module FileUtils
158
173
  # Creates one or more directories.
159
174
  #
160
175
  # FileUtils.mkdir 'test'
161
- # FileUtils.mkdir %w( tmp data )
162
- # FileUtils.mkdir 'notexist', :noop => true # Does not really create.
163
- # FileUtils.mkdir 'tmp', :mode => 0700
176
+ # FileUtils.mkdir %w(tmp data)
177
+ # FileUtils.mkdir 'notexist', noop: true # Does not really create.
178
+ # FileUtils.mkdir 'tmp', mode: 0700
164
179
  #
165
180
  def mkdir(list, mode: nil, noop: nil, verbose: nil)
166
181
  list = fu_list(list)
@@ -179,7 +194,7 @@ module FileUtils
179
194
  #
180
195
  # FileUtils.mkdir_p '/usr/local/lib/ruby'
181
196
  #
182
- # causes to make following directories, if it does not exist.
197
+ # causes to make following directories, if they do not exist.
183
198
  #
184
199
  # * /usr
185
200
  # * /usr/local
@@ -193,7 +208,9 @@ module FileUtils
193
208
  fu_output_message "mkdir -p #{mode ? ('-m %03o ' % mode) : ''}#{list.join ' '}" if verbose
194
209
  return *list if noop
195
210
 
196
- list.map {|path| remove_trailing_slash(path)}.each do |path|
211
+ list.each do |item|
212
+ path = remove_trailing_slash(item)
213
+
197
214
  # optimize for the most common case
198
215
  begin
199
216
  fu_mkdir path, mode
@@ -206,8 +223,9 @@ module FileUtils
206
223
  until path == stack.last # dirname("/")=="/", dirname("C:/")=="C:/"
207
224
  stack.push path
208
225
  path = File.dirname(path)
226
+ break if File.directory?(path)
209
227
  end
210
- stack.pop # root directory should exist
228
+ stack.pop if path == stack.last # root directory should exist
211
229
  stack.reverse_each do |dir|
212
230
  begin
213
231
  fu_mkdir dir, mode
@@ -243,7 +261,7 @@ module FileUtils
243
261
  # FileUtils.rmdir 'somedir'
244
262
  # FileUtils.rmdir %w(somedir anydir otherdir)
245
263
  # # Does not really remove directory; outputs message.
246
- # FileUtils.rmdir 'somedir', :verbose => true, :noop => true
264
+ # FileUtils.rmdir 'somedir', verbose: true, noop: true
247
265
  #
248
266
  def rmdir(list, parents: nil, noop: nil, verbose: nil)
249
267
  list = fu_list(list)
@@ -272,7 +290,7 @@ module FileUtils
272
290
  #
273
291
  # In the first form, creates a hard link +link+ which points to +target+.
274
292
  # If +link+ already exists, raises Errno::EEXIST.
275
- # But if the :force option is set, overwrites +link+.
293
+ # But if the +force+ option is set, overwrites +link+.
276
294
  #
277
295
  # FileUtils.ln 'gcc', 'cc', verbose: true
278
296
  # FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs'
@@ -298,9 +316,6 @@ module FileUtils
298
316
  alias link ln
299
317
  module_function :link
300
318
 
301
- #
302
- # :call-seq:
303
- # FileUtils.cp_lr(src, dest, noop: nil, verbose: nil, dereference_root: true, remove_destination: false)
304
319
  #
305
320
  # Hard link +src+ to +dest+. If +src+ is a directory, this method links
306
321
  # all its contents recursively. If +dest+ is a directory, links
@@ -308,13 +323,16 @@ module FileUtils
308
323
  #
309
324
  # +src+ can be a list of files.
310
325
  #
311
- # # Installing the library "mylib" under the site_ruby directory.
312
- # FileUtils.rm_r site_ruby + '/mylib', :force => true
326
+ # If +dereference_root+ is true, this method dereference tree root.
327
+ #
328
+ # If +remove_destination+ is true, this method removes each destination file before copy.
329
+ #
330
+ # FileUtils.rm_r site_ruby + '/mylib', force: true
313
331
  # FileUtils.cp_lr 'lib/', site_ruby + '/mylib'
314
332
  #
315
333
  # # Examples of linking several files to target directory.
316
334
  # FileUtils.cp_lr %w(mail.rb field.rb debug/), site_ruby + '/tmail'
317
- # FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true
335
+ # FileUtils.cp_lr Dir.glob('*.rb'), '/home/aamine/lib/ruby', noop: true, verbose: true
318
336
  #
319
337
  # # If you want to link all contents of a directory instead of the
320
338
  # # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
@@ -339,7 +357,7 @@ module FileUtils
339
357
  #
340
358
  # In the first form, creates a symbolic link +link+ which points to +target+.
341
359
  # If +link+ already exists, raises Errno::EEXIST.
342
- # But if the :force option is set, overwrites +link+.
360
+ # But if the <tt>force</tt> option is set, overwrites +link+.
343
361
  #
344
362
  # FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
345
363
  # FileUtils.ln_s 'verylongsourcefilename.c', 'c', force: true
@@ -405,7 +423,7 @@ module FileUtils
405
423
  #
406
424
  # FileUtils.cp 'eval.c', 'eval.c.org'
407
425
  # FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
408
- # FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', :verbose => true
426
+ # FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', verbose: true
409
427
  # FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink
410
428
  #
411
429
  def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
@@ -427,13 +445,17 @@ module FileUtils
427
445
  #
428
446
  # +src+ can be a list of files.
429
447
  #
448
+ # If +dereference_root+ is true, this method dereference tree root.
449
+ #
450
+ # If +remove_destination+ is true, this method removes each destination file before copy.
451
+ #
430
452
  # # Installing Ruby library "mylib" under the site_ruby
431
- # FileUtils.rm_r site_ruby + '/mylib', :force
453
+ # FileUtils.rm_r site_ruby + '/mylib', force: true
432
454
  # FileUtils.cp_r 'lib/', site_ruby + '/mylib'
433
455
  #
434
456
  # # Examples of copying several files to target directory.
435
457
  # FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
436
- # FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', :noop => true, :verbose => true
458
+ # FileUtils.cp_r Dir.glob('*.rb'), '/home/foo/lib/ruby', noop: true, verbose: true
437
459
  #
438
460
  # # If you want to copy all contents of a directory instead of the
439
461
  # # directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
@@ -468,7 +490,11 @@ module FileUtils
468
490
  # If +remove_destination+ is true, this method removes each destination file before copy.
469
491
  #
470
492
  def copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
471
- Entry_.new(src, nil, dereference_root).wrap_traverse(proc do |ent|
493
+ if dereference_root
494
+ src = File.realpath(src)
495
+ end
496
+
497
+ Entry_.new(src, nil, false).wrap_traverse(proc do |ent|
472
498
  destent = Entry_.new(dest, ent.rel, false)
473
499
  File.unlink destent.path if remove_destination && (File.file?(destent.path) || File.symlink?(destent.path))
474
500
  ent.copy destent.path
@@ -505,10 +531,10 @@ module FileUtils
505
531
  # disk partition, the file is copied then the original file is removed.
506
532
  #
507
533
  # FileUtils.mv 'badname.rb', 'goodname.rb'
508
- # FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', :force => true # no error
534
+ # FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', force: true # no error
509
535
  #
510
536
  # FileUtils.mv %w(junk.txt dust.txt), '/home/foo/.trash/'
511
- # FileUtils.mv Dir.glob('test*.rb'), 'test', :noop => true, :verbose => true
537
+ # FileUtils.mv Dir.glob('test*.rb'), 'test', noop: true, verbose: true
512
538
  #
513
539
  def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil)
514
540
  fu_output_message "mv#{force ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if verbose
@@ -519,13 +545,12 @@ module FileUtils
519
545
  if destent.exist?
520
546
  if destent.directory?
521
547
  raise Errno::EEXIST, d
522
- else
523
- destent.remove_file if rename_cannot_overwrite_file?
524
548
  end
525
549
  end
526
550
  begin
527
551
  File.rename s, d
528
- rescue Errno::EXDEV
552
+ rescue Errno::EXDEV,
553
+ Errno::EPERM # move from unencrypted to encrypted dir (ext4)
529
554
  copy_entry s, d, true
530
555
  if secure
531
556
  remove_entry_secure s, force
@@ -543,18 +568,13 @@ module FileUtils
543
568
  alias move mv
544
569
  module_function :move
545
570
 
546
- def rename_cannot_overwrite_file? #:nodoc:
547
- /emx/ =~ RbConfig::CONFIG['host_os']
548
- end
549
- private_module_function :rename_cannot_overwrite_file?
550
-
551
571
  #
552
572
  # Remove file(s) specified in +list+. This method cannot remove directories.
553
573
  # All StandardErrors are ignored when the :force option is set.
554
574
  #
555
575
  # FileUtils.rm %w( junk.txt dust.txt )
556
576
  # FileUtils.rm Dir.glob('*.so')
557
- # FileUtils.rm 'NotExistFile', :force => true # never raises exception
577
+ # FileUtils.rm 'NotExistFile', force: true # never raises exception
558
578
  #
559
579
  def rm(list, force: nil, noop: nil, verbose: nil)
560
580
  list = fu_list(list)
@@ -573,7 +593,7 @@ module FileUtils
573
593
  #
574
594
  # Equivalent to
575
595
  #
576
- # FileUtils.rm(list, :force => true)
596
+ # FileUtils.rm(list, force: true)
577
597
  #
578
598
  def rm_f(list, noop: nil, verbose: nil)
579
599
  rm list, force: true, noop: noop, verbose: verbose
@@ -589,18 +609,18 @@ module FileUtils
589
609
  # StandardError when :force option is set.
590
610
  #
591
611
  # FileUtils.rm_r Dir.glob('/tmp/*')
592
- # FileUtils.rm_r 'some_dir', :force => true
612
+ # FileUtils.rm_r 'some_dir', force: true
593
613
  #
594
614
  # WARNING: This method causes local vulnerability
595
615
  # if one of parent directories or removing directory tree are world
596
616
  # writable (including /tmp, whose permission is 1777), and the current
597
617
  # process has strong privilege such as Unix super user (root), and the
598
618
  # system has symbolic link. For secure removing, read the documentation
599
- # of #remove_entry_secure carefully, and set :secure option to true.
600
- # Default is :secure=>false.
619
+ # of remove_entry_secure carefully, and set :secure option to true.
620
+ # Default is <tt>secure: false</tt>.
601
621
  #
602
- # NOTE: This method calls #remove_entry_secure if :secure option is set.
603
- # See also #remove_entry_secure.
622
+ # NOTE: This method calls remove_entry_secure if :secure option is set.
623
+ # See also remove_entry_secure.
604
624
  #
605
625
  def rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil)
606
626
  list = fu_list(list)
@@ -619,10 +639,10 @@ module FileUtils
619
639
  #
620
640
  # Equivalent to
621
641
  #
622
- # FileUtils.rm_r(list, :force => true)
642
+ # FileUtils.rm_r(list, force: true)
623
643
  #
624
644
  # WARNING: This method causes local vulnerability.
625
- # Read the documentation of #rm_r first.
645
+ # Read the documentation of rm_r first.
626
646
  #
627
647
  def rm_rf(list, noop: nil, verbose: nil, secure: nil)
628
648
  rm_r list, force: true, noop: noop, verbose: verbose, secure: secure
@@ -636,7 +656,7 @@ module FileUtils
636
656
  # This method removes a file system entry +path+. +path+ shall be a
637
657
  # regular file, a directory, or something. If +path+ is a directory,
638
658
  # remove it recursively. This method is required to avoid TOCTTOU
639
- # (time-of-check-to-time-of-use) local security vulnerability of #rm_r.
659
+ # (time-of-check-to-time-of-use) local security vulnerability of rm_r.
640
660
  # #rm_r causes security hole when:
641
661
  #
642
662
  # * Parent directory is world writable (including /tmp).
@@ -698,7 +718,7 @@ module FileUtils
698
718
  f.chown euid, -1
699
719
  f.chmod 0700
700
720
  }
701
- rescue EISDIR # JRuby in non-native mode can't open files as dirs
721
+ rescue Errno::EISDIR # JRuby in non-native mode can't open files as dirs
702
722
  File.lstat(dot_file).tap {|fstat|
703
723
  unless fu_stat_identical_entry?(st, fstat)
704
724
  # symlink (TOC-to-TOU attack?)
@@ -755,7 +775,7 @@ module FileUtils
755
775
  # +path+ might be a regular file, a directory, or something.
756
776
  # If +path+ is a directory, remove it recursively.
757
777
  #
758
- # See also #remove_entry_secure.
778
+ # See also remove_entry_secure.
759
779
  #
760
780
  def remove_entry(path, force = false)
761
781
  Entry_.new(path).postorder_traverse do |ent|
@@ -839,8 +859,8 @@ module FileUtils
839
859
  # mode to +mode+. If +dest+ is a directory, destination is +dest+/+src+.
840
860
  # This method removes destination before copy.
841
861
  #
842
- # FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true
843
- # FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true
862
+ # FileUtils.install 'ruby', '/usr/local/bin/ruby', mode: 0755, verbose: true
863
+ # FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', verbose: true
844
864
  #
845
865
  def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil,
846
866
  noop: nil, verbose: nil)
@@ -900,11 +920,8 @@ module FileUtils
900
920
  private_module_function :apply_mask
901
921
 
902
922
  def symbolic_modes_to_i(mode_sym, path) #:nodoc:
903
- mode = if File::Stat === path
904
- path.mode
905
- else
906
- File.stat(path).mode
907
- end
923
+ path = File.stat(path) unless File::Stat === path
924
+ mode = path.mode
908
925
  mode_sym.split(/,/).inject(mode & 07777) do |current_mode, clause|
909
926
  target, *actions = clause.split(/([=+-])/)
910
927
  raise ArgumentError, "invalid file mode: #{mode_sym}" if actions.empty?
@@ -921,7 +938,7 @@ module FileUtils
921
938
  when "x"
922
939
  mask | 0111
923
940
  when "X"
924
- if FileTest.directory? path
941
+ if path.directory?
925
942
  mask | 0111
926
943
  else
927
944
  mask
@@ -970,12 +987,12 @@ module FileUtils
970
987
  # Absolute mode is
971
988
  # FileUtils.chmod 0755, 'somecommand'
972
989
  # FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb)
973
- # FileUtils.chmod 0755, '/usr/bin/ruby', :verbose => true
990
+ # FileUtils.chmod 0755, '/usr/bin/ruby', verbose: true
974
991
  #
975
992
  # Symbolic mode is
976
993
  # FileUtils.chmod "u=wrx,go=rx", 'somecommand'
977
994
  # FileUtils.chmod "u=wr,go=rr", %w(my.rb your.rb his.rb her.rb)
978
- # FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', :verbose => true
995
+ # FileUtils.chmod "u=wrx,go=rx", '/usr/bin/ruby', verbose: true
979
996
  #
980
997
  # "a" :: is user, group, other mask.
981
998
  # "u" :: is user's mask.
@@ -1035,7 +1052,7 @@ module FileUtils
1035
1052
  # the attribute.
1036
1053
  #
1037
1054
  # FileUtils.chown 'root', 'staff', '/usr/local/bin/ruby'
1038
- # FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), :verbose => true
1055
+ # FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), verbose: true
1039
1056
  #
1040
1057
  def chown(user, group, list, noop: nil, verbose: nil)
1041
1058
  list = fu_list(list)
@@ -1059,7 +1076,7 @@ module FileUtils
1059
1076
  # method does not change the attribute.
1060
1077
  #
1061
1078
  # FileUtils.chown_R 'www', 'www', '/var/www/htdocs'
1062
- # FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', :verbose => true
1079
+ # FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', verbose: true
1063
1080
  #
1064
1081
  def chown_R(user, group, list, noop: nil, verbose: nil, force: nil)
1065
1082
  list = fu_list(list)
@@ -1082,11 +1099,6 @@ module FileUtils
1082
1099
  end
1083
1100
  module_function :chown_R
1084
1101
 
1085
- begin
1086
- require 'etc'
1087
- rescue LoadError # rescue LoadError for miniruby
1088
- end
1089
-
1090
1102
  def fu_get_uid(user) #:nodoc:
1091
1103
  return nil unless user
1092
1104
  case user
@@ -1095,6 +1107,7 @@ module FileUtils
1095
1107
  when /\A\d+\z/
1096
1108
  user.to_i
1097
1109
  else
1110
+ require 'etc'
1098
1111
  Etc.getpwnam(user) ? Etc.getpwnam(user).uid : nil
1099
1112
  end
1100
1113
  end
@@ -1108,6 +1121,7 @@ module FileUtils
1108
1121
  when /\A\d+\z/
1109
1122
  group.to_i
1110
1123
  else
1124
+ require 'etc'
1111
1125
  Etc.getgrnam(group) ? Etc.getgrnam(group).gid : nil
1112
1126
  end
1113
1127
  end
@@ -1148,8 +1162,11 @@ module FileUtils
1148
1162
  module StreamUtils_
1149
1163
  private
1150
1164
 
1151
- def fu_windows?
1152
- /mswin|mingw|bccwin|emx/ =~ RbConfig::CONFIG['host_os']
1165
+ case (defined?(::RbConfig) ? ::RbConfig::CONFIG['host_os'] : ::RUBY_PLATFORM)
1166
+ when /mswin|mingw/
1167
+ def fu_windows?; true end
1168
+ else
1169
+ def fu_windows?; false end
1153
1170
  end
1154
1171
 
1155
1172
  def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
@@ -1273,10 +1290,17 @@ module FileUtils
1273
1290
 
1274
1291
  def entries
1275
1292
  opts = {}
1276
- opts[:encoding] = ::Encoding::UTF_8 if fu_windows?
1277
- Dir.entries(path(), opts)\
1278
- .reject {|n| n == '.' or n == '..' }\
1279
- .map {|n| Entry_.new(prefix(), join(rel(), n.untaint)) }
1293
+ opts[:encoding] = fu_windows? ? ::Encoding::UTF_8 : path.encoding
1294
+
1295
+ files = if Dir.respond_to?(:children)
1296
+ Dir.children(path, **opts)
1297
+ else
1298
+ Dir.entries(path(), **opts)
1299
+ .reject {|n| n == '.' or n == '..' }
1300
+ end
1301
+
1302
+ untaint = RUBY_VERSION < '2.7'
1303
+ files.map {|n| Entry_.new(prefix(), join(rel(), untaint ? n.untaint : n)) }
1280
1304
  end
1281
1305
 
1282
1306
  def stat
@@ -1321,6 +1345,7 @@ module FileUtils
1321
1345
  else
1322
1346
  File.chmod mode, path()
1323
1347
  end
1348
+ rescue Errno::EOPNOTSUPP
1324
1349
  end
1325
1350
 
1326
1351
  def chown(uid, gid)
@@ -1363,18 +1388,21 @@ module FileUtils
1363
1388
  end
1364
1389
  when symlink?
1365
1390
  File.symlink File.readlink(path()), dest
1366
- when chardev?
1367
- raise "cannot handle device file" unless File.respond_to?(:mknod)
1368
- mknod dest, ?c, 0666, lstat().rdev
1369
- when blockdev?
1370
- raise "cannot handle device file" unless File.respond_to?(:mknod)
1371
- mknod dest, ?b, 0666, lstat().rdev
1391
+ when chardev?, blockdev?
1392
+ raise "cannot handle device file"
1372
1393
  when socket?
1373
- raise "cannot handle socket" unless File.respond_to?(:mknod)
1374
- mknod dest, nil, lstat().mode, 0
1394
+ begin
1395
+ require 'socket'
1396
+ rescue LoadError
1397
+ raise "cannot handle socket"
1398
+ else
1399
+ raise "cannot handle socket" unless defined?(UNIXServer)
1400
+ end
1401
+ UNIXServer.new(dest).close
1402
+ File.chmod lstat().mode, dest
1375
1403
  when pipe?
1376
1404
  raise "cannot handle FIFO" unless File.respond_to?(:mkfifo)
1377
- mkfifo dest, 0666
1405
+ File.mkfifo dest, lstat().mode
1378
1406
  when door?
1379
1407
  raise "cannot handle door: #{path()}"
1380
1408
  else
@@ -1412,7 +1440,7 @@ module FileUtils
1412
1440
  if st.symlink?
1413
1441
  begin
1414
1442
  File.lchmod mode, path
1415
- rescue NotImplementedError
1443
+ rescue NotImplementedError, Errno::EOPNOTSUPP
1416
1444
  end
1417
1445
  else
1418
1446
  File.chmod mode, path
@@ -1493,14 +1521,14 @@ module FileUtils
1493
1521
 
1494
1522
  private
1495
1523
 
1496
- $fileutils_rb_have_lchmod = nil
1524
+ @@fileutils_rb_have_lchmod = nil
1497
1525
 
1498
1526
  def have_lchmod?
1499
1527
  # This is not MT-safe, but it does not matter.
1500
- if $fileutils_rb_have_lchmod == nil
1501
- $fileutils_rb_have_lchmod = check_have_lchmod?
1528
+ if @@fileutils_rb_have_lchmod == nil
1529
+ @@fileutils_rb_have_lchmod = check_have_lchmod?
1502
1530
  end
1503
- $fileutils_rb_have_lchmod
1531
+ @@fileutils_rb_have_lchmod
1504
1532
  end
1505
1533
 
1506
1534
  def check_have_lchmod?
@@ -1511,14 +1539,14 @@ module FileUtils
1511
1539
  return false
1512
1540
  end
1513
1541
 
1514
- $fileutils_rb_have_lchown = nil
1542
+ @@fileutils_rb_have_lchown = nil
1515
1543
 
1516
1544
  def have_lchown?
1517
1545
  # This is not MT-safe, but it does not matter.
1518
- if $fileutils_rb_have_lchown == nil
1519
- $fileutils_rb_have_lchown = check_have_lchown?
1546
+ if @@fileutils_rb_have_lchown == nil
1547
+ @@fileutils_rb_have_lchown = check_have_lchown?
1520
1548
  end
1521
- $fileutils_rb_have_lchown
1549
+ @@fileutils_rb_have_lchown
1522
1550
  end
1523
1551
 
1524
1552
  def check_have_lchown?
@@ -1532,7 +1560,15 @@ module FileUtils
1532
1560
  def join(dir, base)
1533
1561
  return File.path(dir) if not base or base == '.'
1534
1562
  return File.path(base) if not dir or dir == '.'
1535
- File.join(dir, base)
1563
+ begin
1564
+ File.join(dir, base)
1565
+ rescue EncodingError
1566
+ if fu_windows?
1567
+ File.join(dir.encode(::Encoding::UTF_8), base.encode(::Encoding::UTF_8))
1568
+ else
1569
+ raise
1570
+ end
1571
+ end
1536
1572
  end
1537
1573
 
1538
1574
  if File::ALT_SEPARATOR
@@ -1540,10 +1576,13 @@ module FileUtils
1540
1576
  else
1541
1577
  DIRECTORY_TERM = "(?=/|\\z)"
1542
1578
  end
1543
- SYSCASE = File::FNM_SYSCASE.nonzero? ? "-i" : ""
1544
1579
 
1545
1580
  def descendant_directory?(descendant, ascendant)
1546
- /\A(?#{SYSCASE}:#{Regexp.quote(ascendant)})#{DIRECTORY_TERM}/ =~ File.dirname(descendant)
1581
+ if File::FNM_SYSCASE.nonzero?
1582
+ File.expand_path(File.dirname(descendant)).casecmp(File.expand_path(ascendant)) == 0
1583
+ else
1584
+ File.expand_path(File.dirname(descendant)) == File.expand_path(ascendant)
1585
+ end
1547
1586
  end
1548
1587
  end # class Entry_
1549
1588
 
@@ -1582,13 +1621,13 @@ module FileUtils
1582
1621
  end
1583
1622
  private_module_function :fu_same?
1584
1623
 
1585
- @fileutils_output = $stderr
1586
- @fileutils_label = ''
1587
-
1588
1624
  def fu_output_message(msg) #:nodoc:
1589
- @fileutils_output ||= $stderr
1590
- @fileutils_label ||= ''
1591
- @fileutils_output.puts @fileutils_label + msg
1625
+ output = @fileutils_output if defined?(@fileutils_output)
1626
+ output ||= $stdout
1627
+ if defined?(@fileutils_label)
1628
+ msg = @fileutils_label + msg
1629
+ end
1630
+ output.puts msg
1592
1631
  end
1593
1632
  private_module_function :fu_output_message
1594
1633
 
@@ -1599,8 +1638,11 @@ module FileUtils
1599
1638
  tbl
1600
1639
  }
1601
1640
 
1641
+ public
1642
+
1602
1643
  #
1603
- # Returns an Array of method names which have any options.
1644
+ # Returns an Array of names of high-level methods that accept any keyword
1645
+ # arguments.
1604
1646
  #
1605
1647
  # p FileUtils.commands #=> ["chmod", "cp", "cp_r", "install", ...]
1606
1648
  #
@@ -1639,7 +1681,7 @@ module FileUtils
1639
1681
  end
1640
1682
 
1641
1683
  #
1642
- # Returns an Array of method names which have the option +opt+.
1684
+ # Returns an Array of methods names which have the option +opt+.
1643
1685
  #
1644
1686
  # p FileUtils.collect_method(:preserve) #=> ["cp", "cp_r", "copy", "install"]
1645
1687
  #
@@ -1647,14 +1689,16 @@ module FileUtils
1647
1689
  OPT_TABLE.keys.select {|m| OPT_TABLE[m].include?(opt) }
1648
1690
  end
1649
1691
 
1650
- LOW_METHODS = singleton_methods(false) - collect_method(:noop).map(&:intern)
1651
- module LowMethods
1692
+ private
1693
+
1694
+ LOW_METHODS = singleton_methods(false) - collect_method(:noop).map(&:intern) # :nodoc:
1695
+ module LowMethods # :nodoc: internal use only
1652
1696
  private
1653
1697
  def _do_nothing(*)end
1654
1698
  ::FileUtils::LOW_METHODS.map {|name| alias_method name, :_do_nothing}
1655
1699
  end
1656
1700
 
1657
- METHODS = singleton_methods() - [:private_module_function,
1701
+ METHODS = singleton_methods() - [:private_module_function, # :nodoc:
1658
1702
  :commands, :options, :have_option?, :options_of, :collect_method]
1659
1703
 
1660
1704
  #
@@ -1664,8 +1708,6 @@ module FileUtils
1664
1708
  #
1665
1709
  module Verbose
1666
1710
  include FileUtils
1667
- @fileutils_output = $stderr
1668
- @fileutils_label = ''
1669
1711
  names = ::FileUtils.collect_method(:verbose)
1670
1712
  names.each do |name|
1671
1713
  module_eval(<<-EOS, __FILE__, __LINE__ + 1)
@@ -1689,8 +1731,6 @@ module FileUtils
1689
1731
  module NoWrite
1690
1732
  include FileUtils
1691
1733
  include LowMethods
1692
- @fileutils_output = $stderr
1693
- @fileutils_label = ''
1694
1734
  names = ::FileUtils.collect_method(:noop)
1695
1735
  names.each do |name|
1696
1736
  module_eval(<<-EOS, __FILE__, __LINE__ + 1)
@@ -1715,8 +1755,6 @@ module FileUtils
1715
1755
  module DryRun
1716
1756
  include FileUtils
1717
1757
  include LowMethods
1718
- @fileutils_output = $stderr
1719
- @fileutils_label = ''
1720
1758
  names = ::FileUtils.collect_method(:noop)
1721
1759
  names.each do |name|
1722
1760
  module_eval(<<-EOS, __FILE__, __LINE__ + 1)
metadata CHANGED
@@ -1,52 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fileutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-15 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
11
+ date: 2020-12-22 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: Several file utility methods for copying, moving, removing, etc.
28
14
  email:
29
- -
15
+ -
30
16
  executables: []
31
17
  extensions: []
32
18
  extra_rdoc_files: []
33
19
  files:
34
- - ".gitignore"
35
- - ".travis.yml"
36
- - Gemfile
37
20
  - LICENSE.txt
38
21
  - README.md
39
22
  - Rakefile
40
- - bin/console
41
- - bin/setup
42
23
  - fileutils.gemspec
43
24
  - lib/fileutils.rb
44
25
  homepage: https://github.com/ruby/fileutils
45
26
  licenses:
27
+ - Ruby
46
28
  - BSD-2-Clause
47
29
  metadata:
48
30
  source_code_uri: https://github.com/ruby/fileutils
49
- post_install_message:
31
+ post_install_message:
50
32
  rdoc_options: []
51
33
  require_paths:
52
34
  - lib
@@ -61,9 +43,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
43
  - !ruby/object:Gem::Version
62
44
  version: '0'
63
45
  requirements: []
64
- rubyforge_project:
65
- rubygems_version: 2.7.6
66
- signing_key:
46
+ rubygems_version: 3.2.2
47
+ signing_key:
67
48
  specification_version: 4
68
49
  summary: Several file utility methods for copying, moving, removing, etc.
69
50
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
@@ -1,13 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.7
5
- - 2.4.4
6
- - 2.5.1
7
- - ruby-head
8
- script: rake test
9
- matrix:
10
- include:
11
- - rvm: jruby-9.1.17.0
12
- env:
13
- - "JRUBY_OPTS='-J-Xmx1024M -X+O'"
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in fileutils.gemspec
4
- gemspec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "fileutils"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here