From 4bc40ba0e14b8afc7b3d16ccf4aef39701ba13aa Mon Sep 17 00:00:00 2001 From: Ladislav Slezak Date: Thu, 6 Apr 2006 13:17:34 +0000 Subject: [PATCH] - fixed disk usage counting of updated packages (#163197), use disk usage from different version if it is not provided --- zypp/DiskUsageCounter.cc | 68 +++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/zypp/DiskUsageCounter.cc b/zypp/DiskUsageCounter.cc index 531f7989c..366274d7c 100644 --- a/zypp/DiskUsageCounter.cc +++ b/zypp/DiskUsageCounter.cc @@ -52,13 +52,19 @@ namespace zypp // if the package is not selected for installation or removing // it can't affect disk usage - if ((inst && !installed) || (rem && installed)) + if (inst || rem) { Package::constPtr pkg = boost::dynamic_pointer_cast( it->resolvable() ); DiskUsage du = pkg->diskusage(); + DiskUsage du_another_package; + Edition edition_another_package; + // the same package has been selected for installation bool found_installed = false; + // the same package has been selected for uninstallation + bool found_to_install = false; + // the du is empty or the package is selected for installation (check whether the package is already installed) if (du.size() == 0 || inst) { // disk usage is unknown for already installed packages @@ -70,33 +76,67 @@ namespace zypp ++nameit) { // is version and architecture same? - if (isKind(nameit->resolvable()) && (*it)->edition() == (*nameit)->edition() && (*it)->arch() == (*nameit)->arch()) + if (isKind(nameit->resolvable())) { - if (inst) + // found a package + Package::constPtr pkg_from_source = boost::dynamic_pointer_cast( nameit->resolvable() ); + + if (nameit->status().isToBeInstalled()) + { + found_to_install = true; + } + + // check the version + if ((*it)->edition() == (*nameit)->edition() && (*it)->arch() == (*nameit)->arch()) { - if (nameit->status().isInstalled()) + if (inst) { - found_installed = true; - DBG << name << '-' << (*nameit)->edition() << ": found already installed package" << std::endl; + if (nameit->status().isInstalled()) + { + found_installed = true; + DBG << name << '-' << (*it)->edition() << ": found already installed package (" << (*nameit)->edition() << ")" << std::endl; + } + } + else + { + // the package will be uninstalled and du is empty, try to use du from another object + du = pkg_from_source->diskusage(); + if (du.size() > 0) + { + DBG << name << '-' << (*it)->edition() << ": using DiskUsage from another Package object (" << (*nameit)->edition() << ")" << std::endl; + break; + } } } else { - // found the same package - Package::constPtr pkg_from_source = boost::dynamic_pointer_cast( nameit->resolvable() ); - du = pkg_from_source->diskusage(); - if (du.size() > 0) + if (inst && nameit->status().isInstalled()) { - DBG << name << '-' << (*nameit)->edition() << ": using DiskUsage from another Package object" << std::endl; - break; + // just freshen the package, don't change du statistics + found_installed = true; + DBG << name << '-' << (*it)->edition() << ": found already installed package (" << (*nameit)->edition() << ")" << std::endl; + } + else if (pkg_from_source->diskusage().size() > 0) + { + // found different version of the package, remember the disk usage + // it will be used the same version is not found + du_another_package = pkg_from_source->diskusage(); + edition_another_package = (*nameit)->edition(); } } } } - } + // don't subtract the disk usage for updated package + if (du.size() == 0 && du_another_package.size() > 0 && !(rem && found_to_install)) + { + DBG << name << '-' << (*it)->edition() << ": using DU info from version " << edition_another_package << std::endl; + du = du_another_package; + } + } - if (!inst || !found_installed) + // don't modify du if the installed package is already installed (freshening) + if (du.size() > 0 && !(inst && found_installed)) { // iterate trough all mount points, add usage to each directory // directory tree must be processed from leaves to the root directory -- 2.34.1