ffi-libarchive 1.0.17 → 1.1.13
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/archive.rb +27 -1
 - data/lib/ffi-libarchive/reader.rb +84 -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: c36407f25d172183c558945197b30ab3de6ce623da69bcb95cd64eef1776ca6e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 6205aba975a305bef359027e6337c80829d2409dd25028ce4562af61e3d58e84
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: e2378c1c786464e9d5b77b6d27f97f5171349f6c5b37a3bccbbe4b597b98cefc972e27a89e22e7232d3554128e8929b296398fa04678d7943aa5e1ed32db6111
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0b30a8db432b3d7e8bb55b64fc284c9e74a343e67812aba08eee46ea15493e8a4998326aa9bbf258eeafe165bf01d90be60d7bb3ec4d430ffe9d19801bf73f19
         
     | 
| 
         @@ -12,11 +12,17 @@ module Archive 
     | 
|
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
                attach_function :archive_version_number, [], :int
         
     | 
| 
       14 
14 
     | 
    
         
             
                attach_function :archive_version_string, [], :string
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                attach_function :archive_compression, [:pointer], :int
         
     | 
| 
      
 17 
     | 
    
         
            +
                attach_function :archive_compression_name, [:pointer], :string
         
     | 
| 
       16 
18 
     | 
    
         
             
                attach_function :archive_errno, [:pointer], :int
         
     | 
| 
      
 19 
     | 
    
         
            +
                attach_function :archive_error_string, [:pointer], :string
         
     | 
| 
      
 20 
     | 
    
         
            +
                attach_function :archive_format, [:pointer], :int
         
     | 
| 
      
 21 
     | 
    
         
            +
                attach_function :archive_format_name, [:pointer], :string
         
     | 
| 
       17 
22 
     | 
    
         | 
| 
       18 
23 
     | 
    
         
             
                attach_function :archive_read_new, [], :pointer
         
     | 
| 
       19 
24 
     | 
    
         
             
                attach_function :archive_read_open_filename, %i{pointer string size_t}, :int
         
     | 
| 
      
 25 
     | 
    
         
            +
                attach_function :archive_read_open_fd, %i{pointer int size_t}, :int
         
     | 
| 
       20 
26 
     | 
    
         
             
                attach_function :archive_read_open_memory, %i{pointer pointer size_t}, :int
         
     | 
| 
       21 
27 
     | 
    
         
             
                attach_function :archive_read_open1, [:pointer], :int
         
     | 
| 
       22 
28 
     | 
    
         
             
                attach_function :archive_read_support_compression_program, %i{pointer string}, :int
         
     | 
| 
         @@ -284,6 +290,10 @@ module Archive 
     | 
|
| 
       284 
290 
     | 
    
         
             
                Reader.open_filename file_name, command, &block
         
     | 
| 
       285 
291 
     | 
    
         
             
              end
         
     | 
| 
       286 
292 
     | 
    
         | 
| 
      
 293 
     | 
    
         
            +
              def self.read_open_fd(fd, command = nil, &block)
         
     | 
| 
      
 294 
     | 
    
         
            +
                Reader.open_fd fd, command, &block
         
     | 
| 
      
 295 
     | 
    
         
            +
              end
         
     | 
| 
      
 296 
     | 
    
         
            +
             
     | 
| 
       287 
297 
     | 
    
         
             
              def self.read_open_memory(string, command = nil, &block)
         
     | 
| 
       288 
298 
     | 
    
         
             
                Reader.open_memory string, command, &block
         
     | 
| 
       289 
299 
     | 
    
         
             
              end
         
     | 
| 
         @@ -355,6 +365,14 @@ module Archive 
     | 
|
| 
       355 
365 
     | 
    
         
             
                end
         
     | 
| 
       356 
366 
     | 
    
         
             
                protected :archive
         
     | 
| 
       357 
367 
     | 
    
         | 
| 
      
 368 
     | 
    
         
            +
                def compression
         
     | 
