From a0f4bbf8f98702e977b8fe88ef5140bbf703813c Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 12 Sep 2007 17:05:40 +0000 Subject: [PATCH] - Various disk space calculation fixes. Susetags, plaindir and rpmdb now provide more detailed disk usage information. Yum metadata don't, so we book the package size to '/'. (#308362) --- VERSION.cmake | 6 +- devel/devel.ma/Parse.cc | 60 ++++++++++++++---- package/libzypp.changes | 12 +++- zypp/DiskUsageCounter.cc | 159 +++++++++++------------------------------------ 4 files changed, 96 insertions(+), 141 deletions(-) diff --git a/VERSION.cmake b/VERSION.cmake index 050152b..2fdc770 100644 --- a/VERSION.cmake +++ b/VERSION.cmake @@ -45,6 +45,6 @@ # SET(LIBZYPP_MAJOR "3") -SET(LIBZYPP_MINOR "22") -SET(LIBZYPP_COMPATMINOR "21") -SET(LIBZYPP_PATCH "8") +SET(LIBZYPP_MINOR "23") +SET(LIBZYPP_COMPATMINOR "23") +SET(LIBZYPP_PATCH "0") diff --git a/devel/devel.ma/Parse.cc b/devel/devel.ma/Parse.cc index cf943db..6814265 100644 --- a/devel/devel.ma/Parse.cc +++ b/devel/devel.ma/Parse.cc @@ -83,7 +83,7 @@ struct Xprint { bool operator()( const PoolItem & obj_r ) { - handle( asKind( obj_r ) ); +// handle( asKind( obj_r ) ); // handle( asKind( obj_r ) ); // handle( asKind( obj_r ) ); // handle( asKind( obj_r ) ); @@ -372,6 +372,19 @@ namespace zypp using namespace zypp; +void tt( std::string dd ) +{ + unsigned level = 3; + std::string::size_type pos = dd.find( "/" ); + while ( --level && pos != std::string::npos ) + { + pos = dd.find( "/", pos+1 ); + } + if ( pos != std::string::npos ) + dd.erase( pos+1 ); + DBG << dd << "\t" << level << " " << pos << endl; +} + /****************************************************************** ** ** FUNCTION NAME : main @@ -386,6 +399,19 @@ int main( int argc, char * argv[] ) DigestReceive foo; KeyRingSignalsReceive baa; + DiskUsageCounter::MountPointSet fakePart; + fakePart.insert( DiskUsageCounter::MountPoint( "/", 1024, 10240, 5120, 0LL, false ) ); +// fakePart.insert( DiskUsageCounter::MountPoint( "/usr", 1024, 10240, 5120, 0LL, false ) ); + fakePart.insert( DiskUsageCounter::MountPoint( "/usr/lib", 1024, 10240, 5120, 0LL, false ) ); + fakePart.insert( DiskUsageCounter::MountPoint( "/usr/bin", 1024, 10240, 5120, 0LL, false ) ); + getZYpp()->setPartitions( fakePart ); + + ResPool pool( getZYpp()->pool() ); + vdumpPoolStats( USR << "Initial pool:" << endl, + pool.begin(), + pool.end() ) << endl; + + RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) ); RepoInfoList repos = repoManager.knownRepositories(); SEC << repos << endl; @@ -409,11 +435,6 @@ int main( int argc, char * argv[] ) repos = repoManager.knownRepositories(); } - ResPool pool( getZYpp()->pool() ); - vdumpPoolStats( USR << "Initial pool:" << endl, - pool.begin(), - pool.end() ) << endl; - for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it ) { RepoInfo & nrepo( *it ); @@ -448,7 +469,7 @@ int main( int argc, char * argv[] ) if ( 1 ) { { - zypp::base::LogControl::TmpLineWriter shutUp; + zypp::base::LogControl::TmpLineWriter shutUp; //getZYpp()->initTarget( sysRoot ); getZYpp()->initTarget( "/" ); } @@ -457,10 +478,6 @@ int main( int argc, char * argv[] ) std::for_each( pool.begin(), pool.end(), Xprint() ); - DiskUsageCounter::MountPointSet fakePart; - fakePart.insert( DiskUsageCounter::MountPoint( "/", 1024, 10240, 5120, 0LL, false ) ); - getZYpp()->setPartitions( fakePart ); - USR << getZYpp()->getPartitions() << endl; INT << getZYpp()->diskUsage() << endl; @@ -471,12 +488,31 @@ int main( int argc, char * argv[] ) dbgDu( sel ); MIL << sel->set_status( ui::S_Update ) << endl; +// sel->installedPoolItem().status().setTransact( true, ResStatus::SOLVER ); + dbgDu( sel ); + + MIL << sel->set_status( ui::S_KeepInstalled ) << endl; + dbgDu( sel ); + + sel = getSel( "balsa" ); + dbgDu( sel ); + + MIL << sel->set_status( ui::S_Install ) << endl; + dbgDu( sel ); + + MIL << sel->set_status( ui::S_NoInst ) << endl; + dbgDu( sel ); + + sel = getSel( "libtunepimp" ); + dbgDu( sel ); + + MIL << sel->set_status( ui::S_Del ) << endl; dbgDu( sel ); MIL << sel->set_status( ui::S_KeepInstalled ) << endl; dbgDu( sel ); - /////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// INT << "===[END]============================================" << endl << endl; zypp::base::LogControl::instance().logNothing(); return 0; diff --git a/package/libzypp.changes b/package/libzypp.changes index ba1a716..2b8a075 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,8 +1,16 @@ ------------------------------------------------------------------- +Wed Sep 12 18:48:00 CEST 2007 - ma@suse.de + +- Various disk space calculation fixes. Susetags, plaindir and rpmdb + now provide more detailed disk usage information. + Yum metadata don't, so we book the package size to '/'. (#308362) +- version 3.23.0 + +------------------------------------------------------------------- Wed Sep 12 15:48:41 CEST 2007 - schubi@suse.de - Regarding keep state while recycle old valid solver results. Bug 286889 -- r 7209 +- r 7209 ------------------------------------------------------------------- Wed Sep 12 12:24:49 CEST 2007 - jkupec@suse.cz @@ -15,7 +23,7 @@ Tue Sep 11 17:25:35 CEST 2007 - schubi@suse.de - Update: rename language packages --> take that package which fits to the selected language Bug 308098 -- r 7919 +- r 7919 ------------------------------------------------------------------- Tue Sep 11 16:11:20 CEST 2007 - dmacvicar@suse.de diff --git a/zypp/DiskUsageCounter.cc b/zypp/DiskUsageCounter.cc index 5b54497..ebf93f5 100644 --- a/zypp/DiskUsageCounter.cc +++ b/zypp/DiskUsageCounter.cc @@ -17,159 +17,70 @@ extern "C" #include #include +#include "zypp/base/Easy.h" #include "zypp/base/Logger.h" #include "zypp/base/String.h" #include "zypp/DiskUsageCounter.h" #include "zypp/Package.h" +using std::endl; /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// - DiskUsageCounter::MountPointSet DiskUsageCounter::disk_usage(const ResPool &pool) + DiskUsageCounter::MountPointSet DiskUsageCounter::disk_usage( const ResPool & pool_r ) { - MountPointSet result = mps; + DiskUsageCounter::MountPointSet result = mps; - if (mps.empty()) + if ( result.empty() ) { // partitioning is not set return result; } // set used size after commit to the current used size - for (MountPointSet::iterator mpit = result.begin(); - mpit != result.end(); - mpit++) + for_( it, result.begin(), result.end() ) { - mpit->pkg_size = mpit->used_size; + it->pkg_size = it->used_size; } - // iterate through all packages - for (ResPool::byKind_iterator it = pool.byKindBegin(ResTraits::kind); - it != pool.byKindEnd(ResTraits::kind); - ++it) + // iterate through all items + for_( it, pool_r.begin(), pool_r.end() ) { - bool inst = it->status().isToBeInstalled(); - bool rem = it->status().isToBeUninstalled(); + DiskUsage du( (*it)->diskusage() ); - // if the package is not selected for installation or removing - // it can't affect disk usage - if (inst || rem) - { - Package::constPtr pkg = asKind( 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 - // find the same package from any installation source - std::string name = (*it)->name(); - - for (ResPool::byName_iterator nameit = pool.byNameBegin(name); - nameit != pool.byNameEnd(name); - ++nameit) - { - // is version and architecture same? - if (isKind(nameit->resolvable())) - { - // found a package - Package::constPtr pkg_from_source = asKind( nameit->resolvable() ); - - if (nameit->status().isToBeInstalled()) - { - found_to_install = true; - } - - // check the version - if ((*it)->edition() == (*nameit)->edition() && (*it)->arch() == (*nameit)->arch()) - { - if (inst) - { - if (nameit->status().isInstalled() && !nameit->status().isToBeUninstalled()) - { - found_installed = true; - XXX << 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) - { - XXX << name << '-' << (*it)->edition() << ": using DiskUsage from another Package object (" << (*nameit)->edition() << ")" << std::endl; - break; - } - } - } - else - { - if (inst && nameit->status().isInstalled() && !nameit->status().isToBeUninstalled()) - { - // just freshen the package, don't change du statistics - found_installed = true; - XXX << 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(); - } - } - } - } + // skip items without du info + if ( du.empty() ) + continue; // or find some substitute info - // don't subtract the disk usage for updated package - if (du.size() == 0 && du_another_package.size() > 0 && !(rem && found_to_install)) - { - XXX << name << '-' << (*it)->edition() << ": using DU info from version " << edition_another_package << std::endl; - du = du_another_package; - } - } + // skip items that do not transact + if ( ! it->status().transacts() ) + continue; - // 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 - // so iterate in reverse order so e.g. /usr is used before / - for (MountPointSet::reverse_iterator mpit = result.rbegin(); - mpit != result.rend(); - mpit++) - { - // get usage for the mount point - DiskUsage::Entry entry = du.extract(mpit->dir); - - // add or subtract it to the current value - if (inst) - { - mpit->pkg_size += entry._size; - } - else // the package will be uninstalled - { - mpit->pkg_size -= entry._size; - } - } - } + // traverse mountpoints in reverse order. This is done beacuse + // DiskUsage::extract computes the mountpoint size, and then + // removes the entry. So we must process leaves first. + for_( mpit, result.rbegin(), result.rend() ) + { + // Extract usage for the mount point + DiskUsage::Entry entry = du.extract( mpit->dir ); + + // Adjust the data. + if ( it->status().isInstalled() ) + { + mpit->pkg_size -= entry._size; + } + else + { + mpit->pkg_size += entry._size; + } } } - return result; } - DiskUsageCounter::MountPointSet DiskUsageCounter::detectMountPoints(const std::string &rootdir) { DiskUsageCounter::MountPointSet ret; @@ -308,8 +219,8 @@ namespace zypp str << "dir:[" << obj.dir << "] [ bs: " << obj.block_size << " ts: " << obj.total_size << " us: " << obj.used_size - << " +-: " << obj.pkg_size - << "]" << std::endl; + << " (+-: " << (obj.pkg_size-obj.used_size) + << ")]" << std::endl; return str; } -- 2.7.4