MCPcopy Create free account
hub / github.com/USBGuard/usbguard / write

Method write

src/Library/ConfigFilePrivate.cpp:72–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {

Callers

nothing calls this directly

Calls 2

ExceptionFunction · 0.85
clearMethod · 0.45

Tested by

no test coverage detected