mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-02 17:44:46 -05:00
Better error checking when opening the stream.
This commit is contained in:
parent
d508c2dd68
commit
49d64d8162
@ -36,23 +36,40 @@ QString LayeredStream::errorString() const
|
|||||||
|
|
||||||
bool LayeredStream::open(QIODevice::OpenMode mode)
|
bool LayeredStream::open(QIODevice::OpenMode mode)
|
||||||
{
|
{
|
||||||
// filter out all other modes
|
if (isOpen()) {
|
||||||
mode &= QIODevice::ReadWrite;
|
qWarning("LayeredStream::open: Device is already open.");
|
||||||
|
|
||||||
if (mode == QIODevice::ReadWrite) {
|
|
||||||
qWarning("Reading and writing at the same time is not supported.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (openMode() & mode) {
|
|
||||||
return true;
|
bool readMode = (mode & QIODevice::ReadOnly);
|
||||||
|
bool writeMode = (mode & QIODevice::WriteOnly);
|
||||||
|
|
||||||
|
if (readMode && writeMode) {
|
||||||
|
qWarning("LayeredStream::open: Reading and writing at the same time is not supported.");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else if (!(m_baseDevice->openMode() & mode)) {
|
else if (!readMode && !writeMode) {
|
||||||
qWarning("Base device is not opened correctly.");
|
qWarning("LayeredStream::open: Must be opened in read or write mode.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if ((readMode && !m_baseDevice->isReadable()) ||
|
||||||
|
(writeMode && !m_baseDevice->isWritable())) {
|
||||||
|
qWarning("LayeredStream::open: Base device is not opened correctly.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setOpenMode(mode | QIODevice::Unbuffered);
|
if (mode & QIODevice::Append) {
|
||||||
return true;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user