Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / HistoryLog.cc
index 310a4e9..5f1a8fd 100644 (file)
@@ -16,7 +16,6 @@
 #include "zypp/ZConfig.h"
 #include "zypp/base/String.h"
 #include "zypp/base/Logger.h"
-#include "zypp/base/IOStream.h"
 
 #include "zypp/PathInfo.h"
 #include "zypp/Date.h"
 using std::endl;
 using std::string;
 
-namespace zypp
+namespace
 {
-  namespace
-  {
-    inline string timestamp()
-    { return zypp::Date::now().form( HISTORY_LOG_DATE_FORMAT ); }
+  inline string timestamp()
+  { return zypp::Date::now().form( HISTORY_LOG_DATE_FORMAT ); }
 
-    inline string userAtHostname()
+  inline string userAtHostname()
+  {
+    static char buf[256];
+    string result;
+    char * tmp = ::cuserid(buf);
+    if (tmp)
     {
-      static char buf[256];
-      string result;
-      char * tmp = ::cuserid(buf);
-      if (tmp)
-      {
-       result = string(tmp);
-       if (!::gethostname(buf, 255))
-         result += "@" + string(buf);
-      }
-      return result;
+      result = string(tmp);
+      if (!::gethostname(buf, 255))
+        result += "@" + string(buf);
     }
+    return result;
+  }
 
-    static std::string pidAndAppname()
+  static std::string pidAndAppname()
+  {
+    static std::string _val;
+    if ( _val.empty() )
     {
-      static std::string _val;
-      if ( _val.empty() )
-      {
-       pid_t mypid = getpid();
-       zypp::Pathname p( "/proc/"+zypp::str::numstring(mypid)+"/exe" );
-       zypp::Pathname myname( zypp::filesystem::readlink( p ) );
-
-       _val += zypp::str::numstring(mypid);
-       _val += ":";
-       _val += myname.basename();
-      }
-      return _val;
-    }
+      pid_t mypid = getpid();
+      zypp::Pathname p( "/proc/"+zypp::str::numstring(mypid)+"/exe" );
+      zypp::Pathname myname( zypp::filesystem::readlink( p ) );
 
-    static std::string cmdline()
-    {
-      static std::string _val;
-      if ( _val.empty() )
-      {
-       pid_t mypid = getpid();
-       {
-         std::ifstream cmdlineStr( Pathname("/proc/"+zypp::str::numstring(mypid)+"/cmdline").c_str() );
-         char ch;
-         const char * sep = "'";
-         while ( cmdlineStr && cmdlineStr.get( ch ) )
-         {
-           if ( sep )
-           {
-             _val += sep;
-             sep = nullptr;
-           }
-           switch ( ch )
-           {
-             case '\0':        _val += '\''; sep = " '"; break;
-             case '\n':        _val += ' '; break;
-             case '\\':        _val += '\\'; _val += '\\'; break;
-             case '|':         _val += '\\'; _val += '|'; break;
-             default:          _val += ch; break;
-           }
-         }
-       }
-      }
-      return _val;
+      _val += zypp::str::numstring(mypid);
+      _val += ":";
+      _val += myname.basename();
     }
-  } // namespace
+    return _val;
+  }
+}
 
+namespace zypp
+{
   namespace
   {
     const char         _sep = '|';
@@ -141,7 +109,7 @@ namespace zypp
       if ( !_refcnt )
         closeLog();
     }
-  } // namespace
+  }
 
   ///////////////////////////////////////////////////////////////////
   //
@@ -185,14 +153,14 @@ namespace zypp
 
   /////////////////////////////////////////////////////////////////////////
 
-  void HistoryLog::comment( const string & comment, bool timestamp_r )
+  void HistoryLog::comment( const string & comment, bool timestamp )
   {
     if (comment.empty())
       return;
 
     _log << "# ";
-    if ( timestamp_r )
-      _log << timestamp() << " ";
+    if ( timestamp )
+      _log << ::timestamp() << " ";
 
     const char * s = comment.c_str();
     const char * c = s;
@@ -217,18 +185,6 @@ namespace zypp
 
   /////////////////////////////////////////////////////////////////////////
 
-  void HistoryLog::stampCommand()
-  {
-    _log
-      << timestamp()                                                   // 1 timestamp
-      << _sep << HistoryActionID::STAMP_COMMAND.asString(true)         // 2 action
-      << _sep << userAtHostname()                                      // 3 requested by
-      << _sep << cmdline()                                             // 4 command
-      << _sep << str::escape(ZConfig::instance().userData(), _sep)     // 6 userdata
-      << endl;
-
-  }
-
   void HistoryLog::install( const PoolItem & pi )
   {
     const Package::constPtr p = asKind<Package>(pi.resolvable());
@@ -244,7 +200,7 @@ namespace zypp
 
     // ApplLow is what the solver selected on behalf of the user.
     if (pi.status().isByUser() || pi.status().isByApplLow() )
-      _log << _sep << userAtHostname();                                        // 6 requested by
+      _log << _sep << userAtHostname();                                        // 6 reqested by
     else if (pi.status().isByApplHigh())
       _log << _sep << pidAndAppname();
     else
@@ -273,7 +229,7 @@ namespace zypp
 
     // ApplLow is what the solver selected on behalf of the user.
     if ( pi.status().isByUser() || pi.status().isByApplLow() )
-      _log << _sep << userAtHostname();                                        // 6 requested by
+      _log << _sep << userAtHostname();                                        // 6 reqested by
     else if (pi.status().isByApplHigh())
       _log << _sep << pidAndAppname();
     else