Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / Package.cc
index c73f2f1..5916f4b 100644 (file)
 using namespace std;
 
 ///////////////////////////////////////////////////////////////////
-namespace zyppintern
-{
-  using namespace zypp;
-
-  inline bool schemeIsLocalDir( const Url & url_r )
-  {
-      const std::string & s( url_r.getScheme() );
-      return s == "dir" || s == "file";
-  }
-
-  // here and from SrcPackage.cc
-  Pathname cachedLocation( const OnMediaLocation & loc_r, const RepoInfo & repo_r )
-  {
-    PathInfo pi( repo_r.packagesPath() / loc_r.filename() );
-
-    if ( ! pi.isExist() )
-      return Pathname();       // no file in cache
-
-    if ( loc_r.checksum().empty() )
-    {
-      Url url( repo_r.url() );
-      if ( ! schemeIsLocalDir( url ) )
-       return Pathname();      // same name but no checksum to verify
-
-      // for local repos compare with the checksum in repo
-      if ( CheckSum( CheckSum::md5Type(), std::ifstream( (url.getPathName() / loc_r.filename()).c_str() ) )
-       != CheckSum( CheckSum::md5Type(), std::ifstream( pi.c_str() ) ) )
-       return Pathname();      // same name but wrong checksum
-    }
-    else
-    {
-      if ( loc_r.checksum() != CheckSum( loc_r.checksum().type(), std::ifstream( pi.c_str() ) ) )
-       return Pathname();      // same name but wrong checksum
-    }
-
-    return pi.path();          // the right one
-  }
-} // namespace zyppintern
-///////////////////////////////////////////////////////////////////
-
-///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
@@ -127,10 +86,14 @@ namespace zypp
 
   bool Package::maybeUnsupported() const
   {
-    static const VendorSupportOptions unsupportedOpts( VendorSupportUnknown
-                                                    | VendorSupportUnsupported
-                                                    | VendorSupportACC );
-    return unsupportedOpts.testFlag( vendorSupport() );
+    switch ( vendorSupport() )
+    {
+      case VendorSupportUnknown:
+      case VendorSupportUnsupported:
+      case VendorSupportACC:
+       return true;
+    }
+    return false;
   }
 
   Changelog Package::changelog() const
@@ -192,8 +155,42 @@ namespace zypp
   OnMediaLocation Package::location() const
   { return lookupLocation(); }
 
+  namespace
+  {
+    bool schemeIsLocalDir( const Url & url_r )
+    {
+      std::string s( url_r.getScheme() );
+      return s == "dir" || s == "file";
+    }
+  }
+
   Pathname Package::cachedLocation() const
-  { return zyppintern::cachedLocation( location(), repoInfo() ); }
+  {
+    OnMediaLocation loc( location() );
+    PathInfo pi( repoInfo().packagesPath() / loc.filename() );
+
+    if ( ! pi.isExist() )
+      return Pathname();       // no file in cache
+
+    if ( loc.checksum().empty() )
+    {
+      Url url( repoInfo().url() );
+      if ( ! schemeIsLocalDir( url ) )
+       return Pathname();      // same name but no checksum to verify
+
+      // for local repos compare with the checksum in repo
+      if ( CheckSum( CheckSum::md5Type(), std::ifstream( (url.getPathName() / loc.filename()).c_str() ) )
+       != CheckSum( CheckSum::md5Type(), std::ifstream( pi.c_str() ) ) )
+       return Pathname();      // same name but wrong checksum
+    }
+    else
+    {
+      if ( loc.checksum() != CheckSum( loc.checksum().type(), std::ifstream( pi.c_str() ) ) )
+       return Pathname();      // same name but wrong checksum
+    }
+
+    return pi.path();          // the right one
+  }
 
   std::string Package::sourcePkgName() const
   {