MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / appendSafe

Function appendSafe

launcher/FileSystem.cpp:193–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193void appendSafe(const QString& filename, const QByteArray& data)
194{
195 ensureExists(QFileInfo(filename).dir());
196 QByteArray buffer;
197 try {
198 buffer = read(filename);
199 } catch (FileSystemException&) {
200 buffer = QByteArray();
201 }
202 buffer.append(data);
203 PSaveFile file(filename);
204 if (!file.open(PSaveFile::WriteOnly)) {
205 throw FileSystemException("Couldn't open " + filename + " for writing: " + file.errorString());
206 }
207 if (buffer.size() != file.write(buffer)) {
208 throw FileSystemException("Error writing data to " + filename + ": " + file.errorString());
209 }
210 if (!file.commit()) {
211 throw FileSystemException("Error while committing data to " + filename + ": " + file.errorString());
212 }
213}
214
215void append(const QString& filename, const QByteArray& data)
216{

Callers

nothing calls this directly

Calls 11

ensureExistsFunction · 0.85
QFileInfoClass · 0.85
readFunction · 0.85
QByteArrayClass · 0.85
FileSystemExceptionClass · 0.85
dirMethod · 0.80
appendMethod · 0.80
errorStringMethod · 0.80
openMethod · 0.45
sizeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected