Fix merging browser keys

* Introduce protected custom data function to prevent loss during merge operations
This commit is contained in:
varjolintu
2020-05-01 11:07:14 +03:00
committed by Jonathan White
parent 48bf4fb85d
commit e367c6df95
6 changed files with 29 additions and 20 deletions

View File

@@ -22,6 +22,8 @@
const QString CustomData::LastModified = QStringLiteral("_LAST_MODIFIED");
const QString CustomData::Created = QStringLiteral("_CREATED");
const QString CustomData::BrowserKeyPrefix = QStringLiteral("KPXC_BROWSER_");
const QString CustomData::BrowserLegacyKeyPrefix = QStringLiteral("Public Key: ");
CustomData::CustomData(QObject* parent)
: QObject(parent)
@@ -128,6 +130,11 @@ QDateTime CustomData::getLastModified() const
return {};
}
bool CustomData::isProtectedCustomData(const QString& key) const
{
return key.startsWith(CustomData::BrowserKeyPrefix) || key.startsWith(CustomData::Created);
}
bool CustomData::operator==(const CustomData& other) const
{
return (m_data == other.m_data);

View File

@@ -43,11 +43,14 @@ public:
int dataSize() const;
void copyDataFrom(const CustomData* other);
QDateTime getLastModified() const;
bool isProtectedCustomData(const QString& key) const;
bool operator==(const CustomData& other) const;
bool operator!=(const CustomData& other) const;
static const QString LastModified;
static const QString Created;
static const QString BrowserKeyPrefix;
static const QString BrowserLegacyKeyPrefix;
signals:
void customDataModified();

View File

@@ -632,7 +632,9 @@ Merger::ChangeList Merger::mergeMetadata(const MergeContext& context)
// Check missing keys from source. Remove those from target
for (const auto& key : targetCustomDataKeys) {
if (!sourceMetadata->customData()->contains(key)) {
// Do not remove protected custom data
if (!sourceMetadata->customData()->contains(key)
&& !sourceMetadata->customData()->isProtectedCustomData(key)) {
auto value = targetMetadata->customData()->value(key);
targetMetadata->customData()->remove(key);
changes << tr("Removed custom data %1 [%2]").arg(key, value);