NOISSUE do not override already loaded metadata entities with partial data
This commit is contained in:
		@@ -46,7 +46,6 @@ public: /* types */
 | 
			
		||||
public:
 | 
			
		||||
	virtual ~BaseEntity();
 | 
			
		||||
 | 
			
		||||
	virtual void merge(const std::shared_ptr<BaseEntity> &other) = 0;
 | 
			
		||||
	virtual void parse(const QJsonObject &obj) = 0;
 | 
			
		||||
 | 
			
		||||
	virtual QString localFilename() const = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -103,7 +103,7 @@ void Index::parse(const QJsonObject& obj)
 | 
			
		||||
	parseIndex(obj, this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Index::merge(const Ptr &other)
 | 
			
		||||
void Index::merge(const std::shared_ptr<Index> &other)
 | 
			
		||||
{
 | 
			
		||||
	const QVector<VersionListPtr> lists = std::dynamic_pointer_cast<Index>(other)->m_lists;
 | 
			
		||||
	// initial load, no need to merge
 | 
			
		||||
@@ -124,7 +124,7 @@ void Index::merge(const Ptr &other)
 | 
			
		||||
		{
 | 
			
		||||
			if (m_uids.contains(list->uid()))
 | 
			
		||||
			{
 | 
			
		||||
				m_uids[list->uid()]->merge(list);
 | 
			
		||||
				m_uids[list->uid()]->mergeFromIndex(list);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
 
 | 
			
		||||
@@ -58,7 +58,7 @@ public:
 | 
			
		||||
	QVector<VersionListPtr> lists() const { return m_lists; }
 | 
			
		||||
 | 
			
		||||
public: // for usage by parsers only
 | 
			
		||||
	void merge(const BaseEntity::Ptr &other) override;
 | 
			
		||||
	void merge(const std::shared_ptr<Index> &other);
 | 
			
		||||
	void parse(const QJsonObject &obj) override;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 
 | 
			
		||||
@@ -29,7 +29,7 @@ namespace Meta
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
// Index
 | 
			
		||||
static BaseEntity::Ptr parseIndexInternal(const QJsonObject &obj)
 | 
			
		||||
static std::shared_ptr<Index> parseIndexInternal(const QJsonObject &obj)
 | 
			
		||||
{
 | 
			
		||||
	const QVector<QJsonObject> objects = requireIsArrayOf<QJsonObject>(obj, "packages");
 | 
			
		||||
	QVector<VersionListPtr> lists;
 | 
			
		||||
@@ -59,7 +59,7 @@ static VersionPtr parseCommonVersion(const QString &uid, const QJsonObject &obj)
 | 
			
		||||
	return version;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj)
 | 
			
		||||
static std::shared_ptr<Version> parseVersionInternal(const QJsonObject &obj)
 | 
			
		||||
{
 | 
			
		||||
	VersionPtr version = parseCommonVersion(requireString(obj, "uid"), obj);
 | 
			
		||||
 | 
			
		||||
@@ -70,7 +70,7 @@ static BaseEntity::Ptr parseVersionInternal(const QJsonObject &obj)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Version list / package
 | 
			
		||||
static BaseEntity::Ptr parseVersionListInternal(const QJsonObject &obj)
 | 
			
		||||
static std::shared_ptr<VersionList> parseVersionListInternal(const QJsonObject &obj)
 | 
			
		||||
{
 | 
			
		||||
	const QString uid = requireString(obj, "uid");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -54,43 +54,47 @@ void Meta::Version::parse(const QJsonObject& obj)
 | 
			
		||||
	parseVersion(obj, this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Meta::Version::merge(const std::shared_ptr<BaseEntity> &other)
 | 
			
		||||
void Meta::Version::mergeFromList(const Meta::VersionPtr& other)
 | 
			
		||||
{
 | 
			
		||||
	VersionPtr version = std::dynamic_pointer_cast<Version>(other);
 | 
			
		||||
	if(version->m_providesRecommendations)
 | 
			
		||||
	if(other->m_providesRecommendations)
 | 
			
		||||
	{
 | 
			
		||||
		if(m_recommended != version->m_recommended)
 | 
			
		||||
		if(m_recommended != other->m_recommended)
 | 
			
		||||
		{
 | 
			
		||||
			setRecommended(version->m_recommended);
 | 
			
		||||
			setRecommended(other->m_recommended);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (m_type != version->m_type)
 | 
			
		||||
	if (m_type != other->m_type)
 | 
			
		||||
	{
 | 
			
		||||
		setType(version->m_type);
 | 
			
		||||
		setType(other->m_type);
 | 
			
		||||
	}
 | 
			
		||||
	if (m_time != version->m_time)
 | 
			
		||||
	if (m_time != other->m_time)
 | 
			
		||||
	{
 | 
			
		||||
		setTime(version->m_time);
 | 
			
		||||
		setTime(other->m_time);
 | 
			
		||||
	}
 | 
			
		||||
	if (m_requires != version->m_requires)
 | 
			
		||||
	if (m_requires != other->m_requires)
 | 
			
		||||
	{
 | 
			
		||||
		m_requires = version->m_requires;
 | 
			
		||||
		m_requires = other->m_requires;
 | 
			
		||||
	}
 | 
			
		||||
	if (m_conflicts != version->m_conflicts)
 | 
			
		||||
	if (m_conflicts != other->m_conflicts)
 | 
			
		||||
	{
 | 
			
		||||
		m_conflicts = version->m_conflicts;
 | 
			
		||||
		m_conflicts = other->m_conflicts;
 | 
			
		||||
	}
 | 
			
		||||
	if (m_parentUid != version->m_parentUid)
 | 
			
		||||
	if (m_parentUid != other->m_parentUid)
 | 
			
		||||
	{
 | 
			
		||||
		setParentUid(version->m_parentUid);
 | 
			
		||||
		setParentUid(other->m_parentUid);
 | 
			
		||||
	}
 | 
			
		||||
	if(m_volatile != version->m_volatile)
 | 
			
		||||
	if(m_volatile != other->m_volatile)
 | 
			
		||||
	{
 | 
			
		||||
		setVolatile(version->m_volatile);
 | 
			
		||||
		setVolatile(other->m_volatile);
 | 
			
		||||
	}
 | 
			
		||||
	if(version->m_data)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Meta::Version::merge(const VersionPtr &other)
 | 
			
		||||
{
 | 
			
		||||
	mergeFromList(other);
 | 
			
		||||
	if(other->m_data)
 | 
			
		||||
	{
 | 
			
		||||
		setData(version->m_data);
 | 
			
		||||
		setData(other->m_data);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -84,7 +84,8 @@ public: /* con/des */
 | 
			
		||||
		return m_data != nullptr;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void merge(const std::shared_ptr<BaseEntity> &other) override;
 | 
			
		||||
	void merge(const VersionPtr &other);
 | 
			
		||||
	void mergeFromList(const VersionPtr &other);
 | 
			
		||||
	void parse(const QJsonObject &obj) override;
 | 
			
		||||
 | 
			
		||||
	QString localFilename() const override;
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@
 | 
			
		||||
 | 
			
		||||
#include "Version.h"
 | 
			
		||||
#include "JsonFormat.h"
 | 
			
		||||
#include "Version.h"
 | 
			
		||||
 | 
			
		||||
namespace Meta
 | 
			
		||||
{
 | 
			
		||||
@@ -189,32 +190,44 @@ static const Meta::VersionPtr &getBetterVersion(const Meta::VersionPtr &a, const
 | 
			
		||||
	return (a->type() == "release" ? a : b);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void VersionList::merge(const BaseEntity::Ptr &other)
 | 
			
		||||
void VersionList::mergeFromIndex(const VersionListPtr &other)
 | 
			
		||||
{
 | 
			
		||||
	const VersionListPtr list = std::dynamic_pointer_cast<VersionList>(other);
 | 
			
		||||
	if (m_name != list->m_name)
 | 
			
		||||
	if (m_name != other->m_name)
 | 
			
		||||
	{
 | 
			
		||||
		setName(list->m_name);
 | 
			
		||||
		setName(other->m_name);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if(m_parentUid != list->m_parentUid)
 | 
			
		||||
	if(m_parentUid != other->m_parentUid)
 | 
			
		||||
	{
 | 
			
		||||
		setParentUid(list->m_parentUid);
 | 
			
		||||
		setParentUid(other->m_parentUid);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void VersionList::merge(const VersionListPtr &other)
 | 
			
		||||
{
 | 
			
		||||
	if (m_name != other->m_name)
 | 
			
		||||
	{
 | 
			
		||||
		setName(other->m_name);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if(m_parentUid != other->m_parentUid)
 | 
			
		||||
	{
 | 
			
		||||
		setParentUid(other->m_parentUid);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// TODO: do not reset the whole model. maybe?
 | 
			
		||||
	beginResetModel();
 | 
			
		||||
	m_versions.clear();
 | 
			
		||||
	if(list->m_versions.isEmpty())
 | 
			
		||||
	if(other->m_versions.isEmpty())
 | 
			
		||||
	{
 | 
			
		||||
		qWarning() << "Empty list loaded ...";
 | 
			
		||||
	}
 | 
			
		||||
	for (const VersionPtr &version : list->m_versions)
 | 
			
		||||
	for (const VersionPtr &version : other->m_versions)
 | 
			
		||||
	{
 | 
			
		||||
		// we already have the version. merge the contents
 | 
			
		||||
		if (m_lookup.contains(version->version()))
 | 
			
		||||
		{
 | 
			
		||||
			m_lookup.value(version->version())->merge(version);
 | 
			
		||||
			m_lookup.value(version->version())->mergeFromList(version);
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
 
 | 
			
		||||
@@ -80,7 +80,8 @@ public: // for usage only by parsers
 | 
			
		||||
	void setName(const QString &name);
 | 
			
		||||
	void setParentUid(const QString &parentUid);
 | 
			
		||||
	void setVersions(const QVector<VersionPtr> &versions);
 | 
			
		||||
	void merge(const BaseEntity::Ptr &other) override;
 | 
			
		||||
	void merge(const VersionListPtr &other);
 | 
			
		||||
	void mergeFromIndex(const VersionListPtr &other);
 | 
			
		||||
	void parse(const QJsonObject &obj) override;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user