Commits

a4z  committed d027b15

sumary for new cache changed, some draft code in trial

  • Participants
  • Parent commits fbb2341

Comments (0)

Files changed (5)

File src/cli/appcli.cpp

 namespace {
 bool
 prepairCache(bool syncflag)
-{
+{ // TODO name this nosync ? or add docu other wise its always hard to read first time comming here
+  bool chache_was_new{false};
   if( Cache::get().DB().isNew() )
     {
       if( syncflag )
           LogInfo() << "Cache is new, overrule nosync\n";
           syncflag = false;
         }
+      chache_was_new = true;
     }
 
   try // TODO in new implementation this will be automatically called at open db
     {
       try
         {
-          cli::printSyncReport( Cache::get().doSync() );
+          cli::printSyncReport( Cache::get().doSync(), chache_was_new );
         }
       catch (const Error& e)
         {
 
   Path querypath( appargs.getQuery() );
 
+
+  if(appargs.getFeatureX())
+    {
+      sbbdep::cli::runFx() ;
+      return 0  ;
+    }
+
+
   if( querypath.isEmpty() )
     return 0; // was a sync only call ....
 
       LogError() << "Unknown error" << std::endl;
       return -4;
     }
-  if(appargs.getFeatureX())
-    {
-      sbbdep::cli::runFx() ;
-      return 0  ;
-    }
 
 
   if( appargs.getWhoNeeds() )

File src/cli/featurex.cpp

 
 #include "featurex.hpp"
 
-#include <sbbdep/lddmap.hpp>
-#include <sbbdep/cache.hpp>
 #include <sbbdep/log.hpp>
 
-
 #include <a4sqlt3/sqlcommand.hpp>
 #include <a4sqlt3/dataset.hpp>
+#include <a4sqlt3/dbvalue.hpp>
 
+#include <iostream>
+#include <map>
+#include <memory>
+#include <algorithm>
+#include <functional>
 
-namespace sbbdep {
-namespace cli{
 
-namespace {
-  using StingMap = std::map<std::string, std::string> ;
+std::ostream&
+operator<<(std::ostream& stm, const a4sqlt3::DbValue& v)
+{
+
+  using namespace a4sqlt3 ;
+  switch( v.getStorageType() )
+    {
+
+    case DbValueType::Null:
+      stm << "<NULL>" ;
+      break ;
+
+    case DbValueType::Int64:
+      stm << v.getInt64() ;
+      break ;
+
+    case DbValueType::Real:
+      stm << v.getDouble() ;
+      break ;
+
+    case DbValueType::Text:
+      stm << v.getString() ;
+      break ;
+
+    case DbValueType::Blob:
+      stm << "<BLOB>" ;
+      break ;
+    default:
+      stm << "unknown storage type !!" ;
+      break ;
+    }
+
+  return stm ;
 }
 
+namespace sbbdep
+{
+namespace cli
+{
 
-
-void runFx()
+namespace
 {
-  
-
-  LogInfo() << " internal test function " << __PRETTY_FUNCTION__ << "\n";
-
-#ifndef DEBUG
-  LogInfo() << "not enabled in non debug builds\n";
-  return;
-#endif
-
-  using namespace a4sqlt3;
-  Dataset rs_cnt, rs_files ;
-
-  Cache::get().DB().Execute("SELECT COUNT(*) FROM dynlinked;", rs_cnt);
-
-  Cache::get().DB().Execute("SELECT filename FROM dynlinked;", rs_files);
-
-  int counter = 0;
-  for(auto& row : rs_files)
-    {
-      StingMap ldmap = getLddMap( row.getField(0).getString() )  ;
-      LogDebug() << counter << " from " << rs_cnt.getField(0).getInt64() << " - " << ldmap.size() <<   "\n";
-      counter++;
-    }
-
 
 }
 
+using namespace a4sqlt3 ;
+
+struct HRowSet
+{
+  std::map<std::string, int> names ;
+
+  struct Row
+  {
+    Row()
+        : childs(new HRowSet())
+    {
+    }
+    Row(DbValueList flds)
+        : childs(new HRowSet()),
+          fields
+            {std::move(flds)}
+    {
+    }
+
+    std::unique_ptr<HRowSet> childs ;
+
+    DbValueList fields ;
+
+  } ;
+
+  std::vector<Row> rows ;
+
+  int
+  field(const std::string name)
+  {
+    auto fi = names.find(name) ;
+    if( fi == std::end(names) )
+      throw "TODO" ;
+
+    return fi->second ;
+  }
+} ;
+
+void
+printHRow(const HRowSet& rs, int level = 0)
+{
+
+  std::string indent("..", level) ;
+  for( const auto& row : rs.rows )
+    {
+      std::cout << indent ;
+      for( const auto& f : row.fields )
+        {
+          std::cout << f << " / " ;
+        }
+      std::cout << std::endl ;
+
+      printHRow(*row.childs, level + 1) ;
+
+//      for(const auto& r : row.childs->rows)
+//        {
+//          printHRow(r, level+1);
+//        }
+
+    }
+
+}
+
+//-------------------------------------------------------------------------------------------------
+struct HRow
+{
+  HRow()
+  {
+  }
+  HRow(DbValueList flds)
+      : fields{std::move(flds)}
+  {
+  }
+
+  DbValueList fields ;
+
+  std::vector<HRow> childs ;
+
+} ;
+
+void
+printHRow(const HRow& hr, int level = 0)
+{
+  std::string indent("..", level) ;
+
+  std::cout << indent ;
+  for( const auto& f : hr.fields )
+    {
+      std::cout << f << " / " ;
+    }
+  std::cout << std::endl ;
+
+  for( const auto& r : hr.childs )
+    {
+      printHRow(r, level + 1) ;
+    }
+
+}
+//-------------------------------------------------------------------------------------------------
+
+void
+runFx()
+{
   
-}} // ns
+  LogInfo() << " internal test function " << __PRETTY_FUNCTION__ << "\n" ;
+
+#ifndef DEBUG
+  LogInfo() << "not enabled in non debug builds\n" ;
+  return ;
+#endif
+/*
+    {
+      HRowSet rs ;
+
+      rs.rows.push_back(HRowSet::Row
+        {
+          {DbValue(1), DbValue("eins")}}) ;
+
+      HRowSet& childs = *rs.rows.rbegin()->childs ;
+      childs.rows.push_back(
+          HRowSet::Row{{DbValue("eins"), DbValue("eins")}}
+      ) ;
+      childs.rows.push_back(
+          HRowSet::Row{{DbValue("eins"), DbValue("zwei")}}
+      ) ;
+
+      printHRow(rs) ;
+    }
+
+    {
+      HRow r ;
+
+      r.fields =
+        { DbValue(1), DbValue("eins")} ;
+
+      r.childs.push_back(HRow(
+        {DbValue("eins"), DbValue("eins")})) ;
+      r.childs.push_back(HRow(
+        {DbValue("eins"), DbValue("zwei")})) ;
+
+      printHRow(r) ;
+
+    }
+*/
+
+    const std::string cmd = "/sbin/ldconfig -p";
+    FILE* popin = popen(cmd.c_str(), "r");
+    if( popin )
+      {
+        char buff[512];
+        while (std::fgets(buff, sizeof( buff ), popin) != NULL)
+          {
+            const char* buff_start = buff;
+            const char* buff_end = buff + sizeof( buff ) ;
+
+            const char* soname_begin = std::find_if( buff_start,  buff_end,
+                [](const char c)->bool{ return c != '\t' ; }
+                );
+
+            const char* soname_end = std::find_if( soname_begin,  buff_end,
+                [](const char c)->bool{ return c == ' '; }
+            );
+
+            // TODO if anything is end, exit with a message of problem line
+
+            const std::string arrow = "=> ";
+
+            const char* file_begin = std::search( soname_end, buff_end,
+                std::begin(arrow), std::end(arrow)) + arrow.size();
+
+            const std::string lineend = "\n";
+            const char* file_end = std::search( file_begin, buff_end,
+                std::begin(lineend), std::end(lineend)) ;
+
+            std::cout << "here: '" << std::string(soname_begin, soname_end) << "'" ;
+            if(file_end != buff_end)
+              std::cout << " to '" << std::string(file_begin, file_end) << "'" ;
+
+            std::cout << std::endl ;
+
+          }
+
+
+        pclose(popin);
+      }
+
+
+}
+
+}
+} // ns

File src/cli/report_sync.cpp

 //--------------------------------------------------------------------------------------------------
 
 
-void printSyncReport(Cache::SyncData syncdata)
+void printSyncReport(Cache::SyncData syncdata, bool chache_was_new)
 {
+
+  if(chache_was_new)
+    {
+      LogInfo()  << "\n new cache created, "
+          << syncdata.installed.size()
+          << " packages indexed."
+          << std::endl;
+      return;
+    }
+
   using StringSet = std::set<std::string> ; //make it sortd
 
   StringSet deleted, reinstalled, installed, upgraded;
 
-
   // take removed, than check inserted, if inserted is also in deleted, its an update
   deleted.insert(syncdata.removed.begin(),syncdata.removed.end() );
   // so make all inserted to deleted,

File src/cli/report_sync.hpp

 namespace cli{
 
 
-void printSyncReport(Cache::SyncData syncdata) ;
+void printSyncReport(Cache::SyncData syncdata, bool chache_was_new) ;
 
 
 

File src/sbbdep/lddirs.cpp

   if(Path("/lib64").isFolder() )m_lddirs.insert("/lib64");
   m_lddirs.insert("/usr/lib");
   if(Path("/usr/lib64").isFolder() )m_lddirs.insert("/usr/lib64");
-  
-  
-  std::string line;
+
   std::ifstream ldso_conf("/etc/ld.so.conf");
 
-  if (ldso_conf.is_open())
+  if( ldso_conf.is_open() )
     {
-      while (ldso_conf.good())
+      for( std::string line ; std::getline(ldso_conf, line) ; )
         {
-          std::getline(ldso_conf, line);
-          std::size_t commentpos = line.find_first_of("#");
-          if( commentpos!=std::string::npos ) line.erase(commentpos);
+          std::size_t commentpos = line.find_first_of("#") ;
+          if( commentpos != std::string::npos )
+            line.erase(commentpos) ;
           std::string dirname = boost::algorithm::trim_copy(line) ;
           if( dirname.size() )
             { //  folder path could also be a link
-              Path p(dirname);
-              p.makeRealPath();
+              Path p(dirname) ;
+              p.makeRealPath() ;
               if( p.isFolder() )
                 m_lddirs.insert(p.getURL()) ;
             }
         }
     }
-  else 
+  else
     {
-      throw ErrGeneric("unable to read /etc/ld.so.conf");
+      throw ErrGeneric("unable to read /etc/ld.so.conf") ;
     }
   
   
               std::string orig = path.Str();
               path.makeRealPath();
               if (path.isRegularFile() && isElfLib( path ) )
-                { // filter out what is a regular ld dir
+                { // filter out what is a regular ld dir , TODO since this is a set lookup not reuqired
                   if(m_lddirs.find(path.getDir())== m_lddirs.end())
                     m_ldlnkdirs.insert(path.getDir());
 
+                  // TODO , why did I do this ? only for debug ??
                   if(path.getDir()=="/usr/bin" || path.getDir()=="/usr/sbin")
                     LogInfo()<<"in bin: " << orig << "->" << path.getURL() << std::endl;
                 }