fileutils 1.7.3 → 1.8.1
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 +4 -4
- data/lib/fileutils.rb +109 -79
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 119ccdad9a61fd3b8d32a10a9737c25a71aa74c89af88793ddcd8f9dc08c7bd3
|
|
4
|
+
data.tar.gz: c84c86999eb6506a4d9b2115b1829d2820766ebbecf604aa07b8071320803e2d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f33cafc4d2e0b7ec187909b6ee8f6396a08cbc7216cc135062e7d8d43f72195186e97cb8b085b107f31997f36542894ab52b86f634be881b4ad3f807521b246b
|
|
7
|
+
data.tar.gz: be31fb0185c76372fed0fdb585f37e67a875dafa63497c2095f40ae791228e8c0e5cc96bf6e44870c32652a9ccfc1f3d7bacdc4244084bdfdeb93675e8264077
|
data/lib/fileutils.rb
CHANGED
|
@@ -181,7 +181,7 @@ end
|
|
|
181
181
|
#
|
|
182
182
|
module FileUtils
|
|
183
183
|
# The version number.
|
|
184
|
-
VERSION = "1.
|
|
184
|
+
VERSION = "1.8.1"
|
|
185
185
|
|
|
186
186
|
def self.private_module_function(name) #:nodoc:
|
|
187
187
|
module_function name
|
|
@@ -279,38 +279,67 @@ module FileUtils
|
|
|
279
279
|
end
|
|
280
280
|
private_module_function :remove_trailing_slash
|
|
281
281
|
|
|
282
|
+
# :markup: markdown
|
|
282
283
|
#
|
|
283
|
-
#
|
|
284
|
-
#
|
|
285
|
-
# returns +list+ if it is an array, <tt>[list]</tt> otherwise.
|
|
284
|
+
# call-seq:
|
|
285
|
+
# FileUtils.mkdir(*paths, mode: 0775, noop: nil, verbose: nil) -> array_of_paths or nil
|
|
286
286
|
#
|
|
287
|
-
# Argument
|
|
288
|
-
#
|
|
287
|
+
# Argument `paths` may be one path or an array of paths;
|
|
288
|
+
# each must be {interpretable as a path}[rdoc-ref:FileUtils@Path+Arguments].
|
|
289
289
|
#
|
|
290
|
-
#
|
|
291
|
-
#
|
|
292
|
-
#
|
|
290
|
+
# By default, creates a directory entry at each of the given `paths`;
|
|
291
|
+
# each directory has permissions `0775`;
|
|
292
|
+
# returns an array of the paths:
|
|
293
293
|
#
|
|
294
|
-
#
|
|
295
|
-
#
|
|
294
|
+
# ```ruby
|
|
295
|
+
# FileUtils.mkdir('foo') # => ["foo"]
|
|
296
|
+
# FileUtils.mkdir(%w[bar baz]) # => ["bar", "baz"]
|
|
297
|
+
# File.stat(Dir.new('foo')).mode.to_s(8) # => "40775"
|
|
298
|
+
# File.stat(Dir.new('bar')).mode.to_s(8) # => "40775"
|
|
299
|
+
# File.stat(Dir.new('baz')).mode.to_s(8) # => "40775"
|
|
300
|
+
# FileUtils.rmdir(%w[foo bar baz]) # => ["foo", "bar", "baz"]
|
|
301
|
+
# ```
|
|
296
302
|
#
|
|
297
|
-
#
|
|
303
|
+
# Raises an exception if for any reason a directory cannot be created;
|
|
304
|
+
# a common reason is that the directory already exists.
|
|
298
305
|
#
|
|
299
|
-
#
|
|
300
|
-
#
|
|
301
|
-
# - <tt>noop: true</tt> - does not create directories.
|
|
302
|
-
# - <tt>verbose: true</tt> - prints an equivalent command:
|
|
306
|
+
# With keyword argument `mode` given,
|
|
307
|
+
# creates directories with the given permissions:
|
|
303
308
|
#
|
|
304
|
-
#
|
|
305
|
-
#
|
|
309
|
+
# ```ruby
|
|
310
|
+
# FileUtils.mkdir('bar', mode: 0664)
|
|
311
|
+
# File.stat(Dir.new('bar')).mode.to_s(8) # => "40664"
|
|
312
|
+
# FileUtils.rmdir('bar')
|
|
313
|
+
# ```
|
|
306
314
|
#
|
|
307
|
-
#
|
|
315
|
+
# With keyword argument `noop` given as `true`,
|
|
316
|
+
# does not create directories;
|
|
317
|
+
# returns `nil`
|
|
318
|
+
#
|
|
319
|
+
# ```ruby
|
|
320
|
+
# FileUtils.mkdir('foo', noop: true) # => nil
|
|
321
|
+
# Dir.exist?('foo') # => false
|
|
322
|
+
# ```
|
|
323
|
+
#
|
|
324
|
+
# With keyword argument `verbose` given as `true`,
|
|
325
|
+
# prints a shell command:
|
|
308
326
|
#
|
|
309
|
-
#
|
|
310
|
-
#
|
|
327
|
+
# ```ruby
|
|
328
|
+
# FileUtils.mkdir('foo', verbose: true)
|
|
329
|
+
# FileUtils.mkdir(%w[bar baz], mode: 0644, verbose: true)
|
|
330
|
+
# FileUtils.mkdir(%w[bar baz], mode: 0644, verbose: true, noop: true)
|
|
331
|
+
# ```
|
|
311
332
|
#
|
|
312
|
-
#
|
|
313
|
-
#
|
|
333
|
+
# Output:
|
|
334
|
+
#
|
|
335
|
+
# ```text
|
|
336
|
+
# mkdir foo
|
|
337
|
+
# mkdir -m 644 bar baz
|
|
338
|
+
# mkdir -m 644 bar baz
|
|
339
|
+
# ```
|
|
340
|
+
#
|
|
341
|
+
# Note that in the last call above (containing `noop: true`)
|
|
342
|
+
# the existence of the directory is not checked.
|
|
314
343
|
#
|
|
315
344
|
# Related: FileUtils.mkdir_p.
|
|
316
345
|
#
|
|
@@ -686,7 +715,7 @@ module FileUtils
|
|
|
686
715
|
# Keyword arguments:
|
|
687
716
|
#
|
|
688
717
|
# - <tt>force: true</tt> - overwrites +dest+ if it exists.
|
|
689
|
-
# - <tt>relative:
|
|
718
|
+
# - <tt>relative: true</tt> - create links relative to +dest+.
|
|
690
719
|
# - <tt>noop: true</tt> - does not create links.
|
|
691
720
|
# - <tt>verbose: true</tt> - prints an equivalent command:
|
|
692
721
|
#
|
|
@@ -706,11 +735,12 @@ module FileUtils
|
|
|
706
735
|
#
|
|
707
736
|
def ln_s(src, dest, force: nil, relative: false, target_directory: true, noop: nil, verbose: nil)
|
|
708
737
|
if relative
|
|
709
|
-
return ln_sr(src, dest, force: force, noop: noop, verbose: verbose)
|
|
738
|
+
return ln_sr(src, dest, force: force, target_directory: target_directory, noop: noop, verbose: verbose)
|
|
710
739
|
end
|
|
711
|
-
fu_output_message "ln -s#{force ? 'f' : ''}
|
|
740
|
+
fu_output_message "ln -s#{force ? 'f' : ''}#{
|
|
741
|
+
target_directory ? '' : 'T'} #{[src,dest].flatten.join ' '}" if verbose
|
|
712
742
|
return if noop
|
|
713
|
-
fu_each_src_dest0(src, dest) do |s,d|
|
|
743
|
+
fu_each_src_dest0(src, dest, target_directory) do |s,d|
|
|
714
744
|
remove_file d, true if force
|
|
715
745
|
File.symlink s, d
|
|
716
746
|
end
|
|
@@ -730,42 +760,37 @@ module FileUtils
|
|
|
730
760
|
# Like FileUtils.ln_s, but create links relative to +dest+.
|
|
731
761
|
#
|
|
732
762
|
def ln_sr(src, dest, target_directory: true, force: nil, noop: nil, verbose: nil)
|
|
733
|
-
|
|
734
|
-
dest
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
d = File.join(destdirs = dest, File.basename(s))
|
|
763
|
+
cmd = "ln -s#{force ? 'f' : ''}#{target_directory ? '' : 'T'}" if verbose
|
|
764
|
+
fu_each_src_dest0(src, dest, target_directory) do |s,d|
|
|
765
|
+
if target_directory
|
|
766
|
+
parent = File.dirname(d)
|
|
767
|
+
destdirs = fu_split_path(parent)
|
|
768
|
+
real_ddirs = fu_split_path(File.realpath(parent))
|
|
740
769
|
else
|
|
741
|
-
destdirs
|
|
770
|
+
destdirs ||= fu_split_path(dest)
|
|
771
|
+
real_ddirs ||= fu_split_path(File.realdirpath(dest))
|
|
742
772
|
end
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
773
|
+
srcdirs = fu_split_path(s)
|
|
774
|
+
i = fu_common_components(srcdirs, destdirs)
|
|
775
|
+
n = destdirs.size - i
|
|
776
|
+
n -= 1 unless target_directory
|
|
777
|
+
link1 = fu_clean_components(*Array.new([n, 0].max, '..'), *srcdirs[i..-1])
|
|
778
|
+
begin
|
|
779
|
+
real_sdirs = fu_split_path(File.realdirpath(s)) rescue nil
|
|
780
|
+
rescue
|
|
748
781
|
else
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
end
|
|
755
|
-
s = File.join(*base, *srcdirs)
|
|
782
|
+
i = fu_common_components(real_sdirs, real_ddirs)
|
|
783
|
+
n = real_ddirs.size - i
|
|
784
|
+
n -= 1 unless target_directory
|
|
785
|
+
link2 = fu_clean_components(*Array.new([n, 0].max, '..'), *real_sdirs[i..-1])
|
|
786
|
+
link1 = link2 if !link2.empty? and link1.size > link2.size
|
|
756
787
|
end
|
|
757
|
-
|
|
788
|
+
s = File.join(link1)
|
|
789
|
+
fu_output_message [cmd, s, d].flatten.join(' ') if verbose
|
|
758
790
|
next if noop
|
|
759
791
|
remove_file d, true if force
|
|
760
792
|
File.symlink s, d
|
|
761
793
|
end
|
|
762
|
-
case srcs.size
|
|
763
|
-
when 0
|
|
764
|
-
when 1
|
|
765
|
-
link[srcs[0], target_directory && File.directory?(dest)]
|
|
766
|
-
else
|
|
767
|
-
srcs.each(&link)
|
|
768
|
-
end
|
|
769
794
|
end
|
|
770
795
|
module_function :ln_sr
|
|
771
796
|
|
|
@@ -800,13 +825,13 @@ module FileUtils
|
|
|
800
825
|
# File.file?('dest1/dir1/t2.txt') # => true
|
|
801
826
|
# File.file?('dest1/dir1/t3.txt') # => true
|
|
802
827
|
#
|
|
803
|
-
#
|
|
828
|
+
# Optional arguments:
|
|
804
829
|
#
|
|
805
|
-
# -
|
|
806
|
-
# -
|
|
830
|
+
# - +dereference_root+ - dereferences +src+ if it is a symbolic link (+false+ by default).
|
|
831
|
+
# - +remove_destination+ - removes +dest+ before creating links (+false+ by default).
|
|
807
832
|
#
|
|
808
833
|
# Raises an exception if +dest+ is the path to an existing file or directory
|
|
809
|
-
# and
|
|
834
|
+
# and optional argument +remove_destination+ is not given.
|
|
810
835
|
#
|
|
811
836
|
# Related: FileUtils.ln (has different options).
|
|
812
837
|
#
|
|
@@ -1029,12 +1054,12 @@ module FileUtils
|
|
|
1029
1054
|
# directories, and symbolic links;
|
|
1030
1055
|
# other file types (FIFO streams, device files, etc.) are not supported.
|
|
1031
1056
|
#
|
|
1032
|
-
#
|
|
1057
|
+
# Optional arguments:
|
|
1033
1058
|
#
|
|
1034
|
-
# -
|
|
1035
|
-
# follows the link.
|
|
1036
|
-
# -
|
|
1037
|
-
# -
|
|
1059
|
+
# - +dereference_root+ - if +src+ is a symbolic link,
|
|
1060
|
+
# follows the link (+false+ by default).
|
|
1061
|
+
# - +preserve+ - preserves file times (+false+ by default).
|
|
1062
|
+
# - +remove_destination+ - removes +dest+ before copying files (+false+ by default).
|
|
1038
1063
|
#
|
|
1039
1064
|
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
|
|
1040
1065
|
#
|
|
@@ -1065,12 +1090,12 @@ module FileUtils
|
|
|
1065
1090
|
# FileUtils.copy_file('src0.txt', 'dest0.txt')
|
|
1066
1091
|
# File.file?('dest0.txt') # => true
|
|
1067
1092
|
#
|
|
1068
|
-
#
|
|
1093
|
+
# Optional arguments:
|
|
1069
1094
|
#
|
|
1070
|
-
# -
|
|
1071
|
-
#
|
|
1072
|
-
# -
|
|
1073
|
-
# -
|
|
1095
|
+
# - +dereference+ - if +src+ is a symbolic link,
|
|
1096
|
+
# follows the link (+true+ by default).
|
|
1097
|
+
# - +preserve+ - preserves file times (+false+ by default).
|
|
1098
|
+
# - +remove_destination+ - removes +dest+ before copying files (+false+ by default).
|
|
1074
1099
|
#
|
|
1075
1100
|
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
|
|
1076
1101
|
#
|
|
@@ -1491,7 +1516,8 @@ module FileUtils
|
|
|
1491
1516
|
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
|
|
1492
1517
|
#
|
|
1493
1518
|
def remove_dir(path, force = false)
|
|
1494
|
-
|
|
1519
|
+
raise Errno::ENOTDIR, path unless force or File.directory?(path)
|
|
1520
|
+
remove_entry path, force
|
|
1495
1521
|
end
|
|
1496
1522
|
module_function :remove_dir
|
|
1497
1523
|
|
|
@@ -2040,10 +2066,6 @@ module FileUtils
|
|
|
2040
2066
|
def fu_windows?; false end #:nodoc:
|
|
2041
2067
|
end
|
|
2042
2068
|
|
|
2043
|
-
def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
|
|
2044
|
-
IO.copy_stream(src, dest)
|
|
2045
|
-
end
|
|
2046
|
-
|
|
2047
2069
|
def fu_stream_blksize(*streams) #:nodoc:
|
|
2048
2070
|
streams.each do |s|
|
|
2049
2071
|
next unless s.respond_to?(:stat)
|
|
@@ -2475,6 +2497,10 @@ module FileUtils
|
|
|
2475
2497
|
|
|
2476
2498
|
def fu_each_src_dest0(src, dest, target_directory = true) #:nodoc:
|
|
2477
2499
|
if tmp = Array.try_convert(src)
|
|
2500
|
+
unless target_directory or tmp.size <= 1
|
|
2501
|
+
tmp = tmp.map {|f| File.path(f)} # A workaround for RBS
|
|
2502
|
+
raise ArgumentError, "extra target #{tmp}"
|
|
2503
|
+
end
|
|
2478
2504
|
tmp.each do |s|
|
|
2479
2505
|
s = File.path(s)
|
|
2480
2506
|
yield s, (target_directory ? File.join(dest, File.basename(s)) : dest)
|
|
@@ -2509,7 +2535,11 @@ module FileUtils
|
|
|
2509
2535
|
path = File.path(path)
|
|
2510
2536
|
list = []
|
|
2511
2537
|
until (parent, base = File.split(path); parent == path or parent == ".")
|
|
2512
|
-
list
|
|
2538
|
+
if base != '..' and list.last == '..' and !(fu_have_symlink? && File.symlink?(path))
|
|
2539
|
+
list.pop
|
|
2540
|
+
else
|
|
2541
|
+
list << base
|
|
2542
|
+
end
|
|
2513
2543
|
path = parent
|
|
2514
2544
|
end
|
|
2515
2545
|
list << path
|
|
@@ -2517,14 +2547,14 @@ module FileUtils
|
|
|
2517
2547
|
end
|
|
2518
2548
|
private_module_function :fu_split_path
|
|
2519
2549
|
|
|
2520
|
-
def
|
|
2550
|
+
def fu_common_components(target, base) #:nodoc:
|
|
2521
2551
|
i = 0
|
|
2522
2552
|
while target[i]&.== base[i]
|
|
2523
2553
|
i += 1
|
|
2524
2554
|
end
|
|
2525
|
-
|
|
2555
|
+
i
|
|
2526
2556
|
end
|
|
2527
|
-
private_module_function :
|
|
2557
|
+
private_module_function :fu_common_components
|
|
2528
2558
|
|
|
2529
2559
|
def fu_clean_components(*comp) #:nodoc:
|
|
2530
2560
|
comp.shift while comp.first == "."
|
|
@@ -2534,7 +2564,7 @@ module FileUtils
|
|
|
2534
2564
|
while c = comp.shift
|
|
2535
2565
|
if c == ".." and clean.last != ".." and !(fu_have_symlink? && File.symlink?(path))
|
|
2536
2566
|
clean.pop
|
|
2537
|
-
path.
|
|
2567
|
+
path.sub!(%r((?<=\A|/)[^/]+/\z), "")
|
|
2538
2568
|
else
|
|
2539
2569
|
clean << c
|
|
2540
2570
|
path << c << "/"
|
metadata
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fileutils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Minero Aoki
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: Several file utility methods for copying, moving, removing, etc.
|
|
14
13
|
email:
|
|
15
|
-
-
|
|
14
|
+
-
|
|
16
15
|
executables: []
|
|
17
16
|
extensions: []
|
|
18
17
|
extra_rdoc_files: []
|
|
@@ -29,7 +28,6 @@ licenses:
|
|
|
29
28
|
- BSD-2-Clause
|
|
30
29
|
metadata:
|
|
31
30
|
source_code_uri: https://github.com/ruby/fileutils
|
|
32
|
-
post_install_message:
|
|
33
31
|
rdoc_options: []
|
|
34
32
|
require_paths:
|
|
35
33
|
- lib
|
|
@@ -44,8 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
44
42
|
- !ruby/object:Gem::Version
|
|
45
43
|
version: '0'
|
|
46
44
|
requirements: []
|
|
47
|
-
rubygems_version: 3.
|
|
48
|
-
signing_key:
|
|
45
|
+
rubygems_version: 3.6.9
|
|
49
46
|
specification_version: 4
|
|
50
47
|
summary: Several file utility methods for copying, moving, removing, etc.
|
|
51
48
|
test_files: []
|