minitar 1.0.2 → 1.1.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/CHANGELOG.md +326 -0
- data/CODE_OF_CONDUCT.md +167 -0
- data/CONTRIBUTING.md +312 -0
- data/CONTRIBUTORS.md +27 -0
- data/LICENCE.md +42 -0
- data/Manifest.txt +31 -8
- data/README.md +82 -0
- data/Rakefile +74 -20
- data/SECURITY.md +54 -0
- data/lib/minitar/input.rb +242 -189
- data/lib/minitar/output.rb +72 -64
- data/lib/minitar/pax_header.rb +111 -0
- data/lib/minitar/posix_header.rb +276 -239
- data/lib/minitar/reader.rb +226 -231
- data/lib/minitar/version.rb +5 -0
- data/lib/minitar/writer.rb +246 -299
- data/lib/minitar.rb +134 -115
- data/licenses/bsdl.txt +20 -0
- data/licenses/dco.txt +34 -0
- data/licenses/ruby.txt +52 -0
- data/test/fixtures/issue_46.tar.gz +0 -0
- data/test/fixtures/issue_62.tar.gz +0 -0
- data/test/fixtures/tar_input.tgz +0 -0
- data/test/fixtures/test_input_non_strict_octal.tgz +0 -0
- data/test/fixtures/test_input_relative.tgz +0 -0
- data/test/fixtures/test_input_space_octal.tgz +0 -0
- data/test/fixtures/test_minitar.tar.gz +0 -0
- data/test/minitest_helper.rb +12 -1
- data/test/support/minitar_test_helpers/fixtures.rb +38 -0
- data/test/support/minitar_test_helpers/header.rb +130 -0
- data/test/support/minitar_test_helpers/tarball.rb +324 -0
- data/test/support/minitar_test_helpers.rb +36 -0
- data/test/test_filename_boundary_conditions.rb +74 -0
- data/test/test_gnu_tar_compatibility.rb +92 -0
- data/test/test_integration_pack_unpack_cycle.rb +38 -0
- data/test/test_issue_46.rb +5 -23
- data/test/test_issue_62.rb +50 -0
- data/test/test_minitar.rb +168 -39
- data/test/test_path_normalization.rb +170 -0
- data/test/test_pax_header.rb +104 -0
- data/test/test_pax_support.rb +66 -0
- data/test/test_tar_header.rb +289 -75
- data/test/test_tar_input.rb +14 -61
- data/test/test_tar_output.rb +7 -9
- data/test/test_tar_reader.rb +17 -18
- data/test/test_tar_writer.rb +105 -126
- data/test/test_windows_extraction.rb +121 -0
- metadata +108 -95
- data/Code-of-Conduct.md +0 -128
- data/Contributing.md +0 -94
- data/History.md +0 -236
- data/Licence.md +0 -15
- data/README.rdoc +0 -92
- data/docs/bsdl.txt +0 -19
- data/docs/ruby.txt +0 -56
- data/test/support/tar_test_helpers.rb +0 -134
data/SECURITY.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Minitar Security Policy
|
|
2
|
+
|
|
3
|
+
Minitar aims to be secure by default for the data _inside_ of a tar file.
|
|
4
|
+
|
|
5
|
+
## LLM-Generated Security Report Policy
|
|
6
|
+
|
|
7
|
+
Absolutely no security reports will be accepted that have been generated
|
|
8
|
+
solely by LLM agents. There must be a human that confirms the issue.
|
|
9
|
+
|
|
10
|
+
## Supported Versions
|
|
11
|
+
|
|
12
|
+
Security reports are accepted only for the most recent major release.
|
|
13
|
+
|
|
14
|
+
## Reporting a Vulnerability
|
|
15
|
+
|
|
16
|
+
Report vulnerabilities via the [Tidelift security contact][tidelift]. Tidelift
|
|
17
|
+
will coordinate the fix and disclosure.
|
|
18
|
+
|
|
19
|
+
Alternatively, create a [private vulnerability report][advisory] with GitHub.
|
|
20
|
+
|
|
21
|
+
## Exclusions
|
|
22
|
+
|
|
23
|
+
There are several classes of potential security issues that will **not** be
|
|
24
|
+
accepted for Minitar, because any issues arising from these are a matter of
|
|
25
|
+
the library being used incorrectly.
|
|
26
|
+
|
|
27
|
+
- [CWE-073](https://cwe.mitre.org/data/definitions/73.html)
|
|
28
|
+
- [CWE-078](https://cwe.mitre.org/data/definitions/78.html)
|
|
29
|
+
- [CWE-088](https://cwe.mitre.org/data/definitions/88.html)
|
|
30
|
+
|
|
31
|
+
Minitar does _not_ perform validation or sanitization of path names provided
|
|
32
|
+
to the convenience classes `Minitar::Output` and `Minitar::Input`, which use
|
|
33
|
+
`Kernel.open` for their underlying implementations when not given an IO-like
|
|
34
|
+
object.
|
|
35
|
+
|
|
36
|
+
Improper use of these convenience classes with arbitrary input filenames may
|
|
37
|
+
leave your your software to the same class of vulnerability as reported for
|
|
38
|
+
Net::FTP ([CVE-2017-17405][CVE-2017-17405]). If the input filename argument
|
|
39
|
+
starts with the pipe character (`|`), the command following the pipe character
|
|
40
|
+
is executed.
|
|
41
|
+
|
|
42
|
+
Additionally, the use of the `open-uri` library (which extends `Kernel.open`
|
|
43
|
+
with transparent implementations for `Net::HTTP`, `Net::HTTPS`, and
|
|
44
|
+
`Net::FTP`), there are other possible vulnerabilities when accepting arbitrary
|
|
45
|
+
input, as [detailed][openuri] by Egor Homakov.
|
|
46
|
+
|
|
47
|
+
These security vulnerabilities may be avoided, even with the `Minitar::Output`
|
|
48
|
+
and `Minitar::Input` convenience classes, by providing IO-like objects instead
|
|
49
|
+
of pathname-like objects as the source or destination of these classes.
|
|
50
|
+
|
|
51
|
+
[CVE-2017-17405]: https://nvd.nist.gov/vuln/detail/CVE-2017-17405
|
|
52
|
+
[advisory]: https://github.com/halostatue/diff-lcs/security/advisories/new
|
|
53
|
+
[openuri]: https://sakurity.com/blog/2015/02/28/openuri.html
|
|
54
|
+
[tidelift]: https://tidelift.com/security
|
data/lib/minitar/input.rb
CHANGED
|
@@ -1,239 +1,292 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# This wraps a Minitar::Reader with convenience methods and wrapped stream management;
|
|
4
|
+
# Input only works with data streams that can be rewound.
|
|
5
|
+
#
|
|
6
|
+
# ### Security Notice
|
|
7
|
+
#
|
|
8
|
+
# Constructing a Minitar::Input will use Kernel.open if the provided input is not
|
|
9
|
+
# a readable stream object. Using an untrusted value for input may allow a malicious
|
|
10
|
+
# user to execute arbitrary system commands. It is the **caller's responsibility** to
|
|
11
|
+
# ensure that the input value is safe.
|
|
12
|
+
#
|
|
13
|
+
# * [CWE-073](https://cwe.mitre.org/data/definitions/73.html)
|
|
14
|
+
# * [CWE-078](https://cwe.mitre.org/data/definitions/78.html)
|
|
15
|
+
# * [CWE-088](https://cwe.mitre.org/data/definitions/88.html)
|
|
16
|
+
#
|
|
17
|
+
# This notice applies to Minitar::Input.open, Minitar::Input.each_entry, and
|
|
18
|
+
# Minitar::Input.new.
|
|
19
|
+
class Minitar::Input
|
|
20
|
+
include Enumerable
|
|
21
|
+
|
|
22
|
+
# With no associated block, `Input.open` is a synonym for `Input.new`.
|
|
23
|
+
#
|
|
24
|
+
# If a block is given, the new Input will be yielded to the block as an argument and
|
|
25
|
+
# the Input object will automatically be closed when the block terminates (this also
|
|
26
|
+
# closes the wrapped stream object). The return value will be the value of the block.
|
|
27
|
+
#
|
|
28
|
+
# :call-seq:
|
|
29
|
+
# Minitar::Input.open(io) -> input
|
|
30
|
+
# Minitar::Input.open(io) { |input| block } -> obj
|
|
31
|
+
def self.open(input)
|
|
32
|
+
stream = new(input)
|
|
33
|
+
|
|
34
|
+
if block_given?
|
|
35
|
+
# This exception context must remain, otherwise the stream closes on open even if
|
|
36
|
+
# a block is not given.
|
|
37
|
+
begin
|
|
38
|
+
yield stream
|
|
39
|
+
ensure
|
|
40
|
+
stream.close
|
|
31
41
|
end
|
|
42
|
+
else
|
|
43
|
+
stream
|
|
32
44
|
end
|
|
45
|
+
end
|
|
33
46
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
end
|
|
47
|
+
# Iterates over each entry in the provided input. This wraps the common pattern of:
|
|
48
|
+
#
|
|
49
|
+
# ```ruby
|
|
50
|
+
# Minitar::Input.open(io) do |i|
|
|
51
|
+
# inp.each do |entry|
|
|
52
|
+
# # ...
|
|
53
|
+
# end
|
|
54
|
+
# end
|
|
55
|
+
# ```
|
|
56
|
+
#
|
|
57
|
+
# If a block is not provided, an enumerator will be created with the same behaviour.
|
|
58
|
+
#
|
|
59
|
+
# :call-seq:
|
|
60
|
+
# Minitar::Input.each_entry(io) -> enumerator
|
|
61
|
+
# Minitar::Input.each_entry(io) { |entry| block } -> obj
|
|
62
|
+
def self.each_entry(input)
|
|
63
|
+
return to_enum(__method__, input) unless block_given?
|
|
64
|
+
|
|
65
|
+
Input.open(input) do |stream|
|
|
66
|
+
stream.each do |entry|
|
|
67
|
+
yield entry
|
|
56
68
|
end
|
|
57
69
|
end
|
|
70
|
+
end
|
|
58
71
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
# Creates a new Input object. If `input` is a stream object that responds to #read,
|
|
73
|
+
# then it will simply be wrapped. Otherwise, one will be created and opened using
|
|
74
|
+
# Kernel.open. When Input#close is called, the stream object wrapped will be closed.
|
|
75
|
+
#
|
|
76
|
+
# An exception will be raised if the stream that is wrapped does not support
|
|
77
|
+
# rewinding.
|
|
78
|
+
#
|
|
79
|
+
# :call-seq:
|
|
80
|
+
# Minitar::Input.new(io) -> input
|
|
81
|
+
# Minitar::Input.new(path) -> input
|
|
82
|
+
def initialize(input)
|
|
83
|
+
@io =
|
|
84
|
+
if input.respond_to?(:read)
|
|
72
85
|
input
|
|
73
86
|
else
|
|
74
87
|
::Kernel.open(input, "rb")
|
|
75
88
|
end
|
|
76
89
|
|
|
77
|
-
|
|
78
|
-
raise Minitar::NonSeekableStream
|
|
79
|
-
end
|
|
90
|
+
raise Minitar::NonSeekableStream unless Minitar.seekable?(@io, :rewind)
|
|
80
91
|
|
|
81
|
-
|
|
82
|
-
|
|
92
|
+
@tar = Minitar::Reader.new(@io)
|
|
93
|
+
end
|
|
83
94
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
95
|
+
# When provided a block, iterates through each entry in the archive. When finished,
|
|
96
|
+
# rewinds to the beginning of the stream.
|
|
97
|
+
#
|
|
98
|
+
# If not provided a block, creates an enumerator with the same semantics.
|
|
99
|
+
def each_entry
|
|
100
|
+
return to_enum unless block_given?
|
|
90
101
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
end
|
|
94
|
-
ensure
|
|
95
|
-
@tar.rewind
|
|
102
|
+
@tar.each do |entry|
|
|
103
|
+
yield entry
|
|
96
104
|
end
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
end
|
|
105
|
+
ensure
|
|
106
|
+
@tar.rewind
|
|
107
|
+
end
|
|
108
|
+
alias_method :each, :each_entry
|
|
109
|
+
|
|
110
|
+
# Extracts the current `entry` to `destdir`. If a block is provided, it yields an
|
|
111
|
+
# `action` Symbol, the full name of the file being extracted (`name`), and a Hash of
|
|
112
|
+
# statistical information (`stats`).
|
|
113
|
+
#
|
|
114
|
+
# The `action` will be one of:
|
|
115
|
+
#
|
|
116
|
+
# - `:dir`: The `entry` is a directory.
|
|
117
|
+
# - `:file_start`: The `entry` is a file; the extract of the file is just beginning.
|
|
118
|
+
# - `:file_progress`: Yielded every 4096 bytes during the extract of the `entry`.
|
|
119
|
+
# - `:file_done`: Yielded when the `entry` is completed.
|
|
120
|
+
#
|
|
121
|
+
# The `stats` hash may contain the following keys:
|
|
122
|
+
#
|
|
123
|
+
# - `:current`: The current total number of bytes read in the `entry`.
|
|
124
|
+
# - `:currinc`: The current number of bytes read in this read cycle.
|
|
125
|
+
# - `:entry`: The entry being extracted; this is a Minitar::Reader::EntryStream.
|
|
126
|
+
def extract_entry(destdir, entry, options = {}, &) # :yields: action, name, stats
|
|
127
|
+
stats = {
|
|
128
|
+
current: 0,
|
|
129
|
+
currinc: 0,
|
|
130
|
+
entry: entry
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
# extract_entry is not vulnerable to prefix '/' vulnerabilities; check and reject
|
|
134
|
+
# relative path directories on both Windows and Unix-like systems. This is a hard
|
|
135
|
+
# rejection by throwing exceptions. Future versions may permit relative paths as long
|
|
136
|
+
# as the file does not leave `destdir`.
|
|
137
|
+
full_name = normalize_entry_name(entry.full_name)
|
|
138
|
+
check_relative_path!(full_name)
|
|
139
|
+
|
|
140
|
+
if entry.directory?
|
|
141
|
+
extract_directory(destdir, full_name, entry, stats, options, &)
|
|
142
|
+
else # it's a file
|
|
143
|
+
extract_file(destdir, full_name, entry, stats, options, &)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
139
146
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
# Returns false if the wrapped data stream is open.
|
|
148
|
+
def closed? = @io.closed?
|
|
149
|
+
|
|
150
|
+
# Returns the Minitar::Reader object for direct access.
|
|
151
|
+
attr_reader :tar
|
|
152
|
+
|
|
153
|
+
# Closes both the Minitar::Reader object and the wrapped data stream.
|
|
154
|
+
def close
|
|
155
|
+
@io.close
|
|
156
|
+
@tar.close
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
private
|
|
160
|
+
|
|
161
|
+
# Normalizes an entry name as the filesystem will interpret it.
|
|
162
|
+
#
|
|
163
|
+
# On Unix-like systems (`File::ALT_SEPARATOR.nil?`), consecutive `/` are always
|
|
164
|
+
# squeezed to a single `/`.
|
|
165
|
+
#
|
|
166
|
+
# On Windows, the normalization _and check_ are more extensive:
|
|
167
|
+
#
|
|
168
|
+
# - All `\` are normalized to `/` and squeezed.
|
|
169
|
+
# - Drive designators `[A-Z]:` are rejected with UnsafeFileNameError.
|
|
170
|
+
# - Files with `:` are rejected with UnsafeFileNameError (NTFS alternate data streams
|
|
171
|
+
# are removed with `File.basename`, causing file aliasing).
|
|
172
|
+
# - Each path component is examined to see if, aside from `..` and `.`, it contains
|
|
173
|
+
# a trailing dot or space. These are rejected with UnsafeFileNameError due to file
|
|
174
|
+
# aliasing.
|
|
175
|
+
def normalize_entry_name(name, alt_separator = File::ALT_SEPARATOR)
|
|
176
|
+
return name.squeeze("/") unless alt_separator
|
|
177
|
+
|
|
178
|
+
name = name.tr(alt_separator, "/").squeeze("/")
|
|
179
|
+
|
|
180
|
+
# A drive designator looks like a directory (`C:` is a drive, not a stream name), so
|
|
181
|
+
# it is called out separately from the general `:` check below.
|
|
182
|
+
if name.match?(/\A[A-Za-z]:/)
|
|
183
|
+
raise Minitar::UnsafeFileNameError, "Path begins with a drive designator"
|
|
145
184
|
end
|
|
146
185
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
@io.closed?
|
|
186
|
+
if name.include?(":")
|
|
187
|
+
raise Minitar::UnsafeFileNameError, "Path contains ':'"
|
|
150
188
|
end
|
|
151
189
|
|
|
152
|
-
#
|
|
153
|
-
|
|
190
|
+
# Win32 trims trailing dots and spaces from path components, so `...`, `.. `, and
|
|
191
|
+
# `dirname..` alias a different name (often the containing directory) than the
|
|
192
|
+
# literal name in the archive. `.` and `..` are left alone: `.` is harmless and `..`
|
|
193
|
+
# is handled by #check_relative_path!.
|
|
194
|
+
name.split("/").each do |part|
|
|
195
|
+
next if part == "." || part == ".."
|
|
154
196
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
@tar.close
|
|
197
|
+
if part.match?(/[ .]\z/)
|
|
198
|
+
raise Minitar::UnsafeFileNameError, "Path component ends with '.' or ' '"
|
|
199
|
+
end
|
|
159
200
|
end
|
|
160
201
|
|
|
161
|
-
|
|
202
|
+
name
|
|
203
|
+
end
|
|
162
204
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
nil
|
|
169
|
-
ensure
|
|
170
|
-
dir&.close rescue nil # standard:disable Style/RescueModifier
|
|
205
|
+
# Raises Minitar::SecureRelativePathError if any path component of the (normalized)
|
|
206
|
+
# `name` is `..`.
|
|
207
|
+
def check_relative_path!(name)
|
|
208
|
+
if %r{(?:\A|/)\.\.(?:/|\z)}.match?(name)
|
|
209
|
+
raise Minitar::SecureRelativePathError, "Path contains '..'"
|
|
171
210
|
end
|
|
211
|
+
end
|
|
172
212
|
|
|
173
|
-
|
|
174
|
-
|
|
213
|
+
def fsync_dir(dirname)
|
|
214
|
+
# make sure this hits the disc
|
|
215
|
+
dir = IO.open(dirname, "rb")
|
|
216
|
+
dir.fsync
|
|
217
|
+
rescue # ignore IOError if it's an unpatched (old) Ruby
|
|
218
|
+
nil
|
|
219
|
+
ensure
|
|
220
|
+
dir&.close rescue nil # standard:disable Style/RescueModifier
|
|
221
|
+
end
|
|
175
222
|
|
|
176
|
-
|
|
223
|
+
def extract_directory(destdir, full_name, entry, stats, options)
|
|
224
|
+
dest = File.join(destdir, full_name)
|
|
177
225
|
|
|
178
|
-
|
|
179
|
-
begin
|
|
180
|
-
FileUtils.chmod(entry.mode, dest)
|
|
181
|
-
rescue
|
|
182
|
-
nil
|
|
183
|
-
end
|
|
184
|
-
else
|
|
185
|
-
File.unlink(dest.chomp("/")) if File.symlink?(dest.chomp("/"))
|
|
226
|
+
yield :dir, full_name, stats if block_given?
|
|
186
227
|
|
|
187
|
-
|
|
228
|
+
if Minitar.dir?(dest)
|
|
229
|
+
begin
|
|
188
230
|
FileUtils.chmod(entry.mode, dest)
|
|
231
|
+
rescue
|
|
232
|
+
nil
|
|
189
233
|
end
|
|
234
|
+
else
|
|
235
|
+
File.unlink(dest.chomp("/")) if File.symlink?(dest.chomp("/"))
|
|
190
236
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
fsync_dir(File.join(dest, ".."))
|
|
194
|
-
end
|
|
237
|
+
FileUtils.mkdir_p(dest, mode: entry.mode)
|
|
238
|
+
FileUtils.chmod(entry.mode, dest)
|
|
195
239
|
end
|
|
196
240
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
241
|
+
if options.fetch(:fsync, true)
|
|
242
|
+
fsync_dir(dest)
|
|
243
|
+
fsync_dir(File.join(dest, ".."))
|
|
244
|
+
end
|
|
245
|
+
end
|
|
200
246
|
|
|
201
|
-
|
|
247
|
+
def extract_file(destdir, full_name, entry, stats, options)
|
|
248
|
+
destdir = File.join(destdir, File.dirname(full_name))
|
|
249
|
+
FileUtils.mkdir_p(destdir, mode: 0o755)
|
|
202
250
|
|
|
203
|
-
|
|
251
|
+
destfile = File.join(destdir, File.basename(full_name))
|
|
204
252
|
|
|
205
|
-
|
|
206
|
-
FileUtils.chmod(0o600, destfile) rescue nil # standard:disable Style/RescueModifier
|
|
253
|
+
File.unlink(destfile) if File.symlink?(destfile)
|
|
207
254
|
|
|
208
|
-
|
|
255
|
+
# Errno::ENOENT
|
|
256
|
+
begin
|
|
257
|
+
FileUtils.chmod(0o600, destfile)
|
|
258
|
+
rescue
|
|
259
|
+
nil
|
|
260
|
+
end
|
|
209
261
|
|
|
210
|
-
|
|
211
|
-
loop do
|
|
212
|
-
data = entry.read(4096)
|
|
213
|
-
break unless data
|
|
262
|
+
yield :file_start, full_name, stats if block_given?
|
|
214
263
|
|
|
215
|
-
|
|
216
|
-
|
|
264
|
+
File.open(destfile, "wb", entry.mode) do |os|
|
|
265
|
+
loop do
|
|
266
|
+
data = entry.read(4096)
|
|
267
|
+
break unless data
|
|
217
268
|
|
|
218
|
-
|
|
219
|
-
|
|
269
|
+
stats[:currinc] = os.write(data)
|
|
270
|
+
stats[:current] += stats[:currinc]
|
|
220
271
|
|
|
221
|
-
|
|
222
|
-
yield :file_fsync, full_name, stats if block_given?
|
|
223
|
-
os.fsync
|
|
224
|
-
end
|
|
272
|
+
yield :file_progress, full_name, stats if block_given?
|
|
225
273
|
end
|
|
226
274
|
|
|
227
|
-
FileUtils.chmod(entry.mode, destfile)
|
|
228
|
-
|
|
229
275
|
if options.fetch(:fsync, true)
|
|
230
|
-
yield :
|
|
231
|
-
|
|
232
|
-
fsync_dir(File.dirname(destfile))
|
|
233
|
-
fsync_dir(File.join(File.dirname(destfile), ".."))
|
|
276
|
+
yield :file_fsync, full_name, stats if block_given?
|
|
277
|
+
os.fsync
|
|
234
278
|
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
FileUtils.chmod(entry.mode, destfile)
|
|
235
282
|
|
|
236
|
-
|
|
283
|
+
if options.fetch(:fsync, true)
|
|
284
|
+
yield :dir_fsync, full_name, stats if block_given?
|
|
285
|
+
|
|
286
|
+
fsync_dir(File.dirname(destfile))
|
|
287
|
+
fsync_dir(File.join(File.dirname(destfile), ".."))
|
|
237
288
|
end
|
|
289
|
+
|
|
290
|
+
yield :file_done, full_name, stats if block_given?
|
|
238
291
|
end
|
|
239
292
|
end
|