fileutils 1.7.3 → 1.8.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 +4 -4
- data/lib/fileutils.rb +57 -52
- 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: 86c6c5b356b1a4609616761dd686d3fef6611d3e60bb6cef6b44c624454a2e2f
|
|
4
|
+
data.tar.gz: ec91ec1155d38977abefbfa963d6c5bdc6ebadaf22481a70f6359a4e5a3a4b6d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14affe38fe72bee2de39d9cf4897361ab1fcfd47a8e25f9faae47f563f283491826525a170d01e86bb3423a17cd43477daeceb1ac6c64d6dff6483cab36da702
|
|
7
|
+
data.tar.gz: 174d36e824096f64e63db03c42631d0f3511cbdf48be425cf922ddbe711956404b1b39bc8d2f7d9241d218beba4c0fca7b40d9a5bbb15b29a7980db5db10cde2
|
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.0"
|
|
185
185
|
|
|
186
186
|
def self.private_module_function(name) #:nodoc:
|
|
187
187
|
module_function name
|
|
@@ -706,11 +706,12 @@ module FileUtils
|
|
|
706
706
|
#
|
|
707
707
|
def ln_s(src, dest, force: nil, relative: false, target_directory: true, noop: nil, verbose: nil)
|
|
708
708
|
if relative
|
|
709
|
-
return ln_sr(src, dest, force: force, noop: noop, verbose: verbose)
|
|
709
|
+
return ln_sr(src, dest, force: force, target_directory: target_directory, noop: noop, verbose: verbose)
|
|
710
710
|
end
|
|
711
|
-
fu_output_message "ln -s#{force ? 'f' : ''}
|
|
711
|
+
fu_output_message "ln -s#{force ? 'f' : ''}#{
|
|
712
|
+
target_directory ? '' : 'T'} #{[src,dest].flatten.join ' '}" if verbose
|
|
712
713
|
return if noop
|
|
713
|
-
fu_each_src_dest0(src, dest) do |s,d|
|
|
714
|
+
fu_each_src_dest0(src, dest, target_directory) do |s,d|
|
|
714
715
|
remove_file d, true if force
|
|
715
716
|
File.symlink s, d
|
|
716
717
|
end
|
|
@@ -730,42 +731,37 @@ module FileUtils
|
|
|
730
731
|
# Like FileUtils.ln_s, but create links relative to +dest+.
|
|
731
732
|
#
|
|
732
733
|
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))
|
|
734
|
+
cmd = "ln -s#{force ? 'f' : ''}#{target_directory ? '' : 'T'}" if verbose
|
|
735
|
+
fu_each_src_dest0(src, dest, target_directory) do |s,d|
|
|
736
|
+
if target_directory
|
|
737
|
+
parent = File.dirname(d)
|
|
738
|
+
destdirs = fu_split_path(parent)
|
|
739
|
+
real_ddirs = fu_split_path(File.realpath(parent))
|
|
740
740
|
else
|
|
741
|
-
destdirs
|
|
741
|
+
destdirs ||= fu_split_path(dest)
|
|
742
|
+
real_ddirs ||= fu_split_path(File.realdirpath(dest))
|
|
742
743
|
end
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
744
|
+
srcdirs = fu_split_path(s)
|
|
745
|
+
i = fu_common_components(srcdirs, destdirs)
|
|
746
|
+
n = destdirs.size - i
|
|
747
|
+
n -= 1 unless target_directory
|
|
748
|
+
link1 = fu_clean_components(*Array.new([n, 0].max, '..'), *srcdirs[i..-1])
|
|
749
|
+
begin
|
|
750
|
+
real_sdirs = fu_split_path(File.realdirpath(s)) rescue nil
|
|
751
|
+
rescue
|
|
748
752
|
else
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
end
|
|
755
|
-
s = File.join(*base, *srcdirs)
|
|
753
|
+
i = fu_common_components(real_sdirs, real_ddirs)
|
|
754
|
+
n = real_ddirs.size - i
|
|
755
|
+
n -= 1 unless target_directory
|
|
756
|
+
link2 = fu_clean_components(*Array.new([n, 0].max, '..'), *real_sdirs[i..-1])
|
|
757
|
+
link1 = link2 if link1.size > link2.size
|
|
756
758
|
end
|
|
757
|
-
|
|
759
|
+
s = File.join(link1)
|
|
760
|
+
fu_output_message [cmd, s, d].flatten.join(' ') if verbose
|
|
758
761
|
next if noop
|
|
759
762
|
remove_file d, true if force
|
|
760
763
|
File.symlink s, d
|
|
761
764
|
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
765
|
end
|
|
770
766
|
module_function :ln_sr
|
|
771
767
|
|
|
@@ -800,13 +796,13 @@ module FileUtils
|
|
|
800
796
|
# File.file?('dest1/dir1/t2.txt') # => true
|
|
801
797
|
# File.file?('dest1/dir1/t3.txt') # => true
|
|
802
798
|
#
|
|
803
|
-
#
|
|
799
|
+
# Optional arguments:
|
|
804
800
|
#
|
|
805
|
-
# -
|
|
806
|
-
# -
|
|
801
|
+
# - +dereference_root+ - dereferences +src+ if it is a symbolic link (+false+ by default).
|
|
802
|
+
# - +remove_destination+ - removes +dest+ before creating links (+false+ by default).
|
|
807
803
|
#
|
|
808
804
|
# Raises an exception if +dest+ is the path to an existing file or directory
|
|
809
|
-
# and
|
|
805
|
+
# and optional argument +remove_destination+ is not given.
|
|
810
806
|
#
|
|
811
807
|
# Related: FileUtils.ln (has different options).
|
|
812
808
|
#
|
|
@@ -1029,12 +1025,12 @@ module FileUtils
|
|
|
1029
1025
|
# directories, and symbolic links;
|
|
1030
1026
|
# other file types (FIFO streams, device files, etc.) are not supported.
|
|
1031
1027
|
#
|
|
1032
|
-
#
|
|
1028
|
+
# Optional arguments:
|
|
1033
1029
|
#
|
|
1034
|
-
# -
|
|
1035
|
-
# follows the link.
|
|
1036
|
-
# -
|
|
1037
|
-
# -
|
|
1030
|
+
# - +dereference_root+ - if +src+ is a symbolic link,
|
|
1031
|
+
# follows the link (+false+ by default).
|
|
1032
|
+
# - +preserve+ - preserves file times (+false+ by default).
|
|
1033
|
+
# - +remove_destination+ - removes +dest+ before copying files (+false+ by default).
|
|
1038
1034
|
#
|
|
1039
1035
|
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
|
|
1040
1036
|
#
|
|
@@ -1065,12 +1061,12 @@ module FileUtils
|
|
|
1065
1061
|
# FileUtils.copy_file('src0.txt', 'dest0.txt')
|
|
1066
1062
|
# File.file?('dest0.txt') # => true
|
|
1067
1063
|
#
|
|
1068
|
-
#
|
|
1064
|
+
# Optional arguments:
|
|
1069
1065
|
#
|
|
1070
|
-
# -
|
|
1071
|
-
#
|
|
1072
|
-
# -
|
|
1073
|
-
# -
|
|
1066
|
+
# - +dereference+ - if +src+ is a symbolic link,
|
|
1067
|
+
# follows the link (+true+ by default).
|
|
1068
|
+
# - +preserve+ - preserves file times (+false+ by default).
|
|
1069
|
+
# - +remove_destination+ - removes +dest+ before copying files (+false+ by default).
|
|
1074
1070
|
#
|
|
1075
1071
|
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
|
|
1076
1072
|
#
|
|
@@ -1491,7 +1487,8 @@ module FileUtils
|
|
|
1491
1487
|
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
|
|
1492
1488
|
#
|
|
1493
1489
|
def remove_dir(path, force = false)
|
|
1494
|
-
|
|
1490
|
+
raise Errno::ENOTDIR, path unless force or File.directory?(path)
|
|
1491
|
+
remove_entry path, force
|
|
1495
1492
|
end
|
|
1496
1493
|
module_function :remove_dir
|
|
1497
1494
|
|
|
@@ -2475,6 +2472,10 @@ module FileUtils
|
|
|
2475
2472
|
|
|
2476
2473
|
def fu_each_src_dest0(src, dest, target_directory = true) #:nodoc:
|
|
2477
2474
|
if tmp = Array.try_convert(src)
|
|
2475
|
+
unless target_directory or tmp.size <= 1
|
|
2476
|
+
tmp = tmp.map {|f| File.path(f)} # A workaround for RBS
|
|
2477
|
+
raise ArgumentError, "extra target #{tmp}"
|
|
2478
|
+
end
|
|
2478
2479
|
tmp.each do |s|
|
|
2479
2480
|
s = File.path(s)
|
|
2480
2481
|
yield s, (target_directory ? File.join(dest, File.basename(s)) : dest)
|
|
@@ -2509,7 +2510,11 @@ module FileUtils
|
|
|
2509
2510
|
path = File.path(path)
|
|
2510
2511
|
list = []
|
|
2511
2512
|
until (parent, base = File.split(path); parent == path or parent == ".")
|
|
2512
|
-
list
|
|
2513
|
+
if base != '..' and list.last == '..' and !(fu_have_symlink? && File.symlink?(path))
|
|
2514
|
+
list.pop
|
|
2515
|
+
else
|
|
2516
|
+
list << base
|
|
2517
|
+
end
|
|
2513
2518
|
path = parent
|
|
2514
2519
|
end
|
|
2515
2520
|
list << path
|
|
@@ -2517,14 +2522,14 @@ module FileUtils
|
|
|
2517
2522
|
end
|
|
2518
2523
|
private_module_function :fu_split_path
|
|
2519
2524
|
|
|
2520
|
-
def
|
|
2525
|
+
def fu_common_components(target, base) #:nodoc:
|
|
2521
2526
|
i = 0
|
|
2522
2527
|
while target[i]&.== base[i]
|
|
2523
2528
|
i += 1
|
|
2524
2529
|
end
|
|
2525
|
-
|
|
2530
|
+
i
|
|
2526
2531
|
end
|
|
2527
|
-
private_module_function :
|
|
2532
|
+
private_module_function :fu_common_components
|
|
2528
2533
|
|
|
2529
2534
|
def fu_clean_components(*comp) #:nodoc:
|
|
2530
2535
|
comp.shift while comp.first == "."
|
|
@@ -2534,7 +2539,7 @@ module FileUtils
|
|
|
2534
2539
|
while c = comp.shift
|
|
2535
2540
|
if c == ".." and clean.last != ".." and !(fu_have_symlink? && File.symlink?(path))
|
|
2536
2541
|
clean.pop
|
|
2537
|
-
path.
|
|
2542
|
+
path.sub!(%r((?<=\A|/)[^/]+/\z), "")
|
|
2538
2543
|
else
|
|
2539
2544
|
clean << c
|
|
2540
2545
|
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.0
|
|
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: []
|