ffi-libarchive 1.0.17 → 1.1.3
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/ffi-libarchive/reader.rb +69 -3
- data/lib/ffi-libarchive/version.rb +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad607029b63e0c23ad8bf7ab667c246ec99d122ae09a60430657b1fa6ddd8126
|
4
|
+
data.tar.gz: 57c455b2d4e159da7ccee28faa0f4c347d98e6b92a8ffe70b5c00e6b02a60414
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35b3c1c4737846dedf71efa6925f6c594ff997156cd793a2df39e001d7d874fc74f20a36f38aa0c593718c28ef9bbd64029ec28aadf6e8d2317469e002aaf330
|
7
|
+
data.tar.gz: 5d054df7e653dd6e14f1897cddd0859cdf90e3f26970f2d09701ee0a2ae8c2a89496fe1035850426f7634e01d7fad91cb5ab7b5c7392849d03c8eceace2fe15c
|
@@ -2,16 +2,16 @@ module Archive
|
|
2
2
|
class Reader < BaseArchive
|
3
3
|
private_class_method :new
|
4
4
|
|
5
|
-
def self.open_filename(file_name, command = nil)
|
5
|
+
def self.open_filename(file_name, command = nil, strip_components: 0)
|
6
6
|
if block_given?
|
7
|
-
reader = open_filename file_name, command
|
7
|
+
reader = open_filename file_name, command, strip_components: strip_components
|
8
8
|
begin
|
9
9
|
yield reader
|
10
10
|
ensure
|
11
11
|
reader.close
|
12
12
|
end
|
13
13
|
else
|
14
|
-
new file_name: file_name, command: command
|
14
|
+
new file_name: file_name, command: command, strip_components: strip_components
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -41,9 +41,19 @@ module Archive
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
attr_reader :strip_components
|
45
|
+
|
44
46
|
def initialize(params = {})
|
45
47
|
super C.method(:archive_read_new), C.method(:archive_read_finish)
|
46
48
|
|
49
|
+
if params[:strip_components]
|
50
|
+
raise ArgumentError, "Expected Integer as strip_components" unless params[:strip_components].is_a?(Integer)
|
51
|
+
|
52
|
+
@strip_components = params[:strip_components]
|
53
|
+
else
|
54
|
+
@strip_components = 0
|
55
|
+
end
|
56
|
+
|
47
57
|
if params[:command]
|
48
58
|
cmd = params[:command]
|
49
59
|
raise Error, @archive if C.archive_read_support_compression_program(archive, cmd) != C::OK
|
@@ -131,12 +141,16 @@ module Archive
|
|
131
141
|
|
132
142
|
def each_entry
|
133
143
|
while (entry = next_header)
|
144
|
+
next if strip_entry_components!(entry).nil?
|
145
|
+
|
134
146
|
yield entry
|
135
147
|
end
|
136
148
|
end
|
137
149
|
|
138
150
|
def each_entry_with_data(_size = C::DATA_BUFFER_SIZE)
|
139
151
|
while (entry = next_header)
|
152
|
+
next if strip_entry_components!(entry).nil?
|
153
|
+
|
140
154
|
yield entry, read_data
|
141
155
|
end
|
142
156
|
end
|
@@ -171,5 +185,57 @@ module Archive
|
|
171
185
|
raise Error, @archive if C.archive_read_data_into_fd(archive, fd) != C::OK
|
172
186
|
end
|
173
187
|
end
|
188
|
+
|
189
|
+
private
|
190
|
+
|
191
|
+
#
|
192
|
+
# See:
|
193
|
+
# 1. https://github.com/libarchive/libarchive/blob/6a9dcf9fc429e2dc9fb08e669bf7b0bed4d5edf9/tar/read.c#L346
|
194
|
+
# 2. https://github.com/libarchive/libarchive/blob/a11f15860ae39ecdc8173243a211cdafc8ac893c/tar/util.c#L523-L535
|
195
|
+
# 3. https://github.com/libarchive/libarchive/blob/a11f15860ae39ecdc8173243a211cdafc8ac893c/tar/util.c#L554-L560
|
196
|
+
#
|
197
|
+
# @param entry [Archive::Entry]
|
198
|
+
#
|
199
|
+
# @return [Archive::Entry, nil] entry stripped or nil if entry is no longer relevant due to stripping
|
200
|
+
#
|
201
|
+
def strip_entry_components!(entry)
|
202
|
+
if strip_components > 0
|
203
|
+
name = entry.pathname
|
204
|
+
original_name = name.dup
|
205
|
+
hardlink_name = entry.hardlink
|
206
|
+
original_hardlink_name = hardlink_name.dup
|
207
|
+
|
208
|
+
strip_path_components!(name)
|
209
|
+
return if name.empty?
|
210
|
+
|
211
|
+
unless hardlink_name.nil?
|
212
|
+
strip_path_components!(hardlink_name)
|
213
|
+
return if hardlink_name.empty?
|
214
|
+
end
|
215
|
+
|
216
|
+
if name != original_name
|
217
|
+
entry.copy_pathname(name)
|
218
|
+
end
|
219
|
+
entry.copy_hardlink(hardlink_name) if hardlink_name != original_hardlink_name
|
220
|
+
end
|
221
|
+
|
222
|
+
entry
|
223
|
+
end
|
224
|
+
|
225
|
+
#
|
226
|
+
# @param path [String]
|
227
|
+
#
|
228
|
+
# @return [String]
|
229
|
+
#
|
230
|
+
def strip_path_components!(path)
|
231
|
+
if strip_components > 0
|
232
|
+
is_dir = path.end_with?("/")
|
233
|
+
updated_path = path.split("/").drop(strip_components).join("/")
|
234
|
+
updated_path = is_dir && updated_path != "" ? updated_path + "/" : updated_path
|
235
|
+
path.gsub!(path, updated_path)
|
236
|
+
else
|
237
|
+
path
|
238
|
+
end
|
239
|
+
end
|
174
240
|
end
|
175
241
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-libarchive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Bellone
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-09-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ffi
|
@@ -26,20 +26,6 @@ dependencies:
|
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '1.0'
|
29
|
-
- !ruby/object:Gem::Dependency
|
30
|
-
name: bundler
|
31
|
-
requirement: !ruby/object:Gem::Requirement
|
32
|
-
requirements:
|
33
|
-
- - ">="
|
34
|
-
- !ruby/object:Gem::Version
|
35
|
-
version: '0'
|
36
|
-
type: :development
|
37
|
-
prerelease: false
|
38
|
-
version_requirements: !ruby/object:Gem::Requirement
|
39
|
-
requirements:
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '0'
|
43
29
|
description: A Ruby FFI binding to libarchive.
|
44
30
|
email:
|
45
31
|
- jbellone@bloomberg.net
|
@@ -69,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
55
|
requirements:
|
70
56
|
- - ">="
|
71
57
|
- !ruby/object:Gem::Version
|
72
|
-
version: 2.
|
58
|
+
version: '2.5'
|
73
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
60
|
requirements:
|
75
61
|
- - ">="
|