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/qfsfileengine_unix.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/qfsfileengine_unix.cpp')
-rw-r--r-- | src/corelib/io/qfsfileengine_unix.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp index bc39ea73ee..b82415cb26 100644 --- a/src/corelib/io/qfsfileengine_unix.cpp +++ b/src/corelib/io/qfsfileengine_unix.cpp @@ -82,12 +82,11 @@ static inline int openModeToOpenFlags(QIODevice::OpenMode mode) if (QFSFileEnginePrivate::openModeCanCreate(mode)) oflags |= QT_OPEN_CREAT; - if (mode & QFile::Append) { + if (mode & QFile::Truncate) + oflags |= QT_OPEN_TRUNC; + + if (mode & QFile::Append) oflags |= QT_OPEN_APPEND; - } else if (mode & QFile::WriteOnly) { - if ((mode & QFile::Truncate) || !(mode & QFile::ReadOnly)) - oflags |= QT_OPEN_TRUNC; - } if (mode & QFile::NewOnly) oflags |= QT_OPEN_EXCL; |