libzypp 17.37.17
DiskUsageCounter.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef ZYPP_DISKUSAGE_COUNTER_H
13#define ZYPP_DISKUSAGE_COUNTER_H
14
15#include <set>
16#include <string>
17#include <iosfwd>
18#include <utility>
19
20#include <zypp/ResPool.h>
21#include <zypp/Bitmap.h>
22#include <zypp/base/Flags.h>
23
25namespace zypp
26{
27
33 {
34
35 public:
44 {
45 friend std::ostream & operator<<( std::ostream & str, const MountPoint & obj );
46 std::string dir;
47 std::string fstype;
48 long long block_size;
49 long long total_size;
50 long long used_size;
51 mutable long long pkg_size;
52 // hint bits:
53 bool readonly:1;
54 bool growonly:1;
55
56
58 enum Hint
59 {
60 NoHint = 0,
61 Hint_readonly = (1<<0),
62 Hint_growonly = (1<<1),
63 };
65
67 MountPoint( std::string d = "/",
68 std::string f = std::string(),
69 long long bs = 0LL, long long total = 0LL, long long used = 0LL, long long pkg = 0LL,
70 HintFlags hints = NoHint )
71 : dir(std::move(d)), fstype(std::move(f))
72 , block_size(bs), total_size(total), used_size(used), pkg_size(pkg)
73 , readonly(hints.testFlag(Hint_readonly))
74 , growonly(hints.testFlag(Hint_growonly))
75 {}
76
81 MountPoint( const char * d,
82 const std::string & f = std::string(),
83 long long bs = 0LL, long long total = 0LL, long long used = 0LL, long long pkg = 0LL,
84 HintFlags hints = NoHint )
85 : MountPoint( std::string(d?d:""), f, bs, total, used, pkg, hints )
86 {}
87
88
90 MountPoint( const std::string & d,
91 long long bs, long long total = 0LL, long long used = 0LL, long long pkg = 0LL,
92 HintFlags hints = NoHint )
93 : MountPoint( d, std::string(), bs, total, used, pkg, hints )
94 {}
95
96 MountPoint( const char * d,
97 long long bs, long long total = 0LL, long long used = 0LL, long long pkg = 0LL,
98 HintFlags hints = NoHint )
99 : MountPoint( std::string(d?d:""), bs, total, used, pkg, hints )
100 {}
101
102
104 MountPoint( const std::string & d, HintFlags hints )
105 : MountPoint( d, std::string(), 0LL, 0LL, 0LL, 0LL, hints )
106 {}
107
108 MountPoint( const char * d, HintFlags hints )
109 : MountPoint( std::string(d?d:""), hints )
110 {}
111
112 MountPoint( const std::string & d, Hint hint )
113 : MountPoint( d, HintFlags(hint) )
114 {}
115
116 MountPoint( const char * d, Hint hint )
117 : MountPoint( std::string(d?d:""), HintFlags(hint) )
118 {}
119
121 bool operator<( const MountPoint & rhs ) const
122 { return dir < rhs.dir; }
123
127
131
134 { return ByteCount( used_size, ByteCount::K ); }
135
139
143
147
151 };
152
153
154 using MountPointSet = std::set<MountPoint>;
155
158
161 : _mps(std::move( mps_r ))
162 {}
163
165 void setMountPoints( const MountPointSet & mps_r )
166 { _mps = mps_r; }
167
170 { return _mps; }
171
177 static MountPointSet detectMountPoints( const std::string & rootdir = "/" );
178
180 static MountPointSet justRootPartition();
181
182
184 MountPointSet disk_usage( const ResPool & pool ) const;
185
187 MountPointSet disk_usage( sat::Solvable solv_r ) const;
189 MountPointSet disk_usage( const PoolItem & pi_r ) const
190 { return disk_usage( sat::asSolvable()( pi_r ) ); }
191
193 { return disk_usage( sat::asSolvable()( obj_r ) ); }
194
196 MountPointSet disk_usage( const Bitmap & bitmap_r ) const;
197
199 template<class Iterator>
200 MountPointSet disk_usage( Iterator begin_r, Iterator end_r ) const
201 {
202 Bitmap bitmap( Bitmap::poolSize );
203 for_( it, begin_r, end_r )
204 bitmap.set( sat::asSolvable()( *it ).id() );
205 return disk_usage( bitmap );
206 }
207
208 private:
210 };
211
212
213 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(DiskUsageCounter::MountPoint::HintFlags);
214
216 std::ostream & operator<<( std::ostream & str, const DiskUsageCounter::MountPoint & obj ) ZYPP_API;
217
219 std::ostream & operator<<( std::ostream & str, const DiskUsageCounter::MountPointSet & obj ) ZYPP_API;
220
222 inline std::ostream & operator<<( std::ostream & str, const DiskUsageCounter & obj )
223 { return str << obj.getMountPoints(); }
224
226} // namespace zypp
228#endif // ZYPP_DISKUSAGE_COUNTER_H
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
Store and operate with byte count.
Definition ByteCount.h:32
static const Unit K
1024 Byte
Definition ByteCount.h:46
static const Unit B
1 Byte
Definition ByteCount.h:43
const MountPointSet & getMountPoints() const
Get the current MountPointSet.
MountPointSet disk_usage(Iterator begin_r, Iterator end_r) const
Compute disk usage of a collection (convertible by asSolvable).
MountPointSet disk_usage(const ResPool &pool) const
Compute disk usage if the current transaction woud be commited.
void setMountPoints(const MountPointSet &mps_r)
Set a MountPointSet to compute.
MountPointSet disk_usage(const PoolItem &pi_r) const
std::set< MountPoint > MountPointSet
MountPointSet disk_usage(const ResObject::constPtr &obj_r) const
DiskUsageCounter(MountPointSet mps_r)
Ctor taking the MountPointSet to compute.
std::ostream & operator<<(std::ostream &str, const DiskUsageCounter &obj)
Stream output.
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
TraitsType::constPtrType constPtr
Definition ResObject.h:43
Global ResObject pool.
Definition ResPool.h:62
static constexpr PoolSizeType poolSize
An object indicating the bitmap should match the current pools capacity.
Definition Map.h:41
void set(size_type idx_r)
Set bit idx_r.
Definition Map.cc:81
A Solvable object within the sat Pool.
Definition Solvable.h:54
Definition Arch.h:364
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
sat::Map Bitmap
Definition Bitmap.h:19
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
Mount point description If block_size is set DiskUsageCoutner will assume half a block_size is wasted...
MountPoint(const std::string &d, long long bs, long long total=0LL, long long used=0LL, long long pkg=0LL, HintFlags hints=NoHint)
Ctor initialize directory and sizes.
long long used_size
Used size of the filesystem in KiB (0 if you don't care)
MountPoint(const std::string &d, Hint hint)
ByteCount commitDiff() const
Size change due to installation as ByteCount for convenience.
MountPoint(const std::string &d, HintFlags hints)
Ctor just name and hints, all sizes 0.
ByteCount usedSize() const
Used size of the filesystem as ByteCount for convenience.
ByteCount freeSize() const
Free size of the filesystem as ByteCount for convenience.
@ Hint_growonly
growonly partitions (e.g. snapshotting btrfs)
MountPoint(const char *d, const std::string &f=std::string(), long long bs=0LL, long long total=0LL, long long used=0LL, long long pkg=0LL, HintFlags hints=NoHint)
long long block_size
Block size of the filesystem in B (0 if you don't care)
MountPoint(const char *d, HintFlags hints)
ByteCount freeAfterCommit() const
Free size after installation as ByteCount for convenience.
long long total_size
Total size of the filesystem in KiB (0 if you don't care)
MountPoint(const char *d, long long bs, long long total=0LL, long long used=0LL, long long pkg=0LL, HintFlags hints=NoHint)
bool readonly
hint for readonly partitions
std::string dir
Directory name.
ByteCount blockSize() const
Block size of the filesystem as ByteCount for convenience.
MountPoint(const char *d, Hint hint)
long long pkg_size
Used size after installation in KiB (computed by DiskUsageCoutner)
bool growonly
hint for growonly partitions (e.g. snapshotting btrfs)
bool operator<(const MountPoint &rhs) const
Sort by directory name.
ByteCount usedAfterCommit() const
Used size after installation as ByteCount for convenience.
MountPoint(std::string d="/", std::string f=std::string(), long long bs=0LL, long long total=0LL, long long used=0LL, long long pkg=0LL, HintFlags hints=NoHint)
Ctor initialize directory, fstype and sizes.
std::string fstype
Filesystem type (provided by detectMountPoints)
ByteCount totalSize() const
Total size of the filesystem as ByteCount for convenience.
To Solvable transform functor.
Definition Solvable.h:579
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition Easy.h:27
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
Definition Flags.h:177