Project

General

Profile

Actions

Defect #38250

closed

config/settings.yml not closed in Setting.load_available_settings

Added by Thomas Löber almost 2 years ago. Updated almost 2 years 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