libzypp  10.5.0
DiskUsageCounter.h
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_DISKUSAGE_COUNTER_H
00013 #define ZYPP_DISKUSAGE_COUNTER_H
00014 
00015 #include <zypp/ResPool.h>
00016 
00017 #include <set>
00018 #include <string>
00019 #include <iosfwd>
00020 
00022 namespace zypp
00023 { 
00024 
00025   class DiskUsageCounter
00026   {
00027 
00028   public:
00029 
00033     struct MountPoint
00034     {
00038       std::string dir;
00039 
00043       long long block_size;
00044 
00048       long long total_size;
00049 
00053       long long used_size;
00054 
00058       mutable long long pkg_size;
00059 
00060       bool readonly;
00061 
00065       MountPoint(std::string d = "/", long long bs = 0LL, long long total = 0LL, long long used = 0LL, long long pkg = 0LL, bool ro=false) :
00066         dir(d), block_size(bs), total_size(total), used_size(used), pkg_size(pkg), readonly(ro)
00067       {}
00068 
00069       // sort by directory name
00070       bool operator<( const MountPoint & rhs ) const
00071       {
00072         return dir < rhs.dir;
00073       }
00074 
00075       ByteCount blockSize() const
00076       { return ByteCount( block_size, ByteCount::B ); }
00077 
00078       ByteCount totalSize() const
00079       { return ByteCount( total_size, ByteCount::K ); }
00080 
00081       ByteCount usedSize() const
00082       { return ByteCount( used_size, ByteCount::K ); }
00083 
00084       ByteCount freeSize() const
00085       { return ByteCount( total_size-used_size, ByteCount::K ); }
00086 
00087       ByteCount usedAfterCommit() const
00088       { return ByteCount( pkg_size, ByteCount::K ); }
00089 
00090       ByteCount freeAfterCommit() const
00091       { return ByteCount( total_size-pkg_size, ByteCount::K ); }
00092 
00093       ByteCount commitDiff() const
00094       { return ByteCount( pkg_size-used_size, ByteCount::K ); }
00095     };
00096 
00097     typedef std::set<MountPoint> MountPointSet;
00098 
00099     DiskUsageCounter()
00100     {}
00101 
00102     DiskUsageCounter( const MountPointSet & m )
00103     : mps( m )
00104     {}
00105 
00106     bool setMountPoints( const MountPointSet & m )
00107     {
00108         mps = m;
00109         return true;
00110     }
00111 
00112     const MountPointSet & getMountPoints() const
00113     {
00114         return mps;
00115     }
00116 
00117     static MountPointSet detectMountPoints(const std::string &rootdir = "/");
00118 
00119     static MountPointSet justRootPartition();
00120 
00124     MountPointSet disk_usage( const ResPool & pool );
00125 
00129     MountPointSet disk_usage( sat::Solvable solv_r );
00131     MountPointSet disk_usage( const PoolItem & pi_r  )
00132     { return disk_usage( pi_r.satSolvable() ); }
00134     MountPointSet disk_usage( const ResObject::constPtr & obj_r )
00135     {
00136       if ( ! obj_r )
00137         return MountPointSet();
00138       return disk_usage( obj_r->satSolvable() );
00139     }
00140 
00141   private:
00142 
00143     MountPointSet mps;
00144   };
00146 
00148   std::ostream & operator<<( std::ostream & str, const DiskUsageCounter::MountPoint & obj );
00149 
00151 } // namespace zypp
00153 #endif // ZYPP_DISKUSAGE_COUNTER_H