Project

General

Profile

Actions

Defect #38250

closed

config/settings.yml not closed in Setting.load_available_settings

Added by Thomas Löber about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Code cleanup/refactoring
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

The file config/settings.yml is not closed after it is read in Setting.load_available_settings.

This can cause problems during development, for example when changing Git branches while the Rails server is running (error: unable to unlink old 'config/settings.yml').

The solution is to pass a block to File.open, as it will automatically close the file after the block is executed.

def self.load_available_settings
  File.open("#{Rails.root}/config/settings.yml") do |f|
    YAML.load(f).each do |name, options|
      define_setting name, options
    end
  end
end
Actions

Also available in: Atom PDF