Skip to content

Commit

Permalink
QWinRTFileEngine: Handle QIODevice::Truncate when opening files
Browse files Browse the repository at this point in the history
Fixes: QTBUG-77095
Change-Id: I45b38fab779518c49b22077c493d8640572d40d9
Reviewed-by: André de la Rocha <[email protected]>
Reviewed-by: Maurice Kalinowski <[email protected]>
  • Loading branch information
owolff committed Jul 29, 2019
1 parent 7138d6f commit 3fbb6a9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/plugins/platforms/winrt/qwinrtfileengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QHash>
#include <QtCore/qfunctions_winrt.h>
#include <QtCore/private/qfsfileengine_p.h>

#include <wrl.h>
#include <windows.storage.h>
Expand Down Expand Up @@ -196,7 +197,19 @@ bool QWinRTFileEngine::open(QIODevice::OpenMode openMode)
hr = QWinRTFunctions::await(op, d->stream.GetAddressOf());
RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::OpenError, false);

d->openMode = openMode;
const ProcessOpenModeResult res = processOpenModeFlags(openMode);
if (!res.ok) {
setError(QFileDevice::OpenError, res.error);
return false;
}
d->openMode = res.openMode;
if (d->openMode & QIODevice::Truncate) {
if (!setSize(0)) {
close();
setError(QFileDevice::OpenError, QLatin1String("Could not truncate file"));
return false;
}
}

return SUCCEEDED(hr);
}
Expand Down

0 comments on commit 3fbb6a9

Please sign in to comment.