1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/DiskUsageCounter.h
12 #ifndef ZYPP_DISKUSAGE_COUNTER_H
13 #define ZYPP_DISKUSAGE_COUNTER_H
15 #include "zypp/ResPool.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
25 class DiskUsageCounter
31 * @short Mount point description
41 * Block size of the mount point
46 * Total size in K (1024)
51 * Used size in K (1024)
56 * Used size after commiting the pool (in K)
58 mutable long long pkg_size;
63 * Ctor - initialize directory and package size
65 MountPoint(std::string d = "/", long long bs = 0LL, long long total = 0LL, long long used = 0LL, long long pkg = 0LL, bool ro=false) :
66 dir(d), block_size(bs), total_size(total), used_size(used), pkg_size(pkg), readonly(ro)
69 // sort by directory name
70 bool operator<( const MountPoint & rhs ) const
75 ByteCount blockSize() const
76 { return ByteCount( block_size, ByteCount::B ); }
78 ByteCount totalSize() const
79 { return ByteCount( total_size, ByteCount::K ); }
81 ByteCount usedSize() const
82 { return ByteCount( used_size, ByteCount::K ); }
84 ByteCount freeSize() const
85 { return ByteCount( total_size-used_size, ByteCount::K ); }
87 ByteCount usedAfterCommit() const
88 { return ByteCount( pkg_size, ByteCount::K ); }
90 ByteCount freeAfterCommit() const
91 { return ByteCount( total_size-pkg_size, ByteCount::K ); }
93 ByteCount commitDiff() const
94 { return ByteCount( pkg_size-used_size, ByteCount::K ); }
97 typedef std::set<MountPoint> MountPointSet;
102 DiskUsageCounter( const MountPointSet & m )
106 bool setMountPoints( const MountPointSet & m )
112 const MountPointSet & getMountPoints() const
117 static MountPointSet detectMountPoints(const std::string &rootdir = "/");
119 static MountPointSet justRootPartition();
122 * Compute disk usage of the pool
124 MountPointSet disk_usage( const ResPool & pool );
127 * Compute disk usage of one solvable
129 MountPointSet disk_usage( sat::Solvable solv_r );
131 MountPointSet disk_usage( const PoolItem & pi_r )
132 { return disk_usage( pi_r.satSolvable() ); }
134 MountPointSet disk_usage( const ResObject::constPtr & obj_r )
137 return MountPointSet();
138 return disk_usage( obj_r->satSolvable() );
145 ///////////////////////////////////////////////////////////////////
147 /** \relates DiskUsageCounter::MountPoint Stream output */
148 std::ostream & operator<<( std::ostream & str, const DiskUsageCounter::MountPoint & obj );
150 /////////////////////////////////////////////////////////////////
152 ///////////////////////////////////////////////////////////////////
153 #endif // ZYPP_DISKUSAGE_COUNTER_H