lib/zipr/archive.rb
#
# Description:
#   Determines what files should be added to an archive based on the options and mode provided.
# Returns:
#   An array of files to be added (or the :all symbol).
# Parameters:
#   source_folder: The filesystem directory where files are being added from.
#   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.
#     default: All files and folders under the source_folder.
Determines what files should be added to an archive based on the options and mode provided.
Returns:
An array of files to be added (or the :all symbol).
Parameters:
source_folder: The filesystem directory where files are being added from.
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.
default: All files and folders under the source_folder.
Determines what files should be added to an archive based on the options and mode provided . Returns : An array of files to be added ( or the : all symbol ) . Parameters : source_folder : The filesystem directory where files are being added from . 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 . default : All files and folders under the source_folder .
def determine_files_to_add(source_folder, files_to_check: nil)
      files_to_check ||= Dir.glob("#{source_folder}/**/*".tr('\\', '/')) if files_to_check.nil?
      files_to_add = []
      source_folder_glob = nil
      files_to_check.each do |target_search|
        files = if target_search.is_a?(Regexp)
                  source_folder_glob ||= Dir.glob("#{source_folder.tr('\\', '/')}/**/*")
                  source_folder_glob.select do |path|
                    path =~ target_search
                  end
                  source_folder_glob.select { |path| path.to_s =~ target_search }
                else
                  Dir.glob(Zipr.prepend_source_folder(source_folder, target_search))
                end
        files.each do |source_file|
          relative_path = Zipr.slice_source_folder(source_folder, source_file)
          exists_in_zip = !!@checksums[relative_path]
          next if @mode == :if_missing && exists_in_zip
          next if _excluded_file?(relative_path, exists_in_zip: exists_in_zip) || _excluded_file?(source_file, exists_in_zip: exists_in_zip)
          next if @mode == :idempotent && ::File.file?(source_file) && @checksums[relative_path] == Digest::SHA256.file(source_file).hexdigest
          next if ::File.directory?(source_file) && @checksums[relative_path] == 'directory'
          EasyIO.logger.debug "'#{relative_path}' would be added to archive..."
          files_to_add.push(source_file)
        end
      end
      files_to_add
    end
def determine_files_to_add ( source_folder , files_to_check : nil ) files_to_check ||= Dir . glob ( "#{source_folder}/**/*" . tr ( '\\' , '/' ) ) if files_to_check . nil? files_to_add = [ ] source_folder_glob = nil files_to_check . each do | target_search | files = if target_search . is_a? ( Regexp ) source_folder_glob ||= Dir . glob ( "#{source_folder.tr('\\', '/')}/**/*" ) source_folder_glob . select do | path | path =~ target_search end source_folder_glob . select { | path | path . to_s =~ target_search } else Dir . glob ( Zipr . prepend_source_folder ( source_folder , target_search ) ) end files . each do | source_file | relative_path = Zipr . slice_source_folder ( source_folder , source_file ) exists_in_zip = ! ! @checksums [ relative_path ] next if @mode == :if_missing && exists_in_zip next if _excluded_file? ( relative_path , exists_in_zip : exists_in_zip ) || _excluded_file? ( source_file , exists_in_zip : exists_in_zip ) next if @mode == :idempotent && :: File . file? ( source_file ) && @checksums [ relative_path ] == Digest :: SHA256 . file ( source_file ) . hexdigest next if :: File . directory? ( source_file ) && @checksums [ relative_path ] == 'directory' EasyIO . logger . debug "'#{relative_path}' would be added to archive..." files_to_add . push ( source_file ) end end files_to_add end
Description:
Determines what files should be added to an archive based on the options and mode provided.
Description : Determines what files should be added to an archive based on the options and mode provided .
source_folder
files_to_check