fix build
[platform/upstream/libzypp.git] / zypp / DiskUsageCounter.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/DiskUsageCounter.h
10  *
11 */
12 #ifndef ZYPP_DISKUSAGE_COUNTER_H
13 #define ZYPP_DISKUSAGE_COUNTER_H
14
15 #include <zypp/ResPool.h>
16
17 #include <set>
18 #include <string>
19 #include <iostream>
20
21 ///////////////////////////////////////////////////////////////////
22 namespace zypp
23 { /////////////////////////////////////////////////////////////////
24
25   class DiskUsageCounter
26   {
27
28   public:
29
30     /**
31     * @short Mount point description
32     **/
33     struct MountPoint
34     {
35       /**
36        * Directory name
37        **/
38       std::string dir;
39
40       /**
41        * Block size of the mount point
42        **/
43       long long block_size;       
44
45       /**
46        * Total size in kB (1024)
47        **/
48       long long total_size;
49
50       /**
51        * Used size in kB (1024)
52        **/
53       long long used_size;
54
55       /**
56        * Used size after commiting the pool (in kB)
57        **/
58       mutable long long pkg_size;
59
60       bool readonly;
61
62       /**
63        * Ctor - initialize directory and package size
64        **/
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) {}
67
68       // sort by directory name
69       bool operator<( const MountPoint & rhs ) const
70       {
71         return dir < rhs.dir;
72       }
73     };
74
75     typedef std::set<MountPoint> MountPointSet;
76
77     DiskUsageCounter() {}
78
79     bool setMountPoints(const MountPointSet &m)
80     {
81         mps = m;
82         return true;
83     }
84
85     MountPointSet getMountPoints()
86     {
87         return mps;
88     }
89
90     static MountPointSet detectMountPoints(const std::string &rootdir = "/");
91
92     /**
93      * Compute disk usage of the pool
94      **/
95     MountPointSet disk_usage(const ResPool &pool);
96
97   private:
98
99     MountPointSet mps;
100   };
101   ///////////////////////////////////////////////////////////////////
102   /////////////////////////////////////////////////////////////////
103 } // namespace zypp
104 ///////////////////////////////////////////////////////////////////
105 #endif // ZYPP_DISKUSAGE_COUNTER_H