Skip to content

Commit

Permalink
Revert "[addons] remove GetRepoForAddon and explicitly get the repo w…
Browse files Browse the repository at this point in the history
…ith the highest version"

This reverts commit 61121d7.
  • Loading branch information
tamland authored and popcornmix committed Sep 21, 2015
1 parent 9471e30 commit 0c265bd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 29 deletions.
23 changes: 23 additions & 0 deletions xbmc/addons/AddonDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,29 @@ bool CAddonDatabase::GetAddon(const std::string& id, AddonPtr& addon)
return false;
}

bool CAddonDatabase::GetRepoForAddon(const std::string& addonID, std::string& repo)
{
try
{
if (NULL == m_pDB.get()) return false;
if (NULL == m_pDS2.get()) return false;

std::string sql = PrepareSQL("select repo.addonID from repo join addonlinkrepo on repo.id=addonlinkrepo.idRepo join addon on addonlinkrepo.idAddon=addon.id where addon.addonID like '%s'", addonID.c_str());
m_pDS2->query(sql.c_str());
if (!m_pDS2->eof())
{
repo = m_pDS2->fv(0).get_asString();
m_pDS2->close();
return true;
}
}
catch (...)
{
CLog::Log(LOGERROR, "%s failed for addon %s", __FUNCTION__, addonID.c_str());
}
return false;
}

bool CAddonDatabase::GetAddon(int id, AddonPtr &addon)
{
try
Expand Down
6 changes: 6 additions & 0 deletions xbmc/addons/AddonDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class CAddonDatabase : public CDatabase
/*! \brief grab the (largest) add-on version for an add-on */
ADDON::AddonVersion GetAddonVersion(const std::string &id);

/*! \brief Grab the repository from which a given addon came
\param addonID - the id of the addon in question
\param repo [out] - the id of the repository
\return true if a repo was found, false otherwise.
*/
bool GetRepoForAddon(const std::string& addonID, std::string& repo);
int AddRepository(const std::string& id, const ADDON::VECADDONS& addons, const std::string& checksum, const ADDON::AddonVersion& version);
void DeleteRepository(const std::string& id);
void DeleteRepository(int id);
Expand Down
50 changes: 24 additions & 26 deletions xbmc/addons/AddonInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ bool CAddonInstaller::InstallOrUpdate(const std::string &addonID, bool backgroun
CAddonMgr::GetInstance().GetAddon(addonID, addon, ADDON_UNKNOWN, false);

// check whether we have it available in a repository
RepositoryPtr repo;
if (!GetRepoForAddon(addonID, repo))
AddonPtr repo = GetRepoForAddon(addonID);
if (repo == NULL)
return false;

std::string hash;
Expand Down Expand Up @@ -228,10 +228,7 @@ bool CAddonInstaller::DoInstall(const AddonPtr &addon, const std::string &hash /
if (m_downloadJobs.find(addon->ID()) != m_downloadJobs.end())
return false;

RepositoryPtr repo;
if (!CAddonInstaller::GetRepoForAddon(addon->ID(), repo))
return false;

AddonPtr repo = CAddonInstaller::GetRepoForAddon(addon->ID());
CAddonInstallJob* installJob = new CAddonInstallJob(addon, repo, hash);
if (background)
{
Expand Down Expand Up @@ -437,24 +434,28 @@ void CAddonInstaller::InstallUpdates()
}
}

bool CAddonInstaller::GetRepoForAddon(const std::string& addonId, RepositoryPtr& repoPtr)
AddonPtr CAddonInstaller::GetRepoForAddon(const std::string& addonId)
{
AddonPtr repoPtr;

CAddonDatabase database;
if (!database.Open())
return false;
return repoPtr;

std::vector<std::pair<ADDON::AddonVersion, std::string>> versions;
if (!database.GetAvailableVersions(addonId, versions) || versions.empty())
return false;
std::string repo;
if (!database.GetRepoForAddon(addonId, repo))
return repoPtr;

auto repoId = std::min_element(versions.begin(), versions.end())->second;
if (!CAddonMgr::GetInstance().GetAddon(repo, repoPtr))
return repoPtr;

AddonPtr tmp;
if (!CAddonMgr::GetInstance().GetAddon(repoId, tmp, ADDON_REPOSITORY))
return false;
if (std::dynamic_pointer_cast<CRepository>(repoPtr) == NULL)
{
repoPtr.reset();
return repoPtr;
}

repoPtr = std::static_pointer_cast<CRepository>(tmp);
return true;
return repoPtr;
}

int64_t CAddonInstaller::EnumeratePackageFolder(std::map<std::string,CFileItemList*>& result)
Expand Down Expand Up @@ -735,11 +736,10 @@ bool CAddonInstallJob::Install(const std::string &installFrom, const AddonPtr& r
// don't have the addon or the addon isn't new enough - grab it (no new job for these)
else if (IsModal())
{
RepositoryPtr repoForDep;
AddonPtr repoForDep = CAddonInstaller::GetRepoForAddon(addonID);
AddonPtr addon;
std::string hash;
if (!CAddonInstaller::GetRepoForAddon(addonID, repoForDep) ||
!CAddonInstallJob::GetAddonWithHash(addonID, repoForDep->ID(), addon, hash))
if (!repoForDep || !CAddonInstallJob::GetAddonWithHash(addonID, repoForDep->ID(), addon, hash))
{
CLog::Log(LOGERROR, "CAddonInstallJob[%s]: failed to find dependency %s", m_addon->ID().c_str(), addonID.c_str());
ReportInstallError(m_addon->ID(), m_addon->ID(), g_localizeStrings.Get(24085));
Expand Down Expand Up @@ -863,14 +863,12 @@ bool CAddonUnInstallJob::DoWork()
{
ADDON::OnPreUnInstall(m_addon);

//TODO: looks broken. it just calls the repo with the most recent version, not the owner
RepositoryPtr repoPtr;
if (!CAddonInstaller::GetRepoForAddon(m_addon->ID(), repoPtr))
return false;
if (repoPtr != NULL && !repoPtr->Props().libname.empty())
AddonPtr repoPtr = CAddonInstaller::GetRepoForAddon(m_addon->ID());
RepositoryPtr therepo = std::dynamic_pointer_cast<CRepository>(repoPtr);
if (therepo != NULL && !therepo->Props().libname.empty())
{
CFileItemList dummy;
std::string s = StringUtils::Format("plugin://%s/?action=uninstall&package=%s", repoPtr->ID().c_str(), m_addon->ID().c_str());
std::string s = StringUtils::Format("plugin://%s/?action=uninstall&package=%s", therepo->ID().c_str(), m_addon->ID().c_str());
if (!CDirectory::GetDirectory(s, dummy))
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions xbmc/addons/AddonInstaller.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ class CAddonInstaller : public IJobCallback
void OnJobComplete(unsigned int jobID, bool success, CJob* job);
void OnJobProgress(unsigned int jobID, unsigned int progress, unsigned int total, const CJob *job);

/*! \brief Get the repository which hosts the most recent version of add-on
/*! \brief Find which repository hosts an add-on
* \param addon The add-on to find the repository for
* \param repo [out] The hosting repository
* \return The hosting repository
*/
static bool GetRepoForAddon(const std::string& addonId, ADDON::RepositoryPtr& repo);
static ADDON::AddonPtr GetRepoForAddon(const std::string& addonId);

class CDownloadJob
{
Expand Down

0 comments on commit 0c265bd

Please sign in to comment.