diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2018-07-23 20:06:04 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2018-07-30 15:04:31 +0000 |
commit | cb505bedde4940d927b593ecc3668789e9f1c0a0 (patch) | |
tree | 47a002a0519d728491a354af340a4c5b831c7464 /src/corelib/io/qiodevice.cpp | |
parent | 5da8e5ddd424a11435a3750dc9b955295aeaed9c (diff) |
Actually truncate when asked to
On Unix, we wouldn't even *try* to truncate if the file was open for
appending. The combination may be an eccentric choice but - at least
when it's combined with reading - I can imagine use-cases for it; and
we should (at least try to) deliver what we're asked for, even if we
can't think why anyone would want it. So actually enable truncation
when asked to.
Amended some tests to check this works and corrected the QIODevice
documentation of mode flags (which misdescribed the special case that
implies Truncate). Removed special-case code, to apply truncate when
writing but not reading, since it's been made redundant by the
pre-processing of mode done in QFSFileEngine::processOpenModeFlags().
[ChangeLog][QtCore][QFile] When opening a file, if Truncate is asked
for, or implied by other flags, it shall be attempted, regardless of
what other options are selected. We previously did this on Windows;
now we do so also on Unix (even when appending).
Task-number: QTBUG-13470
Change-Id: I1e08d02cfbae102725fccbbc3aab5c7bf8830687
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qiodevice.cpp')
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 95a5fb27cf..5dd5f8031e 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -312,8 +312,9 @@ QIODevicePrivate::~QIODevicePrivate() \value NotOpen The device is not open. \value ReadOnly The device is open for reading. - \value WriteOnly The device is open for writing. Note that this mode implies - Truncate. + \value WriteOnly The device is open for writing. Note that, for file-system + subclasses (e.g. QFile), this mode implies Truncate unless + combined with ReadOnly, Append or NewOnly. \value ReadWrite The device is open for reading and writing. \value Append The device is opened in append mode so that all data is written to the end of the file. |