zipr 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 59ff464e79a2fcb648409fa45f1732713f282b34
4
- data.tar.gz: 3fad749fa16e837f55419322237e945da88e6156
2
+ SHA256:
3
+ metadata.gz: 937bdb977ae3c5773f446384d75a99909dce1525b37a7178d962d0e0b0e7303d
4
+ data.tar.gz: 520bd57c12f5cd9418fe94eff77c9760d3a04e67d2b45ae773fae8722fe7636b
5
5
  SHA512:
6
- metadata.gz: c16b81553150ba9eb0953136387c2fbd9f6d31e57f630a3501005a7eb0dd4d80bc77fbfbdaa8124ccc4e538cfc429361c7ab5cf77b1d82e1018bf0b09e17977c
7
- data.tar.gz: 548670732186cf43020dd5f47a5d147b6868669da7be05da055967d76ffd1b55c32e23921fcdb40f12d7d9b2a92e325c535944ace9cff2fef02d4bdaf9e6f45f
6
+ metadata.gz: 937864d6924a089ede4705c5cba15bd361c050bfc5548230362b4c29eb6c03abcae3209d3178a6e168838cf4078fbcda7792b43c2548d365c76f04a87a905acc
7
+ data.tar.gz: d529bd61f887f1a663245cfa4ce16e2a7469990a071d18b3b49fd9f359352bee4ac3a880cb803b45ed949f2eada808f91bb3cd803035507e6e2deb79418d186b
data/lib/zipr.rb CHANGED
@@ -21,7 +21,7 @@ require 'easy_io'
21
21
  require 'json'
22
22
  require 'tmpdir'
23
23
  require 'fileutils'
24
- require 'seven_zip_ruby_am'
24
+ require 'seven_zip_ruby'
25
25
  require 'os'
26
26
 
27
27
  require_relative 'zipr/config'
data/lib/zipr/archive.rb CHANGED
@@ -14,6 +14,7 @@ module Zipr
14
14
  # :archive_type - The type of archive - :seven_zip or :zip - Can be omitted if the archive exists or using default. Default: :zip
15
15
  # :exclude_files - Array of files to be excluded from archiving/extracting - Can be relative or exact paths.
16
16
  # :exclude_unless_missing - Array of files to be excluded from archiving/extracting only if they already exist - Can be relative or exact paths.
17
+ # :exclude_unless_archive_changed - Array of files to be excluded from extracting only if the archive hasn't changed and they already exist - Use relative paths.
17
18
  # :password - the archive password - currently :seven_zip is the only supported archive_type for encrypted archives.
18
19
  # :silent - [true/false] No info messages if flagged
19
20
  # checksums: A hash of checksums of the archived files. If you checked one of the determine_files methods for idempotency first, pass the result to this parameter to avoid duplicate processing.
@@ -208,9 +209,9 @@ module Zipr
208
209
 
209
210
  unless ::File.exist?(@path)
210
211
  # If the archive doesn't exist but checksums were provided, check for files to extract based off of checksums
211
- return @checksums.select { |entry_name, checksum| _extract_file?(entry_name, checksum == 'directory', destination_folder, files_to_check) }.keys if @checksums.nil? || @checksums.empty?
212
+ return @checksums.select { |entry_name, checksum| _extract_file?(entry_name, checksum == 'directory', destination_folder, files_to_check) }.keys unless @checksums.nil? || @checksums.empty?
212
213
  # If the archive doesn't exist and no checksums were found, extract all files_to_check or :all files
213
- return files_to_check || :all
214
+ return files_to_check
214
215
  end
215
216
 
216
217
  files_to_extract = case @options[:archive_type]
@@ -441,20 +442,24 @@ module Zipr
441
442
  def _excluded_file?(file_path, destination_path: '', exists_in_zip: false)
442
443
  @options[:exclude_files] ||= []
443
444
  @options[:exclude_unless_missing] ||= []
445
+ @options[:exclude_unless_archive_changed] ||= []
444
446
  return true if @options[:exclude_files].any? { |e| file_path.tr('\\', '/') =~ /^#{Zipr.wildcard_to_regex(e.tr('\\', '/'))}$/i }
445
447
  return true if ::File.exist?(destination_path) && @options[:exclude_unless_missing].any? { |e| file_path.tr('\\', '/') =~ /^#{Zipr.wildcard_to_regex(e.tr('\\', '/'))}$/i }
446
448
  return true if exists_in_zip && @options[:exclude_unless_missing].any? { |e| file_path.tr('\\', '/') =~ /^#{Zipr.wildcard_to_regex(e.tr('\\', '/'))}$/i }
449
+ return true if !@archive_changed && ::File.exist?(destination_path) && @options[:exclude_unless_archive_changed].any? { |e| file_path.tr('\\', '/') =~ /^#{Zipr.wildcard_to_regex(e.tr('\\', '/'))}$/i }
447
450
  false
448
451
  end
449
452
 
450
453
  def _assign_common_accessors(options: nil, checksums: nil, mode: nil)
454
+ _assign_checksums(checksums)
451
455
  @options = options || @options || {}
452
- @checksums = checksums || @checksums || {}
453
456
  @mode = mode || @mode || :idempotent
457
+ @archive_changed = ::File.exist?(@path) && @checksums['archive_checksum'] != Digest::SHA256.file(@path).hexdigest
458
+ end
454
459
 
455
- archive_changed = ::File.exist?(@path) && @checksums['archive_checksum'] != Digest::SHA256.file(@path).hexdigest
456
- outdated_checksums = @checksums.empty? || archive_changed
457
- load_checksum_file if outdated_checksums # Read the checksums file if it hasn't been read yet
460
+ def _assign_checksums(checksums)
461
+ return load_checksum_file if checksums.nil? || checksums.empty? # Read the checksums file if it hasn't been read yet
462
+ @checksums = checksums || {}
458
463
  end
459
464
 
460
465
  # TODO: Add delete method to remove something from an archive
data/lib/zipr/helper.rb CHANGED
@@ -34,8 +34,9 @@ module Zipr
34
34
  end
35
35
 
36
36
  def wildcard_to_regex(entry)
37
- entry.gsub(/([^\.\]])\*/, '\1.*') # convert any asterisk wildcard not preceded by a period or square bracket to .*
38
- .sub(/^\*/, '.*') # convert a string that starts with an asterisk to .* (not preceded by anything)
37
+ return entry if entry.is_a?(Regexp)
38
+ escaped_entry = Regexp.escape(entry).gsub(/\\\*/, '.*') # Convert asterisks to .*
39
+ /#{escaped_entry}/
39
40
  end
40
41
 
41
42
  def prepend_source_folder(source_folder, entry)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Munoz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-27 00:00:00.000000000 Z
11
+ date: 2021-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: easy_io
@@ -53,25 +53,19 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: seven_zip_ruby_am
56
+ name: seven_zip_ruby
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.2'
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 1.2.5.4
61
+ version: '1.3'
65
62
  type: :runtime
66
63
  prerelease: false
67
64
  version_requirements: !ruby/object:Gem::Requirement
68
65
  requirements:
69
66
  - - "~>"
70
67
  - !ruby/object:Gem::Version
71
- version: '1.2'
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: 1.2.5.4
68
+ version: '1.3'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: os
77
71
  requirement: !ruby/object:Gem::Requirement
@@ -134,8 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
128
  - !ruby/object:Gem::Version
135
129
  version: '0'
136
130
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.5.2.3
131
+ rubygems_version: 3.0.3
139
132
  signing_key:
140
133
  specification_version: 4
141
134
  summary: Ruby library for easily extracting and creating 7zip and zip archives idempotently.