added disk usage data to PackageImplIf interface, provide this info from
[platform/upstream/libzypp.git] / zypp / detail / PackageImplIf.cc
index 2acbe55..baa76ee 100644 (file)
@@ -10,6 +10,9 @@
  *
 */
 #include "zypp/detail/PackageImplIf.h"
+#include <iostream>
+
+using namespace std;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -68,11 +71,11 @@ namespace zypp
       std::list<std::string> PackageImplIf::postun() const
       { return std::list<std::string>(); }
 
-      FSize PackageImplIf::sourcesize() const
-      { return FSize(); }
+      ByteCount PackageImplIf::sourcesize() const
+      { return ByteCount(); }
 
-      FSize PackageImplIf::archivesize() const
-      { return FSize(); }
+      ByteCount PackageImplIf::archivesize() const
+      { return ByteCount(); }
 
       std::list<std::string> PackageImplIf::authors() const
       { return std::list<std::string>(); }
@@ -83,6 +86,43 @@ namespace zypp
       License PackageImplIf::licenseToConfirm() const
       { return License(); }
 
+      // disk usage class methods
+
+      std::ostream & operator<<( std::ostream & str, const PackageImplIf::DiskUsage::Entry & obj )
+      {
+        return str << obj.path << '\t' << obj._size << "; files " << obj.files;
+      }
+
+      PackageImplIf::DiskUsage::Entry PackageImplIf::DiskUsage::extract( const std::string & dirname_r )
+      {
+        Entry ret( dirname_r );
+      
+        iterator fst = begin();
+        for ( ; fst != end() && !fst->isBelow( ret ); ++fst )
+          ; // seek 1st equal or below
+      
+        if ( fst != end() ) {
+          iterator lst = fst;
+          for ( ; lst != end() && lst->isBelow( ret ); ++lst ) {
+            // collect while below
+            ret += *lst;
+          }
+          // remove
+          _dirs.erase( fst, lst );
+        }
+      
+        return ret;
+      }
+
+      std::ostream & operator<<( std::ostream & str, const PackageImplIf::DiskUsage & obj )
+      {
+        str << "Package Disk Usage {" << endl;
+        for ( PackageImplIf::DiskUsage::EntrySet::const_iterator it = obj._dirs.begin(); it != obj._dirs.end(); ++it ) {
+          str << "   " << *it << endl;
+        }
+        return str << "}";
+      }
+
     /////////////////////////////////////////////////////////////////
   } // namespace detail
   ///////////////////////////////////////////////////////////////////