fileutils 1.7.2 → 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/{LICENSE.txt → BSDL} +3 -3
- data/COPYING +56 -0
- data/fileutils.gemspec +1 -1
- data/lib/fileutils.rb +71 -64
- metadata +5 -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/{LICENSE.txt → BSDL}
RENAMED
|
@@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without
|
|
|
4
4
|
modification, are permitted provided that the following conditions
|
|
5
5
|
are met:
|
|
6
6
|
1. Redistributions of source code must retain the above copyright
|
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
|
8
8
|
2. Redistributions in binary form must reproduce the above copyright
|
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
|
10
|
-
documentation and/or other materials provided with the distribution.
|
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
|
10
|
+
documentation and/or other materials provided with the distribution.
|
|
11
11
|
|
|
12
12
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
13
13
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
data/COPYING
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
|
|
2
|
+
You can redistribute it and/or modify it under either the terms of the
|
|
3
|
+
2-clause BSDL (see the file BSDL), or the conditions below:
|
|
4
|
+
|
|
5
|
+
1. You may make and give away verbatim copies of the source form of the
|
|
6
|
+
software without restriction, provided that you duplicate all of the
|
|
7
|
+
original copyright notices and associated disclaimers.
|
|
8
|
+
|
|
9
|
+
2. You may modify your copy of the software in any way, provided that
|
|
10
|
+
you do at least ONE of the following:
|
|
11
|
+
|
|
12
|
+
a. place your modifications in the Public Domain or otherwise
|
|
13
|
+
make them Freely Available, such as by posting said
|
|
14
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
|
15
|
+
the author to include your modifications in the software.
|
|
16
|
+
|
|
17
|
+
b. use the modified software only within your corporation or
|
|
18
|
+
organization.
|
|
19
|
+
|
|
20
|
+
c. give non-standard binaries non-standard names, with
|
|
21
|
+
instructions on where to get the original software distribution.
|
|
22
|
+
|
|
23
|
+
d. make other distribution arrangements with the author.
|
|
24
|
+
|
|
25
|
+
3. You may distribute the software in object code or binary form,
|
|
26
|
+
provided that you do at least ONE of the following:
|
|
27
|
+
|
|
28
|
+
a. distribute the binaries and library files of the software,
|
|
29
|
+
together with instructions (in the manual page or equivalent)
|
|
30
|
+
on where to get the original distribution.
|
|
31
|
+
|
|
32
|
+
b. accompany the distribution with the machine-readable source of
|
|
33
|
+
the software.
|
|
34
|
+
|
|
35
|
+
c. give non-standard binaries non-standard names, with
|
|
36
|
+
instructions on where to get the original software distribution.
|
|
37
|
+
|
|
38
|
+
d. make other distribution arrangements with the author.
|
|
39
|
+
|
|
40
|
+
4. You may modify and include the part of the software into any other
|
|
41
|
+
software (possibly commercial). But some files in the distribution
|
|
42
|
+
are not written by the author, so that they are not under these terms.
|
|
43
|
+
|
|
44
|
+
For the list of those files and their copying conditions, see the
|
|
45
|
+
file LEGAL.
|
|
46
|
+
|
|
47
|
+
5. The scripts and library files supplied as input to or produced as
|
|
48
|
+
output from the software do not automatically fall under the
|
|
49
|
+
copyright of the software, but belong to whomever generated them,
|
|
50
|
+
and may be sold commercially, and may be aggregated with this
|
|
51
|
+
software.
|
|
52
|
+
|
|
53
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
|
54
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
55
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
56
|
+
PURPOSE.
|
data/fileutils.gemspec
CHANGED
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
|
17
17
|
s.description = "Several file utility methods for copying, moving, removing, etc."
|
|
18
18
|
|
|
19
19
|
s.require_path = %w{lib}
|
|
20
|
-
s.files = ["
|
|
20
|
+
s.files = ["COPYING", "BSDL", "README.md", "Rakefile", "fileutils.gemspec", "lib/fileutils.rb"]
|
|
21
21
|
s.required_ruby_version = ">= 2.5.0"
|
|
22
22
|
|
|
23
23
|
s.authors = ["Minero Aoki"]
|
data/lib/fileutils.rb
CHANGED
|
@@ -180,7 +180,8 @@ end
|
|
|
180
180
|
# - {CVE-2004-0452}[https://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-0452].
|
|
181
181
|
#
|
|
182
182
|
module FileUtils
|
|
183
|
-
|
|
183
|
+
# The version number.
|
|
184
|
+
VERSION = "1.8.0"
|
|
184
185
|
|
|
185
186
|
def self.private_module_function(name) #:nodoc:
|
|
186
187
|
module_function name
|
|
@@ -705,11 +706,12 @@ module FileUtils
|
|
|
705
706
|
#
|
|
706
707
|
def ln_s(src, dest, force: nil, relative: false, target_directory: true, noop: nil, verbose: nil)
|
|
707
708
|
if relative
|
|
708
|
-
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)
|
|
709
710
|
end
|
|
710
|
-
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
|
|
711
713
|
return if noop
|
|
712
|
-
fu_each_src_dest0(src, dest) do |s,d|
|
|
714
|
+
fu_each_src_dest0(src, dest, target_directory) do |s,d|
|
|
713
715
|
remove_file d, true if force
|
|
714
716
|
File.symlink s, d
|
|
715
717
|
end
|
|
@@ -729,42 +731,37 @@ module FileUtils
|
|
|
729
731
|
# Like FileUtils.ln_s, but create links relative to +dest+.
|
|
730
732
|
#
|
|
731
733
|
def ln_sr(src, dest, target_directory: true, force: nil, noop: nil, verbose: nil)
|
|
732
|
-
|
|
733
|
-
dest
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
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))
|
|
739
740
|
else
|
|
740
|
-
destdirs
|
|
741
|
+
destdirs ||= fu_split_path(dest)
|
|
742
|
+
real_ddirs ||= fu_split_path(File.realdirpath(dest))
|
|
741
743
|
end
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
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
|
|
747
752
|
else
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
end
|
|
754
|
-
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
|
|
755
758
|
end
|
|
756
|
-
|
|
759
|
+
s = File.join(link1)
|
|
760
|
+
fu_output_message [cmd, s, d].flatten.join(' ') if verbose
|
|
757
761
|
next if noop
|
|
758
762
|
remove_file d, true if force
|
|
759
763
|
File.symlink s, d
|
|
760
764
|
end
|
|
761
|
-
case srcs.size
|
|
762
|
-
when 0
|
|
763
|
-
when 1
|
|
764
|
-
link[srcs[0], target_directory && File.directory?(dest)]
|
|
765
|
-
else
|
|
766
|
-
srcs.each(&link)
|
|
767
|
-
end
|
|
768
765
|
end
|
|
769
766
|
module_function :ln_sr
|
|
770
767
|
|
|
@@ -799,13 +796,13 @@ module FileUtils
|
|
|
799
796
|
# File.file?('dest1/dir1/t2.txt') # => true
|
|
800
797
|
# File.file?('dest1/dir1/t3.txt') # => true
|
|
801
798
|
#
|
|
802
|
-
#
|
|
799
|
+
# Optional arguments:
|
|
803
800
|
#
|
|
804
|
-
# -
|
|
805
|
-
# -
|
|
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).
|
|
806
803
|
#
|
|
807
804
|
# Raises an exception if +dest+ is the path to an existing file or directory
|
|
808
|
-
# and
|
|
805
|
+
# and optional argument +remove_destination+ is not given.
|
|
809
806
|
#
|
|
810
807
|
# Related: FileUtils.ln (has different options).
|
|
811
808
|
#
|
|
@@ -1028,12 +1025,12 @@ module FileUtils
|
|
|
1028
1025
|
# directories, and symbolic links;
|
|
1029
1026
|
# other file types (FIFO streams, device files, etc.) are not supported.
|
|
1030
1027
|
#
|
|
1031
|
-
#
|
|
1028
|
+
# Optional arguments:
|
|
1032
1029
|
#
|
|
1033
|
-
# -
|
|
1034
|
-
# follows the link.
|
|
1035
|
-
# -
|
|
1036
|
-
# -
|
|
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).
|
|
1037
1034
|
#
|
|
1038
1035
|
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
|
|
1039
1036
|
#
|
|
@@ -1064,12 +1061,12 @@ module FileUtils
|
|
|
1064
1061
|
# FileUtils.copy_file('src0.txt', 'dest0.txt')
|
|
1065
1062
|
# File.file?('dest0.txt') # => true
|
|
1066
1063
|
#
|
|
1067
|
-
#
|
|
1064
|
+
# Optional arguments:
|
|
1068
1065
|
#
|
|
1069
|
-
# -
|
|
1070
|
-
#
|
|
1071
|
-
# -
|
|
1072
|
-
# -
|
|
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).
|
|
1073
1070
|
#
|
|
1074
1071
|
# Related: {methods for copying}[rdoc-ref:FileUtils@Copying].
|
|
1075
1072
|
#
|
|
@@ -1490,7 +1487,8 @@ module FileUtils
|
|
|
1490
1487
|
# Related: {methods for deleting}[rdoc-ref:FileUtils@Deleting].
|
|
1491
1488
|
#
|
|
1492
1489
|
def remove_dir(path, force = false)
|
|
1493
|
-
|
|
1490
|
+
raise Errno::ENOTDIR, path unless force or File.directory?(path)
|
|
1491
|
+
remove_entry path, force
|
|
1494
1492
|
end
|
|
1495
1493
|
module_function :remove_dir
|
|
1496
1494
|
|
|
@@ -1651,7 +1649,7 @@ module FileUtils
|
|
|
1651
1649
|
when "a"
|
|
1652
1650
|
mask | 07777
|
|
1653
1651
|
else
|
|
1654
|
-
raise ArgumentError, "invalid
|
|
1652
|
+
raise ArgumentError, "invalid 'who' symbol in file mode: #{chr}"
|
|
1655
1653
|
end
|
|
1656
1654
|
end
|
|
1657
1655
|
end
|
|
@@ -1705,7 +1703,7 @@ module FileUtils
|
|
|
1705
1703
|
copy_mask = user_mask(chr)
|
|
1706
1704
|
(current_mode & copy_mask) / (copy_mask & 0111) * (user_mask & 0111)
|
|
1707
1705
|
else
|
|
1708
|
-
raise ArgumentError, "invalid
|
|
1706
|
+
raise ArgumentError, "invalid 'perm' symbol in file mode: #{chr}"
|
|
1709
1707
|
end
|
|
1710
1708
|
end
|
|
1711
1709
|
|
|
@@ -2028,21 +2026,22 @@ module FileUtils
|
|
|
2028
2026
|
|
|
2029
2027
|
private
|
|
2030
2028
|
|
|
2031
|
-
module StreamUtils_
|
|
2029
|
+
module StreamUtils_ # :nodoc:
|
|
2030
|
+
|
|
2032
2031
|
private
|
|
2033
2032
|
|
|
2034
2033
|
case (defined?(::RbConfig) ? ::RbConfig::CONFIG['host_os'] : ::RUBY_PLATFORM)
|
|
2035
2034
|
when /mswin|mingw/
|
|
2036
|
-
def fu_windows?; true end
|
|
2035
|
+
def fu_windows?; true end #:nodoc:
|
|
2037
2036
|
else
|
|
2038
|
-
def fu_windows?; false end
|
|
2037
|
+
def fu_windows?; false end #:nodoc:
|
|
2039
2038
|
end
|
|
2040
2039
|
|
|
2041
2040
|
def fu_copy_stream0(src, dest, blksize = nil) #:nodoc:
|
|
2042
2041
|
IO.copy_stream(src, dest)
|
|
2043
2042
|
end
|
|
2044
2043
|
|
|
2045
|
-
def fu_stream_blksize(*streams)
|
|
2044
|
+
def fu_stream_blksize(*streams) #:nodoc:
|
|
2046
2045
|
streams.each do |s|
|
|
2047
2046
|
next unless s.respond_to?(:stat)
|
|
2048
2047
|
size = fu_blksize(s.stat)
|
|
@@ -2051,14 +2050,14 @@ module FileUtils
|
|
|
2051
2050
|
fu_default_blksize()
|
|
2052
2051
|
end
|
|
2053
2052
|
|
|
2054
|
-
def fu_blksize(st)
|
|
2053
|
+
def fu_blksize(st) #:nodoc:
|
|
2055
2054
|
s = st.blksize
|
|
2056
2055
|
return nil unless s
|
|
2057
2056
|
return nil if s == 0
|
|
2058
2057
|
s
|
|
2059
2058
|
end
|
|
2060
2059
|
|
|
2061
|
-
def fu_default_blksize
|
|
2060
|
+
def fu_default_blksize #:nodoc:
|
|
2062
2061
|
1024
|
|
2063
2062
|
end
|
|
2064
2063
|
end
|
|
@@ -2473,6 +2472,10 @@ module FileUtils
|
|
|
2473
2472
|
|
|
2474
2473
|
def fu_each_src_dest0(src, dest, target_directory = true) #:nodoc:
|
|
2475
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
|
|
2476
2479
|
tmp.each do |s|
|
|
2477
2480
|
s = File.path(s)
|
|
2478
2481
|
yield s, (target_directory ? File.join(dest, File.basename(s)) : dest)
|
|
@@ -2503,11 +2506,15 @@ module FileUtils
|
|
|
2503
2506
|
end
|
|
2504
2507
|
private_module_function :fu_output_message
|
|
2505
2508
|
|
|
2506
|
-
def fu_split_path(path)
|
|
2509
|
+
def fu_split_path(path) #:nodoc:
|
|
2507
2510
|
path = File.path(path)
|
|
2508
2511
|
list = []
|
|
2509
2512
|
until (parent, base = File.split(path); parent == path or parent == ".")
|
|
2510
|
-
list
|
|
2513
|
+
if base != '..' and list.last == '..' and !(fu_have_symlink? && File.symlink?(path))
|
|
2514
|
+
list.pop
|
|
2515
|
+
else
|
|
2516
|
+
list << base
|
|
2517
|
+
end
|
|
2511
2518
|
path = parent
|
|
2512
2519
|
end
|
|
2513
2520
|
list << path
|
|
@@ -2515,16 +2522,16 @@ module FileUtils
|
|
|
2515
2522
|
end
|
|
2516
2523
|
private_module_function :fu_split_path
|
|
2517
2524
|
|
|
2518
|
-
def
|
|
2525
|
+
def fu_common_components(target, base) #:nodoc:
|
|
2519
2526
|
i = 0
|
|
2520
2527
|
while target[i]&.== base[i]
|
|
2521
2528
|
i += 1
|
|
2522
2529
|
end
|
|
2523
|
-
|
|
2530
|
+
i
|
|
2524
2531
|
end
|
|
2525
|
-
private_module_function :
|
|
2532
|
+
private_module_function :fu_common_components
|
|
2526
2533
|
|
|
2527
|
-
def fu_clean_components(*comp)
|
|
2534
|
+
def fu_clean_components(*comp) #:nodoc:
|
|
2528
2535
|
comp.shift while comp.first == "."
|
|
2529
2536
|
return comp if comp.empty?
|
|
2530
2537
|
clean = [comp.shift]
|
|
@@ -2532,7 +2539,7 @@ module FileUtils
|
|
|
2532
2539
|
while c = comp.shift
|
|
2533
2540
|
if c == ".." and clean.last != ".." and !(fu_have_symlink? && File.symlink?(path))
|
|
2534
2541
|
clean.pop
|
|
2535
|
-
path.
|
|
2542
|
+
path.sub!(%r((?<=\A|/)[^/]+/\z), "")
|
|
2536
2543
|
else
|
|
2537
2544
|
clean << c
|
|
2538
2545
|
path << c << "/"
|
|
@@ -2543,11 +2550,11 @@ module FileUtils
|
|
|
2543
2550
|
private_module_function :fu_clean_components
|
|
2544
2551
|
|
|
2545
2552
|
if fu_windows?
|
|
2546
|
-
def fu_starting_path?(path)
|
|
2553
|
+
def fu_starting_path?(path) #:nodoc:
|
|
2547
2554
|
path&.start_with?(%r(\w:|/))
|
|
2548
2555
|
end
|
|
2549
2556
|
else
|
|
2550
|
-
def fu_starting_path?(path)
|
|
2557
|
+
def fu_starting_path?(path) #:nodoc:
|
|
2551
2558
|
path&.start_with?("/")
|
|
2552
2559
|
end
|
|
2553
2560
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
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:
|
|
@@ -17,7 +16,8 @@ executables: []
|
|
|
17
16
|
extensions: []
|
|
18
17
|
extra_rdoc_files: []
|
|
19
18
|
files:
|
|
20
|
-
-
|
|
19
|
+
- BSDL
|
|
20
|
+
- COPYING
|
|
21
21
|
- README.md
|
|
22
22
|
- Rakefile
|
|
23
23
|
- fileutils.gemspec
|
|
@@ -28,7 +28,6 @@ licenses:
|
|
|
28
28
|
- BSD-2-Clause
|
|
29
29
|
metadata:
|
|
30
30
|
source_code_uri: https://github.com/ruby/fileutils
|
|
31
|
-
post_install_message:
|
|
32
31
|
rdoc_options: []
|
|
33
32
|
require_paths:
|
|
34
33
|
- lib
|
|
@@ -43,8 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
43
42
|
- !ruby/object:Gem::Version
|
|
44
43
|
version: '0'
|
|
45
44
|
requirements: []
|
|
46
|
-
rubygems_version: 3.
|
|
47
|
-
signing_key:
|
|
45
|
+
rubygems_version: 3.6.9
|
|
48
46
|
specification_version: 4
|
|
49
47
|
summary: Several file utility methods for copying, moving, removing, etc.
|
|
50
48
|
test_files: []
|