zipr 0.2.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
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: c1cb5647f8410511bd09812946a161adacdc465363420c634d739c862a84b5dc
4
+ data.tar.gz: 1ba4bab69bc9c06b4662b32cb1d74f41810819cf3f0326a424c88caafff5ed4c
5
5
  SHA512:
6
- metadata.gz: c16b81553150ba9eb0953136387c2fbd9f6d31e57f630a3501005a7eb0dd4d80bc77fbfbdaa8124ccc4e538cfc429361c7ab5cf77b1d82e1018bf0b09e17977c
7
- data.tar.gz: 548670732186cf43020dd5f47a5d147b6868669da7be05da055967d76ffd1b55c32e23921fcdb40f12d7d9b2a92e325c535944ace9cff2fef02d4bdaf9e6f45f
6
+ metadata.gz: b823246639b77616bc82dddd9c7018a671f159d0df8777520136a7328db96daff199a926b417d84b2489d3b1faed9b8fa93bb4edbe25eb38192ab96142196b78
7
+ data.tar.gz: 7aa3d47e4e7dcd7f8ef8e8e676569cffe33eeec5cf2b60e4a0416947edc85f1fc4c1a91854395f031e9b81109fd0a7c297b4ef366db387e819a47ba564dc9e7a
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
- # 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
212
+ return @checksums.select { |entry_name, checksum| _extract_file?(entry_name, checksum == 'directory', destination_folder, files_to_check) }.keys unless @checksums.nil? || @checksums.empty?
213
+ # If the archive doesn't exist and no checksums were found, extract all files_to_check
214
+ return files_to_check
214
215
  end
215
216
 
216
217
  files_to_extract = case @options[:archive_type]
@@ -233,13 +234,22 @@ module Zipr
233
234
  # An array of files to be added (or the :all symbol).
234
235
  # Parameters:
235
236
  # source_folder: The filesystem directory where files are being added from.
236
- # files_to_check: Array of files intended to be added to an archive. Can be exact names/paths or names/paths with wildcards (glob style).
237
+ # files_to_check: Array of files intended to be added to an archive. Can be exact names/paths or names/paths with wildcards (glob style) or a Regexp.
237
238
  # default: All files and folders under the source_folder.
238
239
  def determine_files_to_add(source_folder, files_to_check: nil)
239
240
  files_to_check ||= Dir.glob("#{source_folder}/**/*".tr('\\', '/')) if files_to_check.nil?
240
241
  files_to_add = []
242
+ source_folder_glob = nil
241
243
  files_to_check.each do |target_search|
242
- files = Dir.glob(Zipr.prepend_source_folder(source_folder, target_search))
244
+ files = if target_search.is_a?(Regexp)
245
+ source_folder_glob ||= Dir.glob("#{source_folder.tr('\\', '/')}/**/*")
246
+ source_folder_glob.select do |path|
247
+ path =~ target_search
248
+ end
249
+ source_folder_glob.select { |path| path.to_s =~ target_search }
250
+ else
251
+ Dir.glob(Zipr.prepend_source_folder(source_folder, target_search))
252
+ end
243
253
  files.each do |source_file|
244
254
  relative_path = Zipr.slice_source_folder(source_folder, source_file)
245
255
  exists_in_zip = !!@checksums[relative_path]
@@ -441,20 +451,30 @@ module Zipr
441
451
  def _excluded_file?(file_path, destination_path: '', exists_in_zip: false)
442
452
  @options[:exclude_files] ||= []
443
453
  @options[:exclude_unless_missing] ||= []
444
- return true if @options[:exclude_files].any? { |e| file_path.tr('\\', '/') =~ /^#{Zipr.wildcard_to_regex(e.tr('\\', '/'))}$/i }
445
- return true if ::File.exist?(destination_path) && @options[:exclude_unless_missing].any? { |e| file_path.tr('\\', '/') =~ /^#{Zipr.wildcard_to_regex(e.tr('\\', '/'))}$/i }
446
- return true if exists_in_zip && @options[:exclude_unless_missing].any? { |e| file_path.tr('\\', '/') =~ /^#{Zipr.wildcard_to_regex(e.tr('\\', '/'))}$/i }
454
+ @options[:exclude_unless_archive_changed] ||= []
455
+ return true if @options[:exclude_files].any? { |e| file_path.tr('\\', '/') =~ _convert_backslashes_and_cast_to_regexp(e) }
456
+ return true if ::File.exist?(destination_path) && @options[:exclude_unless_missing].any? { |e| file_path.tr('\\', '/') =~ _convert_backslashes_and_cast_to_regexp(e) }
457
+ return true if exists_in_zip && @options[:exclude_unless_missing].any? { |e| file_path.tr('\\', '/') =~ _convert_backslashes_and_cast_to_regexp(e) }
458
+ return true if !@archive_changed && ::File.exist?(destination_path) && @options[:exclude_unless_archive_changed].any? { |e| file_path.tr('\\', '/') =~ _convert_backslashes_and_cast_to_regexp(e) }
447
459
  false
448
460
  end
449
461
 
462
+ def _convert_backslashes_and_cast_to_regexp(path)
463
+ return path if path.is_a?(Regexp) # If it's already a regexp, leave it alone
464
+ path = path.tr('\\', '/')
465
+ /^#{Zipr.wildcard_to_regexp(path)}$/i
466
+ end
467
+
450
468
  def _assign_common_accessors(options: nil, checksums: nil, mode: nil)
469
+ _assign_checksums(checksums)
451
470
  @options = options || @options || {}
452
- @checksums = checksums || @checksums || {}
453
471
  @mode = mode || @mode || :idempotent
472
+ @archive_changed = (::File.exist?(@path) && @checksums['archive_checksum'] != Digest::SHA256.file(@path).hexdigest) || !::File.exist?(@checksum_path)
473
+ end
454
474
 
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
475
+ def _assign_checksums(checksums)
476
+ return load_checksum_file if checksums.nil? || checksums.empty? # Read the checksums file if it hasn't been read yet
477
+ @checksums = checksums || {}
458
478
  end
459
479
 
460
480
  # TODO: Add delete method to remove something from an archive
data/lib/zipr/helper.rb CHANGED
@@ -21,21 +21,30 @@ module Zipr
21
21
  def flattened_paths(source_folder, files)
22
22
  return files if source_folder.nil? || source_folder.empty?
23
23
  result = []
24
+ source_folder_glob = nil
24
25
  files.each do |entry|
26
+ if entry.is_a?(Regexp)
27
+ source_folder_glob ||= Dir.glob("#{source_folder.tr('\\', '/')}/**/*")
28
+ matched_files = source_folder_glob.select { |path| path =~ entry }
29
+ result += matched_files.map { |f| slice_source_folder(source_folder, f) }
30
+ next
31
+ end
32
+
25
33
  standardized_entry = "#{source_folder.tr('\\', '/')}/#{slice_source_folder(source_folder, entry)}"
26
34
  files_found = Dir.glob(standardized_entry)
27
35
  if files_found.empty?
28
36
  result.push(entry)
29
37
  else
30
- result += files_found.map { |e| slice_source_folder(source_folder, e) }
38
+ result += files_found.map { |f| slice_source_folder(source_folder, f) }
31
39
  end
32
40
  end
33
41
  result
34
42
  end
35
43
 
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)
44
+ def wildcard_to_regexp(entry)
45
+ return entry if entry.is_a?(Regexp)
46
+ escaped_entry = Regexp.escape(entry).gsub(/\\\*/, '.*') # Convert asterisks to .*
47
+ /#{escaped_entry}/
39
48
  end
40
49
 
41
50
  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.3
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-08-09 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.