Skip to content

Commit

Permalink
Fix serializing tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Apr 22, 2024
1 parent 8d4f563 commit 2c89c66
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/item/serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,28 +242,29 @@ void serializeData(QDataStream *stream, const QVariantMap &data, int itemDataThr
? value.toByteArray().size() : dataFile.size();

if ( (itemDataThreshold >= 0 && dataLength > itemDataThreshold) || mime.startsWith(mimeFilePrefix) ) {
// Already saved
if ( !dataFile.path().isEmpty() )
continue;
QString path = dataFile.path();

const QByteArray bytes = value.toByteArray();
const QString path = dataFilePath(bytes, true);
// Already saved into a separate data file?
if ( path.isEmpty() ) {
stream->setStatus(QDataStream::WriteFailed);
return;
}

if ( !QFile::exists(path) ) {
QSaveFile f(path);
f.setDirectWriteFallback(false);
if ( !f.open(QIODevice::WriteOnly) || !f.write(bytes) || !f.commit() ) {
log( QStringLiteral("Failed to create data file \"%1\": %2")
.arg(path, f.errorString()),
LogError );
const QByteArray bytes = value.toByteArray();
path = dataFilePath(bytes, true);
if ( path.isEmpty() ) {
stream->setStatus(QDataStream::WriteFailed);
f.cancelWriting();
return;
}

if ( !QFile::exists(path) ) {
QSaveFile f(path);
f.setDirectWriteFallback(false);
if ( !f.open(QIODevice::WriteOnly) || !f.write(bytes) || !f.commit() ) {
log( QStringLiteral("Failed to create data file \"%1\": %2")
.arg(path, f.errorString()),
LogError );
stream->setStatus(QDataStream::WriteFailed);
f.cancelWriting();
return;
}
}
}

if ( mime.startsWith(mimeFilePrefix) )
Expand Down

0 comments on commit 2c89c66

Please sign in to comment.