| 
      
 369 
     | 
    
         
            +
                  C.archive_compression(@archive)
         
     | 
| 
      
 370 
     | 
    
         
            +
                end
         
     | 
| 
      
 371 
     | 
    
         
            +
             
     | 
| 
      
 372 
     | 
    
         
            +
                def compression_name
         
     | 
| 
      
 373 
     | 
    
         
            +
                  C.archive_compression_name(@archive)
         
     | 
| 
      
 374 
     | 
    
         
            +
                end
         
     | 
| 
      
 375 
     | 
    
         
            +
             
     | 
| 
       358 
376 
     | 
    
         
             
                def error_string
         
     | 
| 
       359 
377 
     | 
    
         
             
                  C.archive_error_string(@archive)
         
     | 
| 
       360 
378 
     | 
    
         
             
                end
         
     | 
| 
         @@ -362,5 +380,13 @@ module Archive 
     | 
|
| 
       362 
380 
     | 
    
         
             
                def errno
         
     | 
| 
       363 
381 
     | 
    
         
             
                  C.archive_errno(@archive)
         
     | 
| 
       364 
382 
     | 
    
         
             
                end
         
     | 
| 
      
 383 
     | 
    
         
            +
             
     | 
| 
      
 384 
     | 
    
         
            +
                def format
         
     | 
| 
      
 385 
     | 
    
         
            +
                  C.archive_format(@archive)
         
     | 
| 
      
 386 
     | 
    
         
            +
                end
         
     | 
| 
      
 387 
     | 
    
         
            +
             
     | 
| 
      
 388 
     | 
    
         
            +
                def format_name
         
     | 
| 
      
 389 
     | 
    
         
            +
                  C.archive_format_name(@archive)
         
     | 
| 
      
 390 
     | 
    
         
            +
                end
         
     | 
| 
       365 
391 
     | 
    
         
             
              end
         
     | 
| 
       366 
392 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,16 +2,29 @@ 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 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def self.open_fd(fd, command = nil, strip_components: 0)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  if block_given?
         
     | 
| 
      
 20 
     | 
    
         
            +
                    reader = open_fd fd, command, strip_components: strip_components
         
     | 
| 
      
 21 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 22 
     | 
    
         
            +
                      yield reader
         
     | 
| 
      
 23 
     | 
    
         
            +
                    ensure
         
     | 
| 
      
 24 
     | 
    
         
            +
                      reader.close
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
      
 26 
     | 
    
         
            +
                  else
         
     | 
| 
      
 27 
     | 
    
         
            +
                    new fd: fd, command: command, strip_components: strip_components
         
     | 
| 
       15 
28 
     | 
    
         
             
                  end
         
     | 
| 
       16 
29 
     | 
    
         
             
                end
         
     | 
| 
       17 
30 
     | 
    
         | 
| 
         @@ -41,9 +54,19 @@ module Archive 
     | 
|
| 
       41 
54 
     | 
    
         
             
                  end
         
     | 
| 
       42 
55 
     | 
    
         
             
                end
         
     | 
| 
       43 
56 
     | 
    
         | 
| 
      
 57 
     | 
    
         
            +
                attr_reader :strip_components
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
       44 
59 
     | 
    
         
             
                def initialize(params = {})
         
     | 
| 
       45 
60 
     | 
    
         
             
                  super C.method(:archive_read_new), C.method(:archive_read_finish)
         
     | 
| 
       46 
61 
     | 
    
         | 
| 
      
 62 
     | 
    
         
            +
                  if params[:strip_components]
         
     | 
| 
      
 63 
     | 
    
         
            +
                    raise ArgumentError, "Expected Integer as strip_components" unless params[:strip_components].is_a?(Integer)
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                    @strip_components = params[:strip_components]
         
     | 
| 
      
 66 
     | 
    
         
            +
                  else
         
     | 
| 
      
 67 
     | 
    
         
            +
                    @strip_components = 0
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
       47 
70 
     | 
    
         
             
                  if params[:command]
         
     | 
| 
       48 
71 
     | 
    
         
             
                    cmd = params[:command]
         
     | 
| 
       49 
72 
     | 
    
         
             
                    raise Error, @archive if C.archive_read_support_compression_program(archive, cmd) != C::OK
         
     | 
| 
         @@ -56,6 +79,8 @@ module Archive 
     | 
|
| 
       56 
79 
     | 
    
         
             
                  case
         
     | 
| 
       57 
80 
     | 
    
         
             
                  when params[:file_name]
         
     | 
| 
       58 
81 
     | 
    
         
             
                    raise Error, @archive if C.archive_read_open_filename(archive, params[:file_name], 1024) != C::OK
         
     | 
| 
      
 82 
     | 
    
         
            +
                  when params[:fd]
         
     | 
| 
      
 83 
     | 
    
         
            +
                    raise Error, @archive if C.archive_read_open_fd(archive, params[:fd], 1024) != C::OK
         
     | 
| 
       59 
84 
     | 
    
         
             
                  when params[:memory]
         
     | 
| 
       60 
85 
     | 
    
         
             
                    str = params[:memory]
         
     | 
| 
       61 
86 
     | 
    
         
             
                    @data = FFI::MemoryPointer.new(str.bytesize + 1)
         
     | 
| 
         @@ -131,12 +156,16 @@ module Archive 
     | 
|
| 
       131 
156 
     | 
    
         | 
| 
       132 
157 
     | 
    
         
             
                def each_entry
         
     | 
| 
       133 
158 
     | 
    
         
             
                  while (entry = next_header)
         
     | 
| 
      
 159 
     | 
    
         
            +
                    next if strip_entry_components!(entry).nil?
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
       134 
161 
     | 
    
         
             
                    yield entry
         
     | 
| 
       135 
162 
     | 
    
         
             
                  end
         
     | 
| 
       136 
163 
     | 
    
         
             
                end
         
     | 
| 
       137 
164 
     | 
    
         | 
| 
       138 
165 
     | 
    
         
             
                def each_entry_with_data(_size = C::DATA_BUFFER_SIZE)
         
     | 
| 
       139 
166 
     | 
    
         
             
                  while (entry = next_header)
         
     | 
| 
      
 167 
     | 
    
         
            +
                    next if strip_entry_components!(entry).nil?
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
       140 
169 
     | 
    
         
             
                    yield entry, read_data
         
     | 
| 
       141 
170 
     | 
    
         
             
                  end
         
     | 
| 
       142 
171 
     | 
    
         
             
                end
         
     | 
| 
         @@ -171,5 +200,57 @@ module Archive 
     | 
|
| 
       171 
200 
     | 
    
         
             
                    raise Error, @archive if C.archive_read_data_into_fd(archive, fd) != C::OK
         
     | 
| 
       172 
201 
     | 
    
         
             
                  end
         
     | 
| 
       173 
202 
     | 
    
         
             
                end
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
      
 204 
     | 
    
         
            +
                private
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
      
 206 
     | 
    
         
            +
                #
         
     | 
| 
      
 207 
     | 
    
         
            +
                # See:
         
     | 
| 
      
 208 
     | 
    
         
            +
                #   1. https://github.com/libarchive/libarchive/blob/6a9dcf9fc429e2dc9fb08e669bf7b0bed4d5edf9/tar/read.c#L346
         
     | 
| 
      
 209 
     | 
    
         
            +
                #   2. https://github.com/libarchive/libarchive/blob/a11f15860ae39ecdc8173243a211cdafc8ac893c/tar/util.c#L523-L535
         
     | 
| 
      
 210 
     | 
    
         
            +
                #   3. https://github.com/libarchive/libarchive/blob/a11f15860ae39ecdc8173243a211cdafc8ac893c/tar/util.c#L554-L560
         
     | 
| 
      
 211 
     | 
    
         
            +
                #
         
     | 
| 
      
 212 
     | 
    
         
            +
                # @param entry [Archive::Entry]
         
     | 
