[zypp-commit] r7213 - /trunk/libzypp/zypp/parser/susetags/PackagesDuFileReader.cc
![](https://seccdn.libravatar.org/avatar/1a5a039cbdb74b7bb361ba2e9d30cb91.jpg?s=120&d=mm&r=g)
Author: mlandres Date: Wed Sep 12 17:15:55 2007 New Revision: 7213 URL: http://svn.opensuse.org/viewcvs/zypp?rev=7213&view=rev Log: Store DU entries, if they are equal to or parent of a mountpoint. If no mountpoints are available limit DU entries to depth 3. Modified: trunk/libzypp/zypp/parser/susetags/PackagesDuFileReader.cc Modified: trunk/libzypp/zypp/parser/susetags/PackagesDuFileReader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/parser/susetags/PackagesDuFileReader.cc?rev=7213&r1=7212&r2=7213&view=diff ============================================================================== --- trunk/libzypp/zypp/parser/susetags/PackagesDuFileReader.cc (original) +++ trunk/libzypp/zypp/parser/susetags/PackagesDuFileReader.cc Wed Sep 12 17:15:55 2007 @@ -13,6 +13,7 @@ #include "zypp/base/Easy.h" #include "zypp/base/Regex.h" #include "zypp/base/Logger.h" +#include "zypp/base/String.h" #include "zypp/ZYppFactory.h" #include "zypp/parser/susetags/PackagesDuFileReader.h" @@ -42,25 +43,20 @@ public: Impl( const PackagesDuFileReader & parent_r ) : BaseImpl( parent_r ) - , _counted_entries(0) - , _discarded_entries(0) { _mounts = getZYpp()->getPartitions(); - + for ( DiskUsageCounter::MountPointSet::const_iterator it = _mounts.begin(); it != _mounts.end(); ++ it ) { MIL << "Partition " << *it << endl; } - + } virtual ~Impl() - { - MIL << "DiskUsage: consumed:[ " << _counted_entries - << " ] discarded:[ " << _discarded_entries << " ]" << endl; - } + {} bool hasPackage() const { return _pkgData; } @@ -133,58 +129,52 @@ if ( str::regex_match( *it, what, sizeEntryRX ) ) { bool skip = true; - - // add slash if it's missing - std::string dd(what[1]); - if (dd.size() > 1 && dd[0] != '/') - { - dd.insert(dd.begin(), '/'); - } - - DiskUsage::Entry entry(dd, - str::strtonum<unsigned>(what[2]) + str::strtonum<unsigned>(what[3]), - str::strtonum<unsigned>(what[4]) + str::strtonum<unsigned>(what[5]) ); - + DiskUsage::Entry entry( what[1], + str::strtonum<unsigned>(what[2]) + str::strtonum<unsigned>(what[3]), + str::strtonum<unsigned>(what[4]) + str::strtonum<unsigned>(what[5]) ); + if ( _mounts.empty() ) { - // if no mount information, parse it all - // FIXME at least detect levels? - skip = false; + // if no mount information, cut off deeper directory + // levels in DiskUsage::Entry to reduce data size. + unsigned level = 3; // number of '/' incl. a trailing one + std::string::size_type pos = 0; // we store absolute pathnames + while ( --level && pos != std::string::npos ) + { + pos = entry.path.find( "/", pos+1 ); + } + if ( pos != std::string::npos ) + { + // found 'level' number of '/'es. + skip = ( entry.path[pos] != '\0' ); + } + else + { + // less than 'level' number of '/'es. + skip = false; + } } else { - // iterate over important mounts in reverse order, from the leaves to - // the root + // Store entries, if they are equal to or parent of a mountpoint. for ( DiskUsageCounter::MountPointSet::reverse_iterator mit = _mounts.rbegin(); - mit != _mounts.rend(); - ++ mit ) + mit != _mounts.rend(); + ++ mit ) { - // if the directory we are adding is below one of the mount points - // just add the mount point so it gets summed. - //MIL << "is '" << entry.path << "' == '" << (*mit).dir << "' ?" << endl; - // FIXME make this more clear - if ( entry.path == ( ((*mit).dir[(*mit).dir.size()-1] == '/') ? (*mit).dir : ((*mit).dir + '/' ) ) ) + // Entry.path has leading and trailing '/' (asserted by DiskUsage::Entry). + // So we append a '/' to the mountpoint and test for prefix_r. + if ( str::hasPrefix( (mit->dir+"/"), entry.path ) ) { - // entry is a mountpoint, so we need to keep it - //MIL << "yes" << endl; - // just discard it - _discarded_entries++; skip = false; break; } - else - { - //MIL << "no" << endl; - } } } // try next entry if ( skip ) continue; - - //MIL << "adding entry for " << entry.path << endl; + _data->diskusage.add(entry); - _counted_entries++; } else { @@ -202,8 +192,6 @@ data::Package_Ptr _pkgData; data::SrcPackage_Ptr _srcpkgData; DiskUsageCounter::MountPointSet _mounts; - int _counted_entries; - int _discarded_entries; }; /////////////////////////////////////////////////////////////////// -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org
participants (1)
-
mlandres@svn.opensuse.org