Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFelix Geyer <debfx@fobos.de>2010-09-16 20:20:22 +0400
committerFelix Geyer <debfx@fobos.de>2010-09-16 20:20:22 +0400
commit49d64d81626adf3bdc427d9bcdf7dab486ac916a (patch)
tree7bcc875dca9f2fb31c0502c22a365847e66d16e4 /src
parentd508c2dd6887bc1e59ecb7c18e41d60d9ec221d1 (diff)
Better error checking when opening the stream.
Diffstat (limited to 'src')
-rw-r--r--src/streams/LayeredStream.cpp37
1 files changed, 27 insertions, 10 deletions
diff --git a/src/streams/LayeredStream.cpp b/src/streams/LayeredStream.cpp
index dc4dbd828..d0078085c 100644
--- a/src/streams/LayeredStream.cpp
+++ b/src/streams/LayeredStream.cpp
@@ -36,23 +36,40 @@ QString LayeredStream::errorString() const
bool LayeredStream::open(QIODevice::OpenMode mode)
{
- // filter out all other modes
- mode &= QIODevice::ReadWrite;
+ if (isOpen()) {
+ qWarning("LayeredStream::open: Device is already open.");
+ return false;
+ }
+
+ bool readMode = (mode & QIODevice::ReadOnly);
+ bool writeMode = (mode & QIODevice::WriteOnly);
- if (mode == QIODevice::ReadWrite) {
- qWarning("Reading and writing at the same time is not supported.");
+ if (readMode && writeMode) {
+ qWarning("LayeredStream::open: Reading and writing at the same time is not supported.");
return false;
}
- else if (openMode() & mode) {
- return true;
+ else if (!readMode && !writeMode) {
+ qWarning("LayeredStream::open: Must be opened in read or write mode.");
+ return false;
}
- else if (!(m_baseDevice->openMode() & mode)) {
- qWarning("Base device is not opened correctly.");
+ else if ((readMode && !m_baseDevice->isReadable()) ||
+ (writeMode && !m_baseDevice->isWritable())) {
+ qWarning("LayeredStream::open: Base device is not opened correctly.");
return false;
}
else {
- setOpenMode(mode | QIODevice::Unbuffered);
- return true;
+ if (mode & QIODevice::Append) {
+ qWarning("LayeredStream::open: QIODevice::Append is not supported.");
+ mode = mode & ~QIODevice::Append;
+ }
+ if (mode & QIODevice::Truncate) {
+ qWarning("LayeredStream::open: QIODevice::Truncate is not supported.");
+ mode = mode & ~QIODevice::Truncate;
+ }
+
+ mode = mode | QIODevice::Unbuffered;
+
+ return QIODevice::open(mode);
}
}