Skip to content

Commit

Permalink
Refs #38164 - Always update on upload; generate digest from content only
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren authored and adamruzicka committed Feb 11, 2025
1 parent 5187270 commit 95f151f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/foreman_openscap/scap_file_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module ScapFileContent
validates :digest, :presence => true
validates :scap_file, :presence => true

before_validation :redigest, :if => lambda { |file_content| file_content.persisted? && file_content.scap_file_changed? }
before_validation :redigest, :if => lambda { |file_content| !file_content.persisted? || file_content.scap_file_changed? }
end

def digest
Expand Down
7 changes: 1 addition & 6 deletions app/services/foreman_openscap/bulk_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,10 @@ def upload_from_files(files_array, from_scap_guide = false)
end

file = File.read(datastream, mode: 'rb')
digest = Digest::SHA2.hexdigest(datastream)
title = content_name(datastream, from_scap_guide)
filename = original_filename(datastream)
search_cond = { :title => title }
# Change behavior only if uploading from scap guide
search_cond[:digest] = digest unless from_scap_guide
scap_content = ScapContent.where(search_cond).first_or_initialize

next if scap_content.persisted? && !from_scap_guide
scap_content = ScapContent.where(:title => title).first_or_initialize
scap_content.scap_file = file
scap_content.original_filename = filename
scap_content.location_ids = Location.all.pluck(:id)
Expand Down

0 comments on commit 95f151f

Please sign in to comment.