zipr 0.3.0 → 0.3.4

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
2
  SHA256:
3
- metadata.gz: 937bdb977ae3c5773f446384d75a99909dce1525b37a7178d962d0e0b0e7303d
4
- data.tar.gz: 520bd57c12f5cd9418fe94eff77c9760d3a04e67d2b45ae773fae8722fe7636b
3
+ metadata.gz: 6976718d5e5290a0ae2569b40ddbcb99e96215356a1ec154f3b6bfe2a2486062
4
+ data.tar.gz: d59070f7523eb976b4e443440e7c8f5468b42fc7465ad95041f10081971bfdb4
5
5
  SHA512:
6
- metadata.gz: 937864d6924a089ede4705c5cba15bd361c050bfc5548230362b4c29eb6c03abcae3209d3178a6e168838cf4078fbcda7792b43c2548d365c76f04a87a905acc
7
- data.tar.gz: d529bd61f887f1a663245cfa4ce16e2a7469990a071d18b3b49fd9f359352bee4ac3a880cb803b45ed949f2eada808f91bb3cd803035507e6e2deb79418d186b
6
+ metadata.gz: 31dd85955d53b08413d931d7a65c755c697c2b54e1dd3d85d54fea007fcd346e079b5badac853815670644d15f06e16ea460c00c13a1257817b98ee0b05f6b39
7
+ data.tar.gz: fe3f113d4098f1ddfac92b70b470b3aced82a49806b78f0df4284330e75e433595da060699ad4121fc6afaf23d13ed251289e4c76b8cbc9005325952fff16e44
data/lib/zipr/archive.rb CHANGED
@@ -210,7 +210,7 @@ module Zipr
210
210
  unless ::File.exist?(@path)
211
211
  # If the archive doesn't exist but checksums were provided, check for files to extract based off of checksums
212
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 or :all files
213
+ # If the archive doesn't exist and no checksums were found, extract all files_to_check
214
214
  return files_to_check
215
215
  end
216
216
 
@@ -234,13 +234,22 @@ module Zipr
234
234
  # An array of files to be added (or the :all symbol).
235
235
  # Parameters:
236
236
  # source_folder: The filesystem directory where files are being added from.
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).
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.
238
238
  # default: All files and folders under the source_folder.
239
239
  def determine_files_to_add(source_folder, files_to_check: nil)
240
240
  files_to_check ||= Dir.glob("#{source_folder}/**/*".tr('\\', '/')) if files_to_check.nil?
241
241
  files_to_add = []
242
+ source_folder_glob = nil
242
243
  files_to_check.each do |target_search|
243
- 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
244
253
  files.each do |source_file|
245
254
  relative_path = Zipr.slice_source_folder(source_folder, source_file)
246
255
  exists_in_zip = !!@checksums[relative_path]
@@ -432,6 +441,7 @@ module Zipr
432
441
  def _extract_file?(archive_entry_name, is_a_directory, destination_folder, files_to_check)
433
442
  destination_path = "#{destination_folder}/#{archive_entry_name}"
434
443
  return false unless files_to_check == :all || files_to_check.include?(archive_entry_name) # Make sure the file is in the whitelist if it was provided
444
+ return false if archive_entry_name == 'archive_checksum'
435
445
  return false if ::File.directory?(destination_path) && is_a_directory # Archive item is a directory and the destination directory exists
436
446
  return false if @mode == :if_missing && ::File.exist?(destination_path) # File exists and we're not overwriting existing files due to the mode
437
447
  return false if _excluded_file?(archive_entry_name, destination_path: destination_path) # File is excluded in :options
@@ -443,18 +453,24 @@ module Zipr
443
453
  @options[:exclude_files] ||= []
444
454
  @options[:exclude_unless_missing] ||= []
445
455
  @options[:exclude_unless_archive_changed] ||= []
446
- return true if @options[:exclude_files].any? { |e| file_path.tr('\\', '/') =~ /^#{Zipr.wildcard_to_regex(e.tr('\\', '/'))}$/i }
447
- return true if ::File.exist?(destination_path) && @options[:exclude_unless_missing].any? { |e| file_path.tr('\\', '/') =~ /^#{Zipr.wildcard_to_regex(e.tr('\\', '/'))}$/i }
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 }
456
+ return true if @options[:exclude_files].any? { |e| file_path.tr('\\', '/') =~ _convert_backslashes_and_cast_to_regexp(e) }
457
+ return true if ::File.exist?(destination_path) && @options[:exclude_unless_missing].any? { |e| file_path.tr('\\', '/') =~ _convert_backslashes_and_cast_to_regexp(e) }
458
+ return true if exists_in_zip && @options[:exclude_unless_missing].any? { |e| file_path.tr('\\', '/') =~ _convert_backslashes_and_cast_to_regexp(e) }
459
+ 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) }
450
460
  false
451
461
  end
452
462
 
463
+ def _convert_backslashes_and_cast_to_regexp(path)
464
+ return path if path.is_a?(Regexp) # If it's already a regexp, leave it alone
465
+ path = path.tr('\\', '/')
466
+ /^#{Zipr.wildcard_to_regexp(path)}$/i
467
+ end
468
+
453
469
  def _assign_common_accessors(options: nil, checksums: nil, mode: nil)
454
470
  _assign_checksums(checksums)
455
471
  @options = options || @options || {}
456
472
  @mode = mode || @mode || :idempotent
457
- @archive_changed = ::File.exist?(@path) && @checksums['archive_checksum'] != Digest::SHA256.file(@path).hexdigest
473
+ @archive_changed = (::File.exist?(@path) && @checksums['archive_checksum'] != Digest::SHA256.file(@path).hexdigest) || !::File.exist?(@checksum_path)
458
474
  end
459
475
 
460
476
  def _assign_checksums(checksums)
data/lib/zipr/helper.rb CHANGED
@@ -21,19 +21,27 @@ 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)
44
+ def wildcard_to_regexp(entry)
37
45
  return entry if entry.is_a?(Regexp)
38
46
  escaped_entry = Regexp.escape(entry).gsub(/\\\*/, '.*') # Convert asterisks to .*
39
47
  /#{escaped_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.3.0
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Munoz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-24 00:00:00.000000000 Z
11
+ date: 2021-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: easy_io