Revision 13998ef2 lib/config.py

b/lib/config.py
1041 1041
    """Read the config data from disk.
1042 1042

  
1043 1043
    """
1044
    f = open(self._cfg_file, 'r')
1044
    raw_data = utils.ReadFile(self._cfg_file)
1045

  
1045 1046
    try:
1046
      try:
1047
        data = objects.ConfigData.FromDict(serializer.Load(f.read()))
1048
      except Exception, err:
1049
        raise errors.ConfigurationError(err)
1050
    finally:
1051
      f.close()
1047
      data = objects.ConfigData.FromDict(serializer.Load(raw_data))
1048
    except Exception, err:
1049
      raise errors.ConfigurationError(err)
1052 1050

  
1053 1051
    # Make sure the configuration has the right version
1054 1052
    _ValidateConfig(data)
......
1113 1111
      destination = self._cfg_file
1114 1112
    self._BumpSerialNo()
1115 1113
    txt = serializer.Dump(self._config_data.ToDict())
1116
    dir_name, file_name = os.path.split(destination)
1117
    fd, name = tempfile.mkstemp('.newconfig', file_name, dir_name)
1118
    f = os.fdopen(fd, 'w')
1119
    try:
1120
      f.write(txt)
1121
      os.fsync(f.fileno())
1122
    finally:
1123
      f.close()
1124
    # we don't need to do os.close(fd) as f.close() did it
1125
    os.rename(name, destination)
1114

  
1115
    utils.WriteFile(destination, data=txt)
1116

  
1126 1117
    self.write_count += 1
1127 1118

  
1128 1119
    # and redistribute the config file to master candidates

Also available in: Unified diff