only lock if we are running as root
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 24 Mar 2006 16:35:31 +0000 (16:35 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 24 Mar 2006 16:35:31 +0000 (16:35 +0000)
zypp/CheckSum.h
zypp/ZYppFactory.cc
zypp/source/susetags/ProductMetadataParser.cc
zypp/source/susetags/ProductMetadataParser.h
zypp/source/susetags/SuseTagsProductImpl.h

index 5b3bd24..cd9873c 100644 (file)
@@ -12,6 +12,8 @@
 #ifndef ZYPP_CHECKSUM_H
 #define ZYPP_CHECKSUM_H
 
+#include <string>
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -23,8 +25,14 @@ namespace zypp
     : _type(type)
     , _checksum(checksum)
     {}
-    std::string type() { return _type; }
-    std::string checksum() { return _checksum; }
+    
+    CheckSum()
+    {}
+    
+    std::string type() const 
+    { return _type; } 
+    std::string checksum() const  
+    { return _checksum; } 
   private:
     std::string _type;
     std::string _checksum;
index bd52133..b8d9d64 100644 (file)
@@ -71,7 +71,7 @@ namespace zypp
       Pathname lock_file = Pathname(ZYPP_LOCK_FILE);
       _zypp_lockfile = fopen(lock_file.asString().c_str(), mode);
       if (_zypp_lockfile == 0)
-        ZYPP_THROW (Exception( "Cant open " + lock_file.asString() ) );
+        ZYPP_THROW (Exception( "Cant open " + lock_file.asString() + " in mode " + std::string(mode) ) );
     }
   
     void closeLockFile()
@@ -169,43 +169,59 @@ namespace zypp
         if ( locker_pid == curr_pid )
         {
         // alles ok, we are requesting the instance again
-          MIL << "Lockfile found, but it is myself. Assuming same process getting zypp instance again." << std::endl;
+          //MIL << "Lockfile found, but it is myself. Assuming same process getting zypp instance again." << std::endl;
           return false;
         }
         else
         {
           if ( isProcessRunning(locker_pid) )
           {
-            MIL << locker_pid << " is running and has a ZYpp lock. Sorry" << std::endl;
-            return true;
-          }
-          else
-          {
-            MIL << locker_pid << " has a ZYpp lock, but process is not running. Cleaning lock file." << std::endl;
-            if ( filesystem::unlink(lock_file) == 0 )
+            if ( geteuid() == 0 )
             {
-              createLockFile();
-            // now open it for reading
-              openLockFile("r");
-              shLockFile();
-              return false;
+              // i am root
+              MIL << locker_pid << " is running and has a ZYpp lock. Sorry" << std::endl;
+              return true;
             }
             else
             {
-              ERR << "Can't clean lockfile. Sorry, can't create a new lock. Zypp still locked." << std::endl;
-              return true;
+              MIL << locker_pid << " is running and has a ZYpp lock. Access as normal user allowed." << std::endl;
+              return false;
+            }
+          }
+          else
+          {
+            if ( geteuid() == 0 )
+            {
+              MIL << locker_pid << " has a ZYpp lock, but process is not running. Cleaning lock file." << std::endl;
+              if ( filesystem::unlink(lock_file) == 0 )
+              {
+                createLockFile();
+              // now open it for reading
+                openLockFile("r");
+                shLockFile();
+                return false;
+              }
+              else
+              {
+                ERR << "Can't clean lockfile. Sorry, can't create a new lock. Zypp still locked." << std::endl;
+                return true;
+              }
             }
           }
         }
       }
       else
       {
-        createLockFile();
-      // now open it for reading
-        openLockFile("r");
-        shLockFile();
+        if ( geteuid() == 0 )
+        {
+          createLockFile();
+        // now open it for reading
+          openLockFile("r");
+          shLockFile();
+        }
         return false;
       }
+      return true;
     }
     
   };
@@ -250,11 +266,24 @@ namespace zypp
   //
   ZYpp::Ptr ZYppFactory::getZYpp() const
   {
-    static ZYpp::Ptr _instance( new ZYpp( ZYpp::Impl_Ptr(new ZYpp::Impl) ) );
-    if ( globalLock.zyppLocked() )
-      return 0;
-    else
+    static ZYpp::Ptr _instance;   
+    
+    if ( _instance )
+    {
       return _instance;
+    }
+    else
+    {
+      if ( globalLock.zyppLocked() )
+      {
+        return 0;
+      }
+      else
+      {
+        _instance = new ZYpp( ZYpp::Impl_Ptr(new ZYpp::Impl) );
+        return _instance;
+      }
+    }
   }
 
   /******************************************************************
index cf8549d..8ba9c5e 100644 (file)
@@ -128,6 +128,8 @@ namespace zypp
               prodImpl->_language = value;
             else if(key == "TIMEZONE")
               prodImpl->_timezone = value;
+            else if(key == "META")
+              parseFileCheckSum( key, value, prodImpl->_descr_files_checksums);
             else
               DBG << "parse error" << std::endl;
           }
@@ -233,6 +235,26 @@ namespace zypp
          }
       }
 
+      void ProductMetadataParser::parseFileCheckSum( const std::string &key, const std::string &value, std::map<std::string, CheckSum> &container)
+      {
+        std::list<std::string> splitted;
+        str::split( value, std::back_inserter(splitted), " ");
+        if (splitted.size() != 3)
+        {
+          ERR << "Parse error in checksum. Expected [type checksum file], got [" << value << "]" << std::endl;
+        }
+        else
+        {
+          std::string checksum_type = splitted.front();
+          splitted.pop_front();
+          std::string checksum_str = splitted.front();
+          splitted.pop_front();
+          std::string filename = splitted.front();
+          splitted.pop_front();
+          MIL << "Checksum for " << filename << " is " << checksum_str << " (" << checksum_type << ")" << std::endl;
+          container[filename] = CheckSum(checksum_type, checksum_str);
+        }
+      }
       /////////////////////////////////////////////////////////////////
     } // namespace susetags
     ///////////////////////////////////////////////////////////////////
index fbf5888..79071c7 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "zypp/parser/tagfile/ParseException.h"
 
+#include "zypp/CheckSum.h"
 #include "zypp/Pathname.h"
 #include "zypp/Product.h"
 #include "zypp/source/susetags/SuseTagsProductImpl.h"
@@ -69,6 +70,9 @@ namespace zypp
          * REQUIRES line
          */
         void parseRequires( const std::string &key, const std::string &value, zypp::CapSet &container);
+        
+        void parseFileCheckSum( const std::string &key, const std::string &value, std::map<std::string, CheckSum> &container);
+        
       };
       ///////////////////////////////////////////////////////////////////
 
index 6e4737a..e24d33c 100644 (file)
@@ -12,6 +12,9 @@
 #ifndef ZYPP_DETAIL_SUSETAGS_PRODUCTIMPL_H
 #define ZYPP_DETAIL_SUSETAGS_PRODUCTIMPL_H
 
+#include <map>
+
+#include "zypp/CheckSum.h"
 #include "zypp/CapSet.h"
 #include "zypp/detail/ProductImplIf.h"
 #include "zypp/Source.h"
@@ -69,7 +72,10 @@ namespace zypp
       std::string _language;
       std::string _timezone;
       
+      std::map<std::string, CheckSum> _descr_files_checksums;
+      
       Source_Ref _source;
+     
     };
     ///////////////////////////////////////////////////////////////////