<div dir="ltr"><div>From a5c774c549d83284fff161ae64f658f1ebe5b268 Mon Sep 17 00:00:00 2001</div><div>From: Jonathan Kang <<a href="mailto:jonathan121537@gmail.com">jonathan121537@gmail.com</a>></div><div>Date: Thu, 23 Feb 2017 14:53:45 +0800</div><div>Subject: [PATCH] zypp: Improve zypp_refresh_cache in zypp backend</div><div><br></div><div>---</div><div> backends/zypp/pk-backend-zypp.cpp | 86 ++++++++++++++++++++++++++++++++++-----</div><div> 1 file changed, 76 insertions(+), 10 deletions(-)</div><div><br></div><div>diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp</div><div>index 5006928..a3ba9c2 100644</div><div>--- a/backends/zypp/pk-backend-zypp.cpp</div><div>+++ b/backends/zypp/pk-backend-zypp.cpp</div><div>@@ -986,20 +986,27 @@ static gboolean</div><div> zypp_refresh_meta_and_cache (RepoManager &manager, RepoInfo &repo, bool force = false)</div><div> {</div><div> <span class="Apple-tab-span" style="white-space:pre">  </span>try {</div><div>-<span class="Apple-tab-span" style="white-space:pre">               </span>if (manager.checkIfToRefreshMetadata (repo, repo.url())    //RepoManager::RefreshIfNeededIgnoreDelay)</div><div>-<span class="Apple-tab-span" style="white-space:pre">             </span>    != RepoManager::REFRESH_NEEDED)</div><div>-<span class="Apple-tab-span" style="white-space:pre">                       </span>return TRUE;</div><div>-</div><div> <span class="Apple-tab-span" style="white-space:pre">               </span>sat::Pool pool = sat::Pool::instance ();</div><div>-<span class="Apple-tab-span" style="white-space:pre">            </span>// Erase old solv file</div><div>-<span class="Apple-tab-span" style="white-space:pre">              </span>pool.reposErase (repo.alias ());</div><div>+</div><div> <span class="Apple-tab-span" style="white-space:pre">           </span>manager.refreshMetadata (repo, force ?</div><div> <span class="Apple-tab-span" style="white-space:pre">                                     </span> RepoManager::RefreshForced :</div><div> <span class="Apple-tab-span" style="white-space:pre">                                      </span> RepoManager::RefreshIfNeededIgnoreDelay);</div><div> <span class="Apple-tab-span" style="white-space:pre">         </span>manager.buildCache (repo, force ?</div><div> <span class="Apple-tab-span" style="white-space:pre">                          </span>    RepoManager::BuildForced :</div><div> <span class="Apple-tab-span" style="white-space:pre">                           </span>    RepoManager::BuildIfNeeded);</div><div>-<span class="Apple-tab-span" style="white-space:pre">          </span>manager.loadFromCache (repo);</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>try</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>manager.loadFromCache (repo);</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>catch (const Exception &exp)</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>// cachefile has old fomat (or is corrupted): rebuild it</div><div>+<span class="Apple-tab-span" style="white-space:pre">                    </span>manager.cleanCache (repo);</div><div>+<span class="Apple-tab-span" style="white-space:pre">                  </span>manager.buildCache (repo, force ?</div><div>+<span class="Apple-tab-span" style="white-space:pre">                                   </span>    RepoManager::BuildForced :</div><div>+<span class="Apple-tab-span" style="white-space:pre">                                    </span>    RepoManager::BuildIfNeeded);</div><div>+<span class="Apple-tab-span" style="white-space:pre">                  </span>manager.loadFromCache (repo);</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>}</div><div> <span class="Apple-tab-span" style="white-space:pre">          </span>return TRUE;</div><div> <span class="Apple-tab-span" style="white-space:pre">       </span>} catch (const AbortTransactionException &ex) {</div><div> <span class="Apple-tab-span" style="white-space:pre">                </span>return FALSE;</div><div>@@ -1578,9 +1585,44 @@ zypp_refresh_cache (PkBackendJob *job, ZYpp::Ptr zypp, gboolean force)</div><div> <span class="Apple-tab-span" style="white-space:pre">  </span>if (zypp == NULL)</div><div> <span class="Apple-tab-span" style="white-space:pre">          </span>return  FALSE;</div><div> <span class="Apple-tab-span" style="white-space:pre">    </span>filesystem::Pathname pathname("/");</div><div>-<span class="Apple-tab-span" style="white-space:pre">       </span>// This call is needed to refresh system rpmdb status while refresh cache</div><div>-<span class="Apple-tab-span" style="white-space:pre">   </span>zypp->finishTarget ();</div><div>-<span class="Apple-tab-span" style="white-space:pre">   </span>zypp->initializeTarget (pathname);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>bool poolIsClean = sat::Pool::instance ().reposEmpty ();</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>// Erase and reload all if pool is too holey (densyity [100: good | 0 bad])</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>// NOTE sat::Pool::capacity() > 2 is asserted in division</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>if (!poolIsClean &&</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    sat::Pool::instance ().solvablesSize () * 100 / sat::Pool::instance ().capacity () < 33)</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>sat::Pool::instance ().reposEraseAll ();</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>poolIsClean = true;</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>Target_Ptr target = zypp->getTarget ();</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>if (!target)</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>zypp->initializeTarget (pathname);<span class="Apple-tab-span" style="white-space:pre">       </span>// initial target</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>target = zypp->getTarget ();</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>else</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>// interim storage to avoid delete while iterating</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>std::set<std::string> idsToDelete;</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>const std::set<Edition> &rpmdbKeys (zypp->target ()->rpmDb ().pubkeyEditions ());</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>// load rpmdb trusted keys into zypp keyring</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>target->rpmDb ().exportTrustedKeysInZyppKeyRing ();</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>// keys no longer stored in the rpmdb need to be removed from the zypp keyring!</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>for (const PublicKeyData &el : zypp->keyRing ()->trustedPublicKeyData ())</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>if(!rpmdbKeys.count (Edition(el.gpgPubkeyVersion (), el.gpgPubkeyRelease ())))</div><div>+<span class="Apple-tab-span" style="white-space:pre">                              </span>idsToDelete.insert (<a href="http://el.id">el.id</a> ());</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>for (const std::string & idToDelete : idsToDelete)</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>zypp->keyRing ()->deleteKey (idToDelete, true);</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>// load installed packages to pool</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>target->load ();</div><div> </div><div> <span class="Apple-tab-span" style="white-space:pre">       </span>pk_backend_job_set_status (job, PK_STATUS_ENUM_REFRESH_CACHE);</div><div> <span class="Apple-tab-span" style="white-space:pre">     </span>pk_backend_job_set_percentage (job, 0);</div><div>@@ -1598,6 +1640,22 @@ zypp_refresh_cache (PkBackendJob *job, ZYpp::Ptr zypp, gboolean force)</div><div> <span class="Apple-tab-span" style="white-space:pre">                </span>return FALSE;</div><div> <span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div> </div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>if (!poolIsClean)</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>std::vector<std::string> aliasesToRemove;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>for (const Repository &poolrepo : zypp->pool ().knownRepositories ())</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>if (!(poolrepo.isSystemRepo () || manager.hasRepo (poolrepo.alias ())))</div><div>+<span class="Apple-tab-span" style="white-space:pre">                             </span>aliasesToRemove.push_back (poolrepo.alias ());</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>for (const std::string &aliasToRemove : aliasesToRemove)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>sat::Pool::instance ().reposErase (aliasToRemove);</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div>+</div><div> <span class="Apple-tab-span" style="white-space:pre">  </span>int i = 1;</div><div> <span class="Apple-tab-span" style="white-space:pre"> </span>int num_of_repos = repos.size ();</div><div> <span class="Apple-tab-span" style="white-space:pre">  </span>gchar *repo_messages = NULL;</div><div>@@ -1612,7 +1670,11 @@ zypp_refresh_cache (PkBackendJob *job, ZYpp::Ptr zypp, gboolean force)</div><div> </div><div> <span class="Apple-tab-span" style="white-space:pre">          </span>// skip disabled repos</div><div> <span class="Apple-tab-span" style="white-space:pre">             </span>if (repo.enabled () == false)</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>if (!poolIsClean)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                           </span>sat::Pool::instance ().reposErase (repo.alias ());</div><div> <span class="Apple-tab-span" style="white-space:pre">                 </span>continue;</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>}</div><div> </div><div> <span class="Apple-tab-span" style="white-space:pre">         </span>// do as zypper does</div><div> <span class="Apple-tab-span" style="white-space:pre">               </span>if (!force && !repo.autorefresh())</div><div>@@ -1621,7 +1683,11 @@ zypp_refresh_cache (PkBackendJob *job, ZYpp::Ptr zypp, gboolean force)</div><div> <span class="Apple-tab-span" style="white-space:pre">             </span>// skip changeable media (DVDs and CDs).  Without doing this,</div><div> <span class="Apple-tab-span" style="white-space:pre">             </span>// the disc would be required to be physically present.</div><div> <span class="Apple-tab-span" style="white-space:pre">            </span>if (repo.baseUrlsBegin ()->schemeIsVolatile())</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>{</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>if (!poolIsClean)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                           </span>sat::Pool::instance ().reposErase (repo.alias ());</div><div> <span class="Apple-tab-span" style="white-space:pre">                 </span>continue;</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>}</div><div> </div><div> <span class="Apple-tab-span" style="white-space:pre">         </span>try {</div><div> <span class="Apple-tab-span" style="white-space:pre">                      </span>// Refreshing metadata</div><div>-- </div><div>2.9.3</div><div><br></div></div>