mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-17 14:00:36 -04:00
Remove obsolete read only state from database. (#7324)
This commit is contained in:
parent
c914c116e4
commit
bce8c84c26
13 changed files with 28 additions and 120 deletions
|
@ -96,17 +96,16 @@ QUuid Database::uuid() const
|
|||
* read-write mode and fall back to read-only if that is not possible.
|
||||
*
|
||||
* @param key composite key for unlocking the database
|
||||
* @param readOnly open in read-only mode
|
||||
* @param error error message in case of failure
|
||||
* @return true on success
|
||||
*/
|
||||
bool Database::open(QSharedPointer<const CompositeKey> key, QString* error, bool readOnly)
|
||||
bool Database::open(QSharedPointer<const CompositeKey> key, QString* error)
|
||||
{
|
||||
Q_ASSERT(!m_data.filePath.isEmpty());
|
||||
if (m_data.filePath.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return open(m_data.filePath, std::move(key), error, readOnly);
|
||||
return open(m_data.filePath, std::move(key), error);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,11 +115,10 @@ bool Database::open(QSharedPointer<const CompositeKey> key, QString* error, bool
|
|||
*
|
||||
* @param filePath path to the file
|
||||
* @param key composite key for unlocking the database
|
||||
* @param readOnly open in read-only mode
|
||||
* @param error error message in case of failure
|
||||
* @return true on success
|
||||
*/
|
||||
bool Database::open(const QString& filePath, QSharedPointer<const CompositeKey> key, QString* error, bool readOnly)
|
||||
bool Database::open(const QString& filePath, QSharedPointer<const CompositeKey> key, QString* error)
|
||||
{
|
||||
QFile dbFile(filePath);
|
||||
if (!dbFile.exists()) {
|
||||
|
@ -154,7 +152,6 @@ bool Database::open(const QString& filePath, QSharedPointer<const CompositeKey>
|
|||
return false;
|
||||
}
|
||||
|
||||
setReadOnly(readOnly);
|
||||
setFilePath(filePath);
|
||||
dbFile.close();
|
||||
|
||||
|
@ -260,15 +257,6 @@ bool Database::saveAs(const QString& filePath, SaveAction action, const QString&
|
|||
QMutexLocker locker(&m_saveMutex);
|
||||
|
||||
if (filePath == m_data.filePath) {
|
||||
// Disallow saving to the same file if read-only
|
||||
if (m_data.isReadOnly) {
|
||||
Q_ASSERT_X(false, "Database::saveAs", "Could not save, database file is read-only.");
|
||||
if (error) {
|
||||
*error = tr("Could not save, database file is read-only.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fail-safe check to make sure we don't overwrite underlying file changes
|
||||
// that have not yet triggered a file reload/merge operation.
|
||||
if (!m_fileWatcher->hasSameFileChecksum()) {
|
||||
|
@ -280,7 +268,6 @@ bool Database::saveAs(const QString& filePath, SaveAction action, const QString&
|
|||
}
|
||||
|
||||
// Clear read-only flag
|
||||
setReadOnly(false);
|
||||
m_fileWatcher->stop();
|
||||
|
||||
QFileInfo fileInfo(filePath);
|
||||
|
@ -402,14 +389,6 @@ bool Database::performSave(const QString& filePath, SaveAction action, const QSt
|
|||
|
||||
bool Database::writeDatabase(QIODevice* device, QString* error)
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
if (m_data.isReadOnly) {
|
||||
if (error) {
|
||||
*error = tr("File cannot be written as it is opened in read-only mode.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
PasswordKey oldTransformedKey;
|
||||
if (m_data.key->isEmpty()) {
|
||||
oldTransformedKey.setHash(m_data.transformedDatabaseKey->rawKey());
|
||||
|
@ -556,16 +535,6 @@ bool Database::restoreDatabase(const QString& filePath, const QString& fromBacku
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Database::isReadOnly() const
|
||||
{
|
||||
return m_data.isReadOnly;
|
||||
}
|
||||
|
||||
void Database::setReadOnly(bool readOnly)
|
||||
{
|
||||
m_data.isReadOnly = readOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the database key exists, has subkeys, and the
|
||||
* root group exists
|
||||
|
@ -811,7 +780,6 @@ bool Database::setKey(const QSharedPointer<const CompositeKey>& key,
|
|||
bool updateTransformSalt,
|
||||
bool transformKey)
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
m_keyError.clear();
|
||||
|
||||
if (!key) {
|
||||
|
@ -870,14 +838,11 @@ const QVariantMap& Database::publicCustomData() const
|
|||
|
||||
void Database::setPublicCustomData(const QVariantMap& customData)
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
m_data.publicCustomData = customData;
|
||||
}
|
||||
|
||||
void Database::createRecycleBin()
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
|
||||
auto recycleBin = new Group();
|
||||
recycleBin->setUuid(QUuid::createUuid());
|
||||
recycleBin->setParent(rootGroup());
|
||||
|
@ -891,7 +856,6 @@ void Database::createRecycleBin()
|
|||
|
||||
void Database::recycleEntry(Entry* entry)
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
if (m_metadata->recycleBinEnabled()) {
|
||||
if (!m_metadata->recycleBin()) {
|
||||
createRecycleBin();
|
||||
|
@ -904,7 +868,6 @@ void Database::recycleEntry(Entry* entry)
|
|||
|
||||
void Database::recycleGroup(Group* group)
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
if (m_metadata->recycleBinEnabled()) {
|
||||
if (!m_metadata->recycleBin()) {
|
||||
createRecycleBin();
|
||||
|
@ -917,7 +880,6 @@ void Database::recycleGroup(Group* group)
|
|||
|
||||
void Database::emptyRecycleBin()
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
if (m_metadata->recycleBinEnabled() && m_metadata->recycleBin()) {
|
||||
// destroying direct entries of the recycle bin
|
||||
QList<Entry*> subEntries = m_metadata->recycleBin()->entries();
|
||||
|
@ -988,15 +950,12 @@ QSharedPointer<Kdf> Database::kdf() const
|
|||
|
||||
void Database::setKdf(QSharedPointer<Kdf> kdf)
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
m_data.kdf = std::move(kdf);
|
||||
setFormatVersion(KeePass2Writer::kdbxVersionRequired(this, true, m_data.kdf.isNull()));
|
||||
}
|
||||
|
||||
bool Database::changeKdf(const QSharedPointer<Kdf>& kdf)
|
||||
{
|
||||
Q_ASSERT(!m_data.isReadOnly);
|
||||
|
||||
kdf->randomizeSeed();
|
||||
QByteArray transformedDatabaseKey;
|
||||
if (!m_data.key) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue