fixed: installating/updating several add-ons with the same dependencies
authorspiff <spiff@xbmc.org>
Mon, 14 Nov 2011 15:22:25 +0000 (16:22 +0100)
committerspiff <spiff@xbmc.org>
Mon, 14 Nov 2011 15:30:09 +0000 (16:30 +0100)
if we had a job already registered, the Install() call in the dependency
install code would return false, thus halting the installation
we now wait around until the job finishes instead

xbmc/addons/AddonInstaller.cpp
xbmc/addons/AddonInstaller.h

index 5bdcf62..7de9eee 100644 (file)
@@ -324,6 +324,12 @@ void CAddonInstaller::UpdateRepos(bool force, bool wait)
   }
 }
 
+bool CAddonInstaller::HasJob(const CStdString& ID) const
+{
+  CSingleLock lock(m_critSection);
+  return m_downloadJobs.find(ID) != m_downloadJobs.end();
+}
+
 CAddonInstallJob::CAddonInstallJob(const AddonPtr &addon, const CStdString &hash, bool update, const CStdString &referer)
 : m_addon(addon), m_hash(hash), m_update(update), m_referer(referer)
 {
@@ -459,8 +465,18 @@ bool CAddonInstallJob::Install(const CStdString &installFrom)
     AddonPtr dependency;
     if (!CAddonMgr::Get().GetAddon(it->first,dependency) || dependency->Version() < it->second.first)
     {
+      bool force=(dependency != NULL);
+      // dependency is already queued up for install - ::Install will fail
+      // instead we wait until the Job has finished. note that we
+      // recall install on purpose in case prior installation failed
+      if (CAddonInstaller::Get().HasJob(it->first))
+      {
+        while (CAddonInstaller::Get().HasJob(it->first))
+          Sleep(50);
+        force = false;
+      }
       // don't have the addon or the addon isn't new enough - grab it (no new job for these)
-      if (!CAddonInstaller::Get().Install(it->first, dependency != NULL, referer, false))
+      if (!CAddonInstaller::Get().Install(it->first, force, referer, false))
       {
         DeleteAddon(addonFolder);
         return false;
index 5bc7dd4..f16cf45 100644 (file)
@@ -72,6 +72,13 @@ public:
    \param force whether we should run an update regardless of the normal update cycle. Defaults to false.
    \param wait whether we should busy wait for the updates to be performed. Defaults to false.
    */
+
+  /*! \brief Check if an installation job for a given add-on is already queued up
+   *  \param ID The ID of the add-on
+   *  \return true if a job exists, false otherwise
+   */
+  bool HasJob(const CStdString& ID) const;
+
   void UpdateRepos(bool force = false, bool wait = false);
 
   void OnJobComplete(unsigned int jobID, bool success, CJob* job);