Skip to content

Commit

Permalink
98848 Use FileUtils.mv over File.rename to account for external d…
Browse files Browse the repository at this point in the history
…evice error - IVC CHAMPVA forms (#19885)

* updated file move operation to account for possible file system issues

* missing end
  • Loading branch information
michaelclement authored Dec 17, 2024
1 parent af35cd8 commit ef3c028
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions modules/ivc_champva/app/services/ivc_champva/attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module IvcChampva
module Attachments
attr_accessor :form_id, :uuid, :data

def handle_attachments(file_path)
def handle_attachments(file_path) # rubocop:disable Metrics/MethodLength
file_paths = [file_path]
attachments = get_attachments

Expand All @@ -22,7 +22,14 @@ def handle_attachments(file_path)
File.join(File.dirname(attachment), new_file_name)
end

File.rename(attachment, new_file_path)
if Flipper.enabled?(:champva_pdf_decrypt, @current_user)
# Use FileUtils.mv to handle `Errno::EXDEV` error since encrypted PDFs
# get stashed in the clamav_tmp dir which is a different device on staging, apparently
FileUtils.mv(attachment, new_file_path) # Performs a copy automatically if mv fails
else
File.rename(attachment, new_file_path)
end

file_paths << new_file_path
end

Expand Down

0 comments on commit ef3c028

Please sign in to comment.