diff options
| author | d3fault <d3fault@d3fault.net> | 2017-11-24 16:07:53 -0700 |
|---|---|---|
| committer | d3fault <d3fault@d3fault.net> | 2018-01-17 04:32:47 +0000 |
| commit | 1a4cc8d57b928509a64f9679e5c0e7afaa05cb54 (patch) | |
| tree | 7748aa4993fca0bf115402e2df4bd7d4d49537db /src/corelib/io/qsavefile.cpp | |
| parent | 0aecac1dcfd4b8e353e2fc0b0ad06d77b4b125d6 (diff) | |
Add QIODevice::NewOnly and QIODevice::ExistingOnly OpenMode flags
When QFile::open is called with the NewOnly flag, the call will
fail if the file already exists. As usual, if the file does not exist,
it will be created. Like QTemporaryFile, there is a guarantee from
the operating system that you are not accidentally creating a new file
on top of an older file. When QFile::open is called with the
ExistingOnly flag, the call will fail if the file does not exist. The
ExistingOnly flag only provides new functionality when used with the
WriteOnly flag. For ReadOnly it provides no change in functionality,
as ReadOnly by itself already never creates.
Task-number: QTBUG-52244
Change-Id: I8e3206728f245f95172c225bf297023fb078fc6d
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/corelib/io/qsavefile.cpp')
| -rw-r--r-- | src/corelib/io/qsavefile.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/io/qsavefile.cpp b/src/corelib/io/qsavefile.cpp index 63f2284ef5e..56934a9a0f7 100644 --- a/src/corelib/io/qsavefile.cpp +++ b/src/corelib/io/qsavefile.cpp @@ -184,7 +184,8 @@ void QSaveFile::setFileName(const QString &name) Important: the \a mode must include QIODevice::WriteOnly. It may also have additional flags, such as QIODevice::Text and QIODevice::Unbuffered. - QIODevice::ReadWrite and QIODevice::Append are not supported at the moment. + QIODevice::ReadWrite, QIODevice::Append, QIODevice::NewOnly and + QIODevice::ExistingOnly are not supported at the moment. \sa QIODevice::OpenMode, setFileName() */ @@ -201,7 +202,8 @@ bool QSaveFile::open(OpenMode mode) return false; } // In the future we could implement ReadWrite by copying from the existing file to the temp file... - if ((mode & ReadOnly) || (mode & Append)) { + // The implications of NewOnly and ExistingOnly when used with QSaveFile need to be considered carefully... + if (mode & (ReadOnly | Append | NewOnly | ExistingOnly)) { qWarning("QSaveFile::open: Unsupported open mode 0x%x", int(mode)); return false; } |