| 
      
 213 
     | 
    
         
            +
                #
         
     | 
| 
      
 214 
     | 
    
         
            +
                # @return [Archive::Entry, nil] entry stripped or nil if entry is no longer relevant due to stripping
         
     | 
| 
      
 215 
     | 
    
         
            +
                #
         
     | 
| 
      
 216 
     | 
    
         
            +
                def strip_entry_components!(entry)
         
     | 
| 
      
 217 
     | 
    
         
            +
                  if strip_components > 0
         
     | 
| 
      
 218 
     | 
    
         
            +
                    name = entry.pathname
         
     | 
| 
      
 219 
     | 
    
         
            +
                    original_name = name.dup
         
     | 
| 
      
 220 
     | 
    
         
            +
                    hardlink_name = entry.hardlink
         
     | 
| 
      
 221 
     | 
    
         
            +
                    original_hardlink_name = hardlink_name.dup
         
     | 
| 
      
 222 
     | 
    
         
            +
             
     | 
| 
      
 223 
     | 
    
         
            +
                    strip_path_components!(name)
         
     | 
| 
      
 224 
     | 
    
         
            +
                    return if name.empty?
         
     | 
| 
      
 225 
     | 
    
         
            +
             
     | 
| 
      
 226 
     | 
    
         
            +
                    unless hardlink_name.nil?
         
     | 
| 
      
 227 
     | 
    
         
            +
                      strip_path_components!(hardlink_name)
         
     | 
| 
      
 228 
     | 
    
         
            +
                      return if hardlink_name.empty?
         
     | 
| 
      
 229 
     | 
    
         
            +
                    end
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
                    if name != original_name
         
     | 
| 
      
 232 
     | 
    
         
            +
                      entry.copy_pathname(name)
         
     | 
| 
      
 233 
     | 
    
         
            +
                    end
         
     | 
| 
      
 234 
     | 
    
         
            +
                    entry.copy_hardlink(hardlink_name) if hardlink_name != original_hardlink_name
         
     | 
| 
      
 235 
     | 
    
         
            +
                  end
         
     | 
| 
      
 236 
     | 
    
         
            +
             
     | 
| 
      
 237 
     | 
    
         
            +
                  entry
         
     | 
| 
      
 238 
     | 
    
         
            +
                end
         
     | 
| 
      
 239 
     | 
    
         
            +
             
     | 
| 
      
 240 
     | 
    
         
            +
                #
         
     | 
| 
      
 241 
     | 
    
         
            +
                # @param path [String]
         
     | 
| 
      
 242 
     | 
    
         
            +
                #
         
     | 
| 
      
 243 
     | 
    
         
            +
                # @return [String]
         
     | 
| 
      
 244 
     | 
    
         
            +
                #
         
     | 
| 
      
 245 
     | 
    
         
            +
                def strip_path_components!(path)
         
     | 
| 
      
 246 
     | 
    
         
            +
                  if strip_components > 0
         
     | 
| 
      
 247 
     | 
    
         
            +
                    is_dir = path.end_with?("/")
         
     | 
| 
      
 248 
     | 
    
         
            +
                    updated_path = path.split("/").drop(strip_components).join("/")
         
     | 
| 
      
 249 
     | 
    
         
            +
                    updated_path = is_dir && updated_path != "" ? updated_path + "/" : updated_path
         
     | 
| 
      
 250 
     | 
    
         
            +
                    path.gsub!(path, updated_path)
         
     | 
| 
      
 251 
     | 
    
         
            +
                  else
         
     | 
| 
      
 252 
     | 
    
         
            +
                    path
         
     | 
| 
      
 253 
     | 
    
         
            +
                  end
         
     | 
| 
      
 254 
     | 
    
         
            +
                end
         
     | 
| 
       174 
255 
     | 
    
         
             
              end
         
     | 
| 
       175 
256 
     | 
    
         
             
            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.13
         
     | 
| 
       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:  
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2023-08-07 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 
     | 
    
         
             
              - - ">="
         
     |