| 70 | } |
| 71 | |
| 72 | void ConfigFilePrivate::write() |
| 73 | { |
| 74 | if (!_stream.is_open()) { |
| 75 | throw USBGUARD_BUG("ConfigFilePrivate::write: write() before open()"); |
| 76 | } |
| 77 | |
| 78 | if (_readonly) { |
| 79 | throw USBGUARD_BUG("ConfigFilePrivate::write: not applicable in read-only mode"); |
| 80 | } |
| 81 | |
| 82 | if (_dirty) { |
| 83 | /* Update _lines */ |
| 84 | for (auto const& map_entry : _settings) { |
| 85 | const NVPair& setting = map_entry.second; |
| 86 | _lines[setting.line_number - 1] = setting.name + "=" + setting.value; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | _stream.clear(); |
| 91 | _stream.seekp(0); |
| 92 | |
| 93 | for (auto const& line : _lines) { |
| 94 | _stream << line << std::endl; |
| 95 | |
| 96 | if (!_stream.good()) { |
| 97 | throw Exception("Configuration", "write", "failed to write configuration to disk"); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | _stream.flush(); |
| 102 | _dirty = false; |
| 103 | } |
| 104 | |
| 105 | void ConfigFilePrivate::close() |
| 106 | { |