Skip to content

Commit

Permalink
Prefer block version of File.open to ensure file gets automatically c…
Browse files Browse the repository at this point in the history
…losed
  • Loading branch information
chessbyte committed Oct 21, 2019
1 parent 5819fce commit 2082460
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/task_helpers/imports/reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def import(options = {})
:overwrite => options[:overwrite],
:save => true }

begin
report_fd = File.open(filename, 'r')
File.open(filename, 'r') do |report_fd|
MiqReport.import(report_fd, report_options)
rescue ActiveModel::UnknownAttributeError, RuntimeError => err
$log.error("Error importing #{filename} : #{err.message}")
Expand Down
3 changes: 1 addition & 2 deletions lib/task_helpers/imports/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def import(options = {})
:overwrite => options[:overwrite],
:save => true }

begin
widget_fd = File.open(filename, 'r')
File.open(filename, 'r') do |widget_fd|
MiqWidget.import(widget_fd, widget_options)
rescue ActiveModel::UnknownAttributeError, RuntimeError => err
$log.error("Error importing #{filename} : #{err.message}")
Expand Down

0 comments on commit 2082460

Please sign in to comment.