Imported Upstream version 17.13.0 upstream/17.13.0
authorDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 2 Sep 2019 07:19:36 +0000 (16:19 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Mon, 2 Sep 2019 07:19:36 +0000 (16:19 +0900)
41 files changed:
CMakeLists.txt
VERSION.cmake
cmake/modules/FindDbus.cmake [deleted file]
cmake/modules/FindHal.cmake [deleted file]
libzypp.spec.cmake
package/libzypp.changes
tests/zypp/CMakeLists.txt
tests/zypp/RpmPkgSigCheck_test.cc [new file with mode: 0644]
tests/zypp/data/RpmPkgSigCheck/no.rpm [new file with mode: 0644]
tests/zypp/data/RpmPkgSigCheck/signed.key [new file with mode: 0644]
tests/zypp/data/RpmPkgSigCheck/signed.rpm [new file with mode: 0644]
tests/zypp/data/RpmPkgSigCheck/signed_broken.rpm [new file with mode: 0644]
tests/zypp/data/RpmPkgSigCheck/signed_broken_header.rpm [new file with mode: 0644]
tests/zypp/data/RpmPkgSigCheck/unsigned.rpm [new file with mode: 0644]
tests/zypp/data/RpmPkgSigCheck/unsigned_broken.rpm [new file with mode: 0644]
tests/zypp/data/RpmPkgSigCheck/unsigned_broken_header.rpm [new file with mode: 0644]
zypp/AutoDispose.h
zypp/CMakeLists.txt
zypp/KeyManager.cc
zypp/KeyManager.h
zypp/KeyRing.cc
zypp/MediaSetAccess.cc
zypp/PublicKey.cc
zypp/RepoManager.cc
zypp/base/Fd.cc [deleted file]
zypp/base/Fd.h [deleted file]
zypp/media/MediaCD.cc
zypp/media/MediaCurl.cc
zypp/media/MediaManager.cc
zypp/media/MediaManager.h
zypp/media/MediaMultiCurl.cc
zypp/target/TargetImpl.cc
zypp/target/hal/HalContext.cc [deleted file]
zypp/target/hal/HalContext.h [deleted file]
zypp/target/hal/HalException.h [deleted file]
zypp/target/rpm/librpmDb.cc
zypp/thread/Mutex.cc [deleted file]
zypp/thread/Mutex.h [deleted file]
zypp/thread/MutexException.h [deleted file]
zypp/thread/MutexLock.h [deleted file]
zypp/thread/Once.h [deleted file]

index e5fc2e7..ff17324 100644 (file)
@@ -192,20 +192,7 @@ FIND_PACKAGE(OpenSSL REQUIRED)
 
 FIND_PACKAGE(Udev)
 IF ( NOT UDEV_FOUND )
-  FIND_PACKAGE(Hal)
-  IF ( NOT HAL_FOUND )
-    MESSAGE(WARNING "No udev or HAL. CD device detection will be poor")
-  ELSE ( NOT HAL_FOUND )
-      ADD_DEFINITIONS(-DHAVE_HAL)
-      INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR})
-      INCLUDE_DIRECTORIES(${HAL_INCLUDE_DIR}/hal)
-      # HAL requires working dbus
-      FIND_PACKAGE(Dbus REQUIRED)
-      IF(DBUS_FOUND)
-        INCLUDE_DIRECTORIES(${DBUS_INCLUDE_DIR})
-        INCLUDE_DIRECTORIES(${DBUS_ARCH_INCLUDE_DIR})
-      ENDIF(DBUS_FOUND)
-  ENDIF ( NOT HAL_FOUND )
+  MESSAGE(WARNING "No udev found. CD device detection will be poor")
 ELSE ( NOT UDEV_FOUND )
   ADD_DEFINITIONS(-DHAVE_UDEV)
 ENDIF ( NOT UDEV_FOUND )
index 6115a73..33e3da1 100644 (file)
@@ -60,9 +60,9 @@
 #
 SET(LIBZYPP_MAJOR "17")
 SET(LIBZYPP_COMPATMINOR "12")
-SET(LIBZYPP_MINOR "12")
+SET(LIBZYPP_MINOR "13")
 SET(LIBZYPP_PATCH "0")
 #
-# LAST RELEASED: 17.12.0 (12)
+# LAST RELEASED: 17.13.0 (12)
 # (The number in parenthesis is LIBZYPP_COMPATMINOR)
 #=======
diff --git a/cmake/modules/FindDbus.cmake b/cmake/modules/FindDbus.cmake
deleted file mode 100644 (file)
index d79cd9a..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-
-if(DBUS_INCLUDE_DIR AND DBUS_LIBRARY AND DBUS_ARCH_INCLUDE_DIR)
-       # Already in cache, be silent
-       set(DBUS_FIND_QUIETLY TRUE)     
-endif(DBUS_INCLUDE_DIR AND DBUS_LIBRARY AND DBUS_ARCH_INCLUDE_DIR)
-
-set(DBUS_LIBRARY)
-set(DBUS_INCLUDE_DIR)
-set(DBUS_ARCH_INCLUDE_DIR)
-
-FIND_PATH(DBUS_INCLUDE_DIR dbus/dbus.h
-       /usr/include
-       /usr/include/dbus-1.0
-       /usr/local/include
-)
-
-FIND_PATH(DBUS_ARCH_INCLUDE_DIR dbus/dbus-arch-deps.h
-       /usr/lib/include
-       /usr/lib/dbus-1.0/include
-  /usr/lib64/include
-  /usr/lib64/dbus-1.0/include
-)
-
-FIND_LIBRARY(DBUS_LIBRARY NAMES dbus-1 dbus
-       PATHS
-       /usr/lib
-       /usr/local/lib
-)
-
-if(DBUS_INCLUDE_DIR AND DBUS_LIBRARY AND DBUS_ARCH_INCLUDE_DIR)
-   MESSAGE( STATUS "dbus found: includes in ${DBUS_INCLUDE_DIR}, library in ${DBUS_LIBRARY}")
-   set(DBUS_FOUND TRUE)
-else(DBUS_INCLUDE_DIR AND DBUS_LIBRARY AND DBUS_ARCH_INCLUDE_DIR)
-   MESSAGE( STATUS "dbus not found")
-endif(DBUS_INCLUDE_DIR AND DBUS_LIBRARY AND DBUS_ARCH_INCLUDE_DIR)
-
-MARK_AS_ADVANCED(DBUS_INCLUDE_DIR DBUS_LIBRARY DBUS_ARCH_INCLUDE_DIR)
\ No newline at end of file
diff --git a/cmake/modules/FindHal.cmake b/cmake/modules/FindHal.cmake
deleted file mode 100644 (file)
index 58c149a..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-
-if(HAL_INCLUDE_DIR AND HAL_LIBRARY AND HAL_STORAGE_LIBRARY)
-       # Already in cache, be silent
-       set(HAL_FIND_QUIETLY TRUE)      
-endif(HAL_INCLUDE_DIR AND HAL_LIBRARY AND HAL_STORAGE_LIBRARY)
-
-set(HAL_LIBRARY)
-set(HAL_INCLUDE_DIR)
-set(HAL_STORAGE_LIBRARY)
-
-FIND_PATH(HAL_INCLUDE_DIR hal/libhal.h
-       /usr/include
-       /usr/local/include
-)
-
-FIND_LIBRARY(HAL_LIBRARY NAMES hal
-       PATHS
-       /usr/lib
-       /usr/local/lib
-)
-
-FIND_LIBRARY(HAL_STORAGE_LIBRARY NAMES hal-storage
-       PATHS
-       /usr/lib
-       /usr/local/lib
-)
-
-if(HAL_INCLUDE_DIR AND HAL_LIBRARY AND HAL_STORAGE_LIBRARY)
-   MESSAGE( STATUS "hal found: includes in ${HAL_INCLUDE_DIR}, library in ${HAL_LIBRARY}")
-   set(HAL_FOUND TRUE)
-else(HAL_INCLUDE_DIR AND HAL_LIBRARY AND HAL_STORAGE_LIBRARY)
-   MESSAGE( STATUS "hal not found")
-endif(HAL_INCLUDE_DIR AND HAL_LIBRARY AND HAL_STORAGE_LIBRARY)
-
-MARK_AS_ADVANCED(HAL_INCLUDE_DIR HAL_LIBRARY HAL_STORAGE_LIBRARY)
index e148e20..b149f0c 100644 (file)
@@ -45,11 +45,7 @@ Recommends:     lsof
 %endif
 BuildRequires:  cmake
 BuildRequires:  openssl-devel
-%if 0%{?suse_version} >= 1130 || 0%{?fedora_version} >= 16
 BuildRequires:  pkgconfig(libudev)
-%else
-BuildRequires:  hal-devel
-%endif
 %if 0%{?suse_version} >= 1330
 BuildRequires:  libboost_headers-devel
 BuildRequires:  libboost_program_options-devel
@@ -172,11 +168,7 @@ Requires:       openssl-devel
 Requires:       popt-devel
 Requires:       rpm-devel > 4.4
 Requires:       zlib-devel
-%if 0%{?suse_version} >= 1130 || 0%{?fedora_version} >= 16
 Requires:       libudev-devel
-%else
-Requires:       hal-devel
-%endif
 %if 0%{?suse_version}
 %if 0%{?suse_version} >= 1100
 # Code11+
@@ -270,7 +262,7 @@ cd ..
 
 %check
 pushd build/tests
-LD_LIBRARY_PATH="%{buildroot}/%{_libdir}:$LD_LIBRARY_PATH" ctest .
+LD_LIBRARY_PATH="%{buildroot}/%{_libdir}:$LD_LIBRARY_PATH" ctest --output-on-failure .
 popd
 
 %post
index 7030795..938b7db 100644 (file)
@@ -1,4 +1,14 @@
 -------------------------------------------------------------------
+Thu Jul 25 17:25:10 CEST 2019 - ma@suse.de
+
+- MediaCurl: Fix leaking filedescriptors (bsc#1116995)
+- commit: Run file conflict check on dry-run (best with download-only)
+  (bsc#1140039)
+- commit: do not remove orphan products if the .prod file is owned by
+  a package (bsc#1139795)
+- version 17.13.0 (12)
+
+-------------------------------------------------------------------
 Tue May 28 16:50:14 CEST 2019 - ma@suse.de
 
 - Drop unused InterProcessMutex class and test
index 4612227..093f8f3 100644 (file)
@@ -41,6 +41,7 @@ ADD_TESTS(
   ResKind
   Resolver
   ResStatus
+  RpmPkgSigCheck
   Selectable
   SetRelationMixin
   SetTracker
diff --git a/tests/zypp/RpmPkgSigCheck_test.cc b/tests/zypp/RpmPkgSigCheck_test.cc
new file mode 100644 (file)
index 0000000..0b84afe
--- /dev/null
@@ -0,0 +1,260 @@
+#include "TestSetup.h"
+static TestSetup test;
+
+#include "zypp/target/rpm/RpmDb.h"
+using target::rpm::RpmDb;
+
+#define DATADIR (Pathname(TESTS_SRC_DIR) / "/zypp/data/RpmPkgSigCheck")
+
+///////////////////////////////////////////////////////////////////
+//
+// - RpmDb::checkPackage (legacy) and RpmDb::checkPackageSignature are
+// expected to produce the same result, except for ...
+//
+// Result comparison is not very sophisticated. As the detail strings are
+// user visible (at least in zypper) we want a notification (breaking testcase)
+// if something in the rpm format changes.
+//
+///////////////////////////////////////////////////////////////////
+namespace
+{
+  struct CheckResult
+  {
+    CheckResult()
+    {}
+
+    CheckResult( RpmDb::CheckPackageResult && result_r )
+    : result { std::move(result_r) }
+    {}
+
+    CheckResult( RpmDb::CheckPackageResult && result_r,
+                std::vector<std::pair<RpmDb::CheckPackageResult,std::string>> && detail_r )
+    : result { std::move(result_r) }
+    { static_cast<std::vector<std::pair<RpmDb::CheckPackageResult,std::string>>&>(detail) = std::move(detail_r); }
+
+    RpmDb::CheckPackageResult result;
+    RpmDb::CheckPackageDetail detail;
+  };
+
+  bool operator==( const CheckResult & lhs, const CheckResult & rhs )
+  {
+    if ( lhs.result != rhs.result )
+      return false;
+    // protect against reordered details:
+    if ( lhs.detail.size() != rhs.detail.size() )
+      return false;
+    for ( const auto & l : lhs.detail )
+    {
+      if ( std::find( rhs.detail.begin(), rhs.detail.end(), l ) == rhs.detail.end() )
+       return false;
+    }
+    return true;
+  }
+
+  std::ostream & operator<<( std::ostream & str, const CheckResult & obj )
+  {
+    str << "R: " << obj.result;
+    for ( const auto & el : obj.detail )
+      str << endl << "   "  << el.first << " | " << el.second;
+    return str;
+  }
+
+  CheckResult gcheckPackage( const Pathname & path_r )
+  {
+    CheckResult res;
+    res.result = test.target().rpmDb().checkPackage( path_r, res.detail );
+//     cout << "==-" << path_r << endl;
+//     cout << res << endl;
+    return res;
+  }
+
+  CheckResult gcheckPackageSignature( const Pathname & path_r )
+  {
+    CheckResult res;
+    res.result = test.target().rpmDb().checkPackageSignature( path_r, res.detail );
+//     cout << "==!" << path_r << endl;
+//     cout << res << endl;
+    return res;
+  }
+} // namespace
+
+
+BOOST_AUTO_TEST_CASE(no_pkg)
+{
+  Pathname rpm { DATADIR/"no.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  BOOST_CHECK_EQUAL( cp, cs );
+
+  CheckResult xpct { RpmDb::CHK_ERROR, {/*empty details*/} };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
+
+BOOST_AUTO_TEST_CASE(unsigned_pkg)
+{
+  Pathname rpm { DATADIR/"unsigned.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  // For unsigned packages the final result differs!
+  // (but only if the digests are OK)
+  BOOST_CHECK_EQUAL( cp.result, RpmDb::CHK_OK );
+  BOOST_CHECK_EQUAL( cs.result, RpmDb::CHK_NOSIG );
+  BOOST_CHECK_EQUAL( cp.detail, cs.detail );
+
+  CheckResult xpct { RpmDb::CHK_NOSIG, {
+    { RpmDb::CHK_OK,   "    Header SHA1 digest: OK" },
+    { RpmDb::CHK_OK,   "    Header SHA256 digest: OK" },
+    { RpmDb::CHK_OK,   "    Payload SHA256 digest: OK" },
+    { RpmDb::CHK_OK,   "    MD5 digest: OK" },
+    { RpmDb::CHK_NOSIG,        "    Package is not signed!" },
+  } };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
+
+BOOST_AUTO_TEST_CASE(unsigned_broken_pkg)
+{
+  Pathname rpm { DATADIR/"unsigned_broken.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  // Unsigned, but a broken digest 'superseeds' CHK_NOSIG
+  BOOST_CHECK_EQUAL( cp, cs );
+
+  CheckResult xpct { RpmDb::CHK_FAIL, {
+    { RpmDb::CHK_OK,   "    Header SHA1 digest: OK" },
+    { RpmDb::CHK_OK,   "    Header SHA256 digest: OK" },
+    { RpmDb::CHK_FAIL, "    Payload SHA256 digest: BAD (Expected 6632dfb6e78fd3346baa860da339acdedf6f019fb1b5448ba1baa6cef67de795 != 85156c232f4c76273bbbb134d8d869e93bbfc845dd0d79016856e5356dd33727)" },
+    { RpmDb::CHK_FAIL, "    MD5 digest: BAD (Expected e3f474f75d2d2b267da4ff80fc071dd7 != cebe1e7d39b4356639a0779aa23f6e27)" },
+  } };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
+
+BOOST_AUTO_TEST_CASE(unsigned_broken_header_pkg)
+{
+  Pathname rpm { DATADIR/"unsigned_broken_header.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  // Unsigned, but a broken digest 'superseeds' CHK_NOSIG
+  BOOST_CHECK_EQUAL( cp, cs );
+
+  CheckResult xpct { RpmDb::CHK_FAIL, {
+    { RpmDb::CHK_FAIL, "    Header SHA1 digest: BAD (Expected d6768447e13388b0c35fb151ebfa8f6646a115e9 != dd761ace671a5eb2669b269faf22a3cd72792138)" },
+    { RpmDb::CHK_FAIL, "    Header SHA256 digest: BAD (Expected 2ce9f41bc0de68b4cb1aa1e18c1bea43dfaa01299ae61ef3e4466df332c792e5 != 4a9410db7131cead773afe1876f2490023ccc7dc47cbba47807430c53ea9649d)" },
+    { RpmDb::CHK_FAIL, "    Payload SHA256 digest: BAD (Expected 6632dfb6e78fd3346baa860da339acdedf6f019fb1b5448ba1baa6cef67de795 != 85156c232f4c76273bbbb134d8d869e93bbfc845dd0d79016856e5356dd33727)" },
+    { RpmDb::CHK_FAIL, "    MD5 digest: BAD (Expected e3f474f75d2d2b267da4ff80fc071dd7 != 9afd6b52896d23910280ddded1921071)" },
+  } };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
+
+BOOST_AUTO_TEST_CASE(signed_pkg_nokey)
+{
+  Pathname rpm { DATADIR/"signed.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  BOOST_CHECK_EQUAL( cp, cs );
+
+  CheckResult xpct { RpmDb::CHK_NOKEY, {
+    { RpmDb::CHK_NOKEY,        "    Header V3 RSA/SHA256 Signature, key ID 3dbdc284: NOKEY" },
+    { RpmDb::CHK_OK,   "    Header SHA1 digest: OK" },
+    { RpmDb::CHK_OK,   "    Header SHA256 digest: OK" },
+    { RpmDb::CHK_OK,   "    Payload SHA256 digest: OK" },
+    { RpmDb::CHK_OK,   "    MD5 digest: OK" },
+  } };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
+
+BOOST_AUTO_TEST_CASE(signed_broken_pkg_nokey)
+{
+  Pathname rpm { DATADIR/"signed_broken.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  BOOST_CHECK_EQUAL( cp, cs );
+
+  CheckResult xpct { RpmDb::CHK_FAIL, {
+    { RpmDb::CHK_NOKEY,        "    Header V3 RSA/SHA256 Signature, key ID 3dbdc284: NOKEY" },
+    { RpmDb::CHK_OK,   "    Header SHA1 digest: OK" },
+    { RpmDb::CHK_OK,   "    Header SHA256 digest: OK" },
+    { RpmDb::CHK_FAIL, "    Payload SHA256 digest: BAD (Expected 6632dfb6e78fd3346baa860da339acdedf6f019fb1b5448ba1baa6cef67de795 != 85156c232f4c76273bbbb134d8d869e93bbfc845dd0d79016856e5356dd33727)" },
+    { RpmDb::CHK_FAIL, "    MD5 digest: BAD (Expected 8e64684e4d5bd90c3c13f76ecbda9ee2 != 442a473472708c39f3ac2b5eb38b476f)" },
+  } };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
+
+BOOST_AUTO_TEST_CASE(signed_broken_header_pkg_nokey)
+{
+  Pathname rpm { DATADIR/"signed_broken_header.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  BOOST_CHECK_EQUAL( cp, cs );
+
+  CheckResult xpct { RpmDb::CHK_FAIL, {
+    { RpmDb::CHK_FAIL, "    Header V3 RSA/SHA256 Signature, key ID 3dbdc284: BAD" },
+    { RpmDb::CHK_FAIL, "    Header SHA1 digest: BAD (Expected 9ca2e3aec038e562d33442271ee52c08ded0d637 != 95286fd653f927df0a42746e310861d3f89bb75c)" },
+    { RpmDb::CHK_FAIL, "    Header SHA256 digest: BAD (Expected e88100656c8e06b6e4bb9155f0dd111ef8042866941f02b623cb46e12a82f732 != 76b343bcb9b8aaf9998fdcf7392e234944a0b078c67667fa0d658208b9a66983)" },
+    { RpmDb::CHK_FAIL, "    Payload SHA256 digest: BAD (Expected 6632dfb6e78fd3346baa860da339acdedf6f019fb1b5448ba1baa6cef67de795 != 85156c232f4c76273bbbb134d8d869e93bbfc845dd0d79016856e5356dd33727)" },
+    { RpmDb::CHK_FAIL, "    MD5 digest: BAD (Expected 8e64684e4d5bd90c3c13f76ecbda9ee2 != 81df819a7d94638ff3ffe0bb93a7d177)" },
+
+  } };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
+
+
+///////////////////////////////////////////////////////////////////
+BOOST_AUTO_TEST_CASE(add_key)
+{
+  PublicKey key { Pathname(DATADIR)/"signed.key" };
+  //cout << key << endl;
+  test.target().rpmDb().importPubkey( key );
+}
+///////////////////////////////////////////////////////////////////
+
+
+BOOST_AUTO_TEST_CASE(signed_pkg_withkey)
+{
+  Pathname rpm { DATADIR/"signed.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  BOOST_CHECK_EQUAL( cp, cs );
+
+  CheckResult xpct { RpmDb::CHK_OK, {
+    { RpmDb::CHK_OK,   "    Header V3 RSA/SHA256 Signature, key ID 3dbdc284: OK" },
+    { RpmDb::CHK_OK,   "    Header SHA1 digest: OK" },
+    { RpmDb::CHK_OK,   "    Header SHA256 digest: OK" },
+    { RpmDb::CHK_OK,   "    Payload SHA256 digest: OK" },
+    { RpmDb::CHK_OK,   "    MD5 digest: OK" },
+  } };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
+
+BOOST_AUTO_TEST_CASE(signed_broken_pkg_withkey)
+{
+  Pathname rpm { DATADIR/"signed_broken.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  BOOST_CHECK_EQUAL( cp, cs );
+
+  CheckResult xpct { RpmDb::CHK_FAIL, {
+    { RpmDb::CHK_OK,   "    Header V3 RSA/SHA256 Signature, key ID 3dbdc284: OK" },
+    { RpmDb::CHK_OK,   "    Header SHA1 digest: OK" },
+    { RpmDb::CHK_OK,   "    Header SHA256 digest: OK" },
+    { RpmDb::CHK_FAIL, "    Payload SHA256 digest: BAD (Expected 6632dfb6e78fd3346baa860da339acdedf6f019fb1b5448ba1baa6cef67de795 != 85156c232f4c76273bbbb134d8d869e93bbfc845dd0d79016856e5356dd33727)" },
+    { RpmDb::CHK_FAIL, "    MD5 digest: BAD (Expected 8e64684e4d5bd90c3c13f76ecbda9ee2 != 442a473472708c39f3ac2b5eb38b476f)" },
+  } };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
+
+BOOST_AUTO_TEST_CASE(signed_broken_header_pkg_withkey)
+{
+  Pathname rpm { DATADIR/"signed_broken_header.rpm" };
+  CheckResult cp { gcheckPackage( rpm ) };
+  CheckResult cs { gcheckPackageSignature( rpm ) };
+  BOOST_CHECK_EQUAL( cp, cs );
+
+  CheckResult xpct { RpmDb::CHK_FAIL, {
+    { RpmDb::CHK_FAIL, "    Header V3 RSA/SHA256 Signature, key ID 3dbdc284: BAD" },
+    { RpmDb::CHK_FAIL, "    Header SHA1 digest: BAD (Expected 9ca2e3aec038e562d33442271ee52c08ded0d637 != 95286fd653f927df0a42746e310861d3f89bb75c)" },
+    { RpmDb::CHK_FAIL, "    Header SHA256 digest: BAD (Expected e88100656c8e06b6e4bb9155f0dd111ef8042866941f02b623cb46e12a82f732 != 76b343bcb9b8aaf9998fdcf7392e234944a0b078c67667fa0d658208b9a66983)" },
+    { RpmDb::CHK_FAIL, "    Payload SHA256 digest: BAD (Expected 6632dfb6e78fd3346baa860da339acdedf6f019fb1b5448ba1baa6cef67de795 != 85156c232f4c76273bbbb134d8d869e93bbfc845dd0d79016856e5356dd33727)" },
+    { RpmDb::CHK_FAIL, "    MD5 digest: BAD (Expected 8e64684e4d5bd90c3c13f76ecbda9ee2 != 81df819a7d94638ff3ffe0bb93a7d177)" },
+  } };
+  BOOST_CHECK_EQUAL( xpct, cs );
+}
diff --git a/tests/zypp/data/RpmPkgSigCheck/no.rpm b/tests/zypp/data/RpmPkgSigCheck/no.rpm
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/zypp/data/RpmPkgSigCheck/signed.key b/tests/zypp/data/RpmPkgSigCheck/signed.key
new file mode 100644 (file)
index 0000000..5aa6ca0
--- /dev/null
@@ -0,0 +1,19 @@
+-----BEGIN PGP PUBLIC KEY BLOCK-----
+Version: rpm-4.11.2 (NSS-3)
+
+mQENBEkUTD8BCADWLy5d5IpJedHQQSXkC1VK/oAZlJEeBVpSZjMCn8LiHaI9Wq3G
+3Vp6wvsP1b3kssJGzVFNctdXt5tjvOLxvrEfRJuGfqHTKILByqLzkeyWawbFNfSQ
+93/8OunfSTXC1Sx3hgsNXQuOrNVKrDAQUqT620/jj94xNIg09bLSxsjN6EeTvyiO
+mtE9H1J03o9tY6meNL/gcQhxBvwuo205np0JojYBP0pOfN8l9hnIOLkA0yu4ZXig
+oKOVmf4iTjX4NImIWldT+UaWTO18NWcCrujtgHueytwYLBNV5N0oJIP2VYuLZfSD
+VYuPllv7c6O2UEOXJsdbQaVuzU1HLocDyipnABEBAAG0NG9wZW5TVVNFIFByb2pl
+Y3QgU2lnbmluZyBLZXkgPG9wZW5zdXNlQG9wZW5zdXNlLm9yZz6JATwEEwECACYC
+GwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAUCU2dN1AUJHR8ElQAKCRC4iy/UPb3C
+hGQrB/9teCZ3Nt8vHE0SC5NmYMAE1Spcjkzx6M4r4C70AVTMEQh/8BvgmwkKP/qI
+CWo2vC1hMXRgLg/TnTtFDq7kW+mHsCXmf5OLh2qOWCKi55Vitlf6bmH7n+h34Sha
+Ei8gAObSpZSF8BzPGl6v0QmEaGKM3O1oUbbB3Z8i6w21CTg7dbU5vGR8Yhi9rNtr
+hqrPS+q2yftjNbsODagaOUb85ESfQGx/LqoMePD+7MqGpAXjKMZqsEDP0TbxTwSk
+4UKnF4zFCYHPLK3y/hSH5SEJwwPY11l6JGdC1Ue8Zzaj7f//axUs/hTC0UZaEE+a
+5v4gbqOcigKaFs9Lc3Bj8b/lE10Y
+=i2TA
+-----END PGP PUBLIC KEY BLOCK-----
diff --git a/tests/zypp/data/RpmPkgSigCheck/signed.rpm b/tests/zypp/data/RpmPkgSigCheck/signed.rpm
new file mode 100644 (file)
index 0000000..410d968
Binary files /dev/null and b/tests/zypp/data/RpmPkgSigCheck/signed.rpm differ
diff --git a/tests/zypp/data/RpmPkgSigCheck/signed_broken.rpm b/tests/zypp/data/RpmPkgSigCheck/signed_broken.rpm
new file mode 100644 (file)
index 0000000..18ca278
Binary files /dev/null and b/tests/zypp/data/RpmPkgSigCheck/signed_broken.rpm differ
diff --git a/tests/zypp/data/RpmPkgSigCheck/signed_broken_header.rpm b/tests/zypp/data/RpmPkgSigCheck/signed_broken_header.rpm
new file mode 100644 (file)
index 0000000..f7d0901
Binary files /dev/null and b/tests/zypp/data/RpmPkgSigCheck/signed_broken_header.rpm differ
diff --git a/tests/zypp/data/RpmPkgSigCheck/unsigned.rpm b/tests/zypp/data/RpmPkgSigCheck/unsigned.rpm
new file mode 100644 (file)
index 0000000..d933983
Binary files /dev/null and b/tests/zypp/data/RpmPkgSigCheck/unsigned.rpm differ
diff --git a/tests/zypp/data/RpmPkgSigCheck/unsigned_broken.rpm b/tests/zypp/data/RpmPkgSigCheck/unsigned_broken.rpm
new file mode 100644 (file)
index 0000000..ddc1f93
Binary files /dev/null and b/tests/zypp/data/RpmPkgSigCheck/unsigned_broken.rpm differ
diff --git a/tests/zypp/data/RpmPkgSigCheck/unsigned_broken_header.rpm b/tests/zypp/data/RpmPkgSigCheck/unsigned_broken_header.rpm
new file mode 100644 (file)
index 0000000..2704b2f
Binary files /dev/null and b/tests/zypp/data/RpmPkgSigCheck/unsigned_broken_header.rpm differ
index 727d3da..4c3bd0d 100644 (file)
@@ -194,6 +194,45 @@ namespace zypp
     inline std::ostream & operator<<( std::ostream & str, const AutoDispose<Tp> & obj )
     { return str << obj.value(); }
 
+
+  ///////////////////////////////////////////////////////////////////
+  /// \class AutoFD
+  /// \brief \ref AutoDispose\<int>  calling \c ::close
+  /// \ingroup g_RAII
+  ///////////////////////////////////////////////////////////////////
+  struct AutoFD : public AutoDispose<int>
+  {
+    AutoFD( int fd_r = -1 ) : AutoDispose<int>( fd_r, [] ( int fd_r ) { if ( fd_r != -1 ) ::close( fd_r ); } ) {}
+  };
+
+  ///////////////////////////////////////////////////////////////////
+  /// \class AutoFILE
+  /// \brief \ref AutoDispose\<FILE*> calling \c ::fclose
+  /// \see \ref AutoDispose
+  /// \ingroup g_RAII
+  ///////////////////////////////////////////////////////////////////
+  struct AutoFILE : public AutoDispose<FILE*>
+  {
+    AutoFILE( FILE* file_r = nullptr ) : AutoDispose<FILE*>( file_r, [] ( FILE* file_r ) { if ( file_r ) ::fclose( file_r ); } ) {}
+  };
+
+  ///////////////////////////////////////////////////////////////////
+  /// \class AutoFREE<Tp>
+  /// \brief \ref AutoDispose\<Tp*> calling \c ::free
+  /// \ingroup g_RAII
+  ///////////////////////////////////////////////////////////////////
+  template <typename Tp>
+  struct AutoFREE : public AutoDispose<Tp*>
+  {
+    AutoFREE( Tp* ptr_r = nullptr ) : AutoDispose<Tp*>( ptr_r, [] ( Tp* ptr_r ) { if ( ptr_r ) ::free( ptr_r ); } ) {}
+    AutoFREE( void* ptr_r ) : AutoFREE( static_cast<Tp*>(ptr_r) ) {}
+  };
+
+  template <>
+  struct AutoFREE<void> : public AutoDispose<void*>
+  {
+    AutoFREE( void* ptr_r = nullptr ) : AutoDispose<void*>( ptr_r, [] ( void* ptr_r ) { if ( ptr_r ) ::free( ptr_r ); } ) {}
+  };
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
index b090a5a..3d3629a 100644 (file)
@@ -207,7 +207,6 @@ SET( zypp_base_SRCS
   base/SerialNumber.cc
   base/Random.cc
   base/Measure.cc
-  base/Fd.cc
   base/Gettext.cc
   base/GzStream.cc
   base/IOStream.cc
@@ -245,7 +244,6 @@ SET( zypp_base_HEADERS
   base/UserRequestException.h
   base/EnumClass.h
   base/ExternalDataSource.h
-  base/Fd.h
   base/Flags.h
   base/Function.h
   base/Functional.h
@@ -604,19 +602,6 @@ INSTALL(  FILES
   DESTINATION ${INCLUDE_INSTALL_DIR}/zypp/target
 )
 
-IF(NOT UDEV_FOUND)
-IF(HAL_FOUND)
-SET( zypp_target_hal_SRCS
-  target/hal/HalContext.cc
-)
-SET( zypp_target_hal_HEADERS
-  target/hal/HalContext.h
-  target/hal/HalException.h
-)
-ENDIF(HAL_FOUND)
-ENDIF(NOT UDEV_FOUND)
-# as HAL is deprecated, we don't install headers
-
 SET( zypp_target_modalias_SRCS
   target/modalias/Modalias.cc
 )
@@ -656,22 +641,6 @@ INSTALL(  FILES
   DESTINATION ${INCLUDE_INSTALL_DIR}/zypp/target/rpm
 )
 
-SET( zypp_thread_SRCS
-  thread/Mutex.cc
-)
-
-SET( zypp_thread_HEADERS
-  thread/Mutex.h
-  thread/MutexException.h
-  thread/MutexLock.h
-  thread/Once.h
-)
-
-INSTALL(  FILES
-  ${zypp_thread_HEADERS}
-  DESTINATION ${INCLUDE_INSTALL_DIR}/zypp/thread
-)
-
 SET( zypp_ui_SRCS
   ui/Selectable.cc
   ui/SelectableImpl.cc
@@ -826,7 +795,6 @@ ${zypp_target_modalias_SRCS}
 ${zypp_target_SRCS}
 ${zypp_solver_detail_SRCS}
 ${zypp_ui_SRCS}
-${zypp_thread_SRCS}
 ${zypp_SRCS}
 ${zypp_zypp_detail_SRCS}
 ${zypp_sat_SRCS}
@@ -852,7 +820,6 @@ ${zypp_sat_detail_HEADERS}
 ${zypp_url_HEADERS}
 ${zypp_HEADERS}
 ${zypp_zypp_detail_HEADERS}
-${zypp_thread_HEADERS}
 ${zypp_repo_HEADERS}
 ${zypp_source_susetags_HEADERS}
 ${zypp_target_modalias_HEADERS}
@@ -893,7 +860,6 @@ SET_LOGGROUP( "libsolv" ${zypp_sat_SRCS} )
 #SET_LOGGROUP( "group" ${zypp_parser_SRCS} )
 #SET_LOGGROUP( "group" ${zypp_SRCS} )
 #SET_LOGGROUP( "group" ${zypp_zypp_detail_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_thread_SRCS} )
 #SET_LOGGROUP( "group" ${zypp_source_susetags_SRCS} )
 #SET_LOGGROUP( "group" ${zypp_target_modalias_SRCS} )
 #SET_LOGGROUP( "group" ${zypp_target_SRCS} )
index 6bbde68..fbf5bd4 100644 (file)
@@ -7,11 +7,12 @@
 |                                                                      |
 \---------------------------------------------------------------------*/
 #include "zypp/KeyManager.h"
-#include "zypp/PublicKey.h"
+#include "zypp/KeyRing.h"
 #include "zypp/PathInfo.h"
 #include "zypp/base/Logger.h"
 #include "zypp/TmpPath.h"
 #include "zypp/base/String.h"
+#include "zypp/AutoDispose.h"
 
 #include <boost/thread/once.hpp>
 #include <boost/interprocess/smart_ptr/scoped_ptr.hpp>
@@ -35,6 +36,19 @@ namespace zypp
     // threads are introduced into libzypp
     boost::once_flag gpgme_init_once = BOOST_ONCE_INIT;
 
+    void initGpgme ()
+    {
+      const char *version = gpgme_check_version(NULL);
+      if ( version )
+      {
+       MIL << "Initialized libgpgme version: " << version << endl;
+      }
+      else
+      {
+       MIL << "Initialized libgpgme with unknown version" << endl;
+      }
+    }
+
     //using boost::interprocess pointer because it allows a custom deleter
     typedef boost::interprocess::scoped_ptr<gpgme_data, boost::function<void (gpgme_data_t)>> GpgmeDataPtr;
     typedef boost::interprocess::scoped_ptr<_gpgme_key, boost::function<void (gpgme_key_t)>>  GpgmeKeyPtr;
@@ -53,19 +67,6 @@ namespace zypp
     std::ostream & operator<<( std::ostream & str, const GpgmeErr & obj )
     { return str << "<" << gpgme_strsource(obj) << "> " << gpgme_strerror(obj); }
 
-    void initGpgme ()
-    {
-      const char *version = gpgme_check_version(NULL);
-      if ( version )
-      {
-       MIL << "Initialized libgpgme version: " << version << endl;
-      }
-      else
-      {
-       MIL << "Initialized libgpgme with unknown version" << endl;
-      }
-    }
-
     /** \relates gpgme_import_result_t Stream output. */
     std::ostream & operator<<( std::ostream & str, const _gpgme_op_import_result & obj )
     {
@@ -93,44 +94,46 @@ namespace zypp
   } // namespace
   ///////////////////////////////////////////////////////////////////
 
-class KeyManagerCtx::Impl
-{
-public:
-  Impl();
-  ~Impl();
-
-  /** Return all fingerprints found in \a signature_r. */
-  std::list<std::string> readSignaturesFprs( const Pathname & signature_r )
-  { return readSignaturesFprsOptVerify( signature_r ); }
+  struct GpgmeException : public KeyRingException
+  {
+    GpgmeException( const std::string & in_r, const GpgmeErr & err_r )
+    : KeyRingException( str::Format( "libgpgme error in '%1%': %2%" ) % in_r % err_r )
+    {}
+  };
 
-  /** Tries to verify the \a file_r using \a signature_r. */
-  bool verifySignaturesFprs( const Pathname & file_r, const Pathname & signature_r )
+  class KeyManagerCtx::Impl
   {
-    bool verify = false;
-    readSignaturesFprsOptVerify( signature_r, file_r, &verify );
-    return verify;
-  }
+  public:
+    Impl()
+    { boost::call_once( gpgme_init_once, initGpgme ); }
 
-  gpgme_ctx_t _ctx;
+    ~Impl()
+    { if ( _ctx ) gpgme_release( _ctx ); }
 
-private:
-  /** Return all fingerprints found in \a signature_r and optionally verify the \a file_r on the fly.
-   *
-   * If \a verify_r is not a \c nullptr, log verification errors and return
-   * whether all signatures are good.
-   */
-  std::list<std::string> readSignaturesFprsOptVerify( const Pathname & signature_r, const Pathname & file_r = "/dev/null", bool * verify_r = nullptr );
-};
 
-KeyManagerCtx::Impl::Impl()
-{ }
+    /** Return all fingerprints found in \a signature_r. */
+    std::list<std::string> readSignaturesFprs( const Pathname & signature_r )
+    { return readSignaturesFprsOptVerify( signature_r ); }
 
+    /** Tries to verify the \a file_r using \a signature_r. */
+    bool verifySignaturesFprs( const Pathname & file_r, const Pathname & signature_r )
+    {
+      bool verify = false;
+      readSignaturesFprsOptVerify( signature_r, file_r, &verify );
+      return verify;
+    }
 
-KeyManagerCtx::KeyManagerCtx()
-  : _pimpl( new Impl )
-{
+    gpgme_ctx_t _ctx { nullptr };
+    bool _volatile { false };  ///< readKeyFromFile workaround bsc#1140670
 
-}
+  private:
+    /** Return all fingerprints found in \a signature_r and optionally verify the \a file_r on the fly.
+     *
+     * If \a verify_r is not a \c nullptr, log verification errors and return
+     * whether all signatures are good.
+     */
+    std::list<std::string> readSignaturesFprsOptVerify( const Pathname & signature_r, const Pathname & file_r = "/dev/null", bool * verify_r = nullptr );
+  };
 
 std::list<std::string> KeyManagerCtx::Impl::readSignaturesFprsOptVerify( const Pathname & signature_r, const Pathname & file_r, bool * verify_r )
 {
@@ -216,114 +219,153 @@ std::list<std::string> KeyManagerCtx::Impl::readSignaturesFprsOptVerify( const P
   return signatures;
 }
 
-KeyManagerCtx::Impl::~Impl()
-{
-  gpgme_release(_ctx);
-}
 
-KeyManagerCtx::Ptr KeyManagerCtx::createForOpenPGP()
+KeyManagerCtx::KeyManagerCtx()
+: _pimpl( new Impl )
+{}
+
+KeyManagerCtx KeyManagerCtx::createForOpenPGP()
 {
-  //make sure gpgpme is initialized
-  boost::call_once(gpgme_init_once, initGpgme);
+  static Pathname tmppath( zypp::myTmpDir() / "PublicKey" );
+  filesystem::assert_dir( tmppath );
 
-  gpgme_ctx_t ctx;
-  GpgmeErr err = gpgme_new(&ctx);
-  if (err != GPG_ERR_NO_ERROR) {
-    ERR << err << endl;
-    return shared_ptr<KeyManagerCtx>();
-  }
+  KeyManagerCtx ret { createForOpenPGP( tmppath ) };
+  ret._pimpl->_volatile = true;        // readKeyFromFile workaround bsc#1140670
+  return ret;
+}
 
-  //use OpenPGP
-  err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP);
-  if (err != GPG_ERR_NO_ERROR) {
-    ERR << err << endl;
-    gpgme_release(ctx);
-    return shared_ptr<KeyManagerCtx>();
+KeyManagerCtx KeyManagerCtx::createForOpenPGP( const Pathname & keyring_r )
+{
+  DBG << "createForOpenPGP(" << keyring_r << ")" << endl;
+
+  KeyManagerCtx ret;
+  gpgme_ctx_t & ctx { ret._pimpl->_ctx };
+
+  // create the context
+  GpgmeErr err = gpgme_new( &ctx );
+  if ( err != GPG_ERR_NO_ERROR )
+    ZYPP_THROW( GpgmeException( "gpgme_new", err ) );
+
+  // use OpenPGP
+  err = gpgme_set_protocol( ctx, GPGME_PROTOCOL_OpenPGP );
+  if ( err != GPG_ERR_NO_ERROR )
+    ZYPP_THROW( GpgmeException( "gpgme_set_protocol", err ) );
+
+  if ( !keyring_r.empty() ) {
+    // get engine information to read current state
+    gpgme_engine_info_t enginfo = gpgme_ctx_get_engine_info( ctx );
+    if ( !enginfo )
+      ZYPP_THROW( GpgmeException( "gpgme_ctx_get_engine_info", err ) );
+
+    err = gpgme_ctx_set_engine_info( ctx, GPGME_PROTOCOL_OpenPGP, enginfo->file_name, keyring_r.c_str() );
+    if ( err != GPG_ERR_NO_ERROR )
+      ZYPP_THROW( GpgmeException( "gpgme_ctx_set_engine_info", err ) );
   }
 
-  shared_ptr<KeyManagerCtx> me( new KeyManagerCtx());
-  me->_pimpl->_ctx = ctx;
-  return me;
+  return ret;
 }
 
-bool KeyManagerCtx::setHomedir(const Pathname &keyring_r)
+Pathname KeyManagerCtx::homedir() const
 {
+  Pathname ret;
+  if ( gpgme_engine_info_t enginfo = gpgme_ctx_get_engine_info( _pimpl->_ctx ) )
+    ret = enginfo->home_dir;
+  return ret;
+}
 
-  /* get engine information to read current state*/
-  gpgme_engine_info_t enginfo = gpgme_ctx_get_engine_info(_pimpl->_ctx);
-  if (!enginfo)
-    return false;
+std::list<PublicKeyData> KeyManagerCtx::listKeys()
+{
+  std::list<PublicKeyData> ret;
+  GpgmeErr err = GPG_ERR_NO_ERROR;
 
-  GpgmeErr err = gpgme_ctx_set_engine_info(
-        _pimpl->_ctx,
-        GPGME_PROTOCOL_OpenPGP,
-        enginfo->file_name,
-        keyring_r.c_str());
+  // Reset gpgme_keylist_mode on return!
+  AutoDispose<gpgme_keylist_mode_t> guard { gpgme_get_keylist_mode( _pimpl->_ctx ), bind( &gpgme_set_keylist_mode, _pimpl->_ctx, _1 ) };
+  // Let listed keys include signatures (required if PublicKeyData are created from the key)
+  if ( (err = gpgme_set_keylist_mode( _pimpl->_ctx, GPGME_KEYLIST_MODE_LOCAL | GPGME_KEYLIST_MODE_SIGS )) != GPG_ERR_NO_ERROR ) {
+    ERR << "gpgme_set_keylist_mode: " << err << endl;
+    return ret;
+  }
 
-  if (err != GPG_ERR_NO_ERROR) {
-    ERR << "Unable to set homedir " << err << endl;
-    return false;
+  if ( (err = gpgme_op_keylist_start( _pimpl->_ctx, NULL, 0 )) != GPG_ERR_NO_ERROR ) {
+    ERR << "gpgme_op_keylist_start: " << err << endl;
+    return ret;
+  }
+  // Close list operation on return!
+  AutoDispose<gpgme_ctx_t> guard2 { _pimpl->_ctx, &gpgme_op_keylist_end };
+
+  AutoDispose<gpgme_key_t> key { nullptr, &gpgme_key_release };
+  for ( ; gpgme_op_keylist_next( _pimpl->_ctx, &(*key) ) == GPG_ERR_NO_ERROR; key.getDispose()( key ) ) {
+    PublicKeyData data { PublicKeyData::fromGpgmeKey( key ) };
+    if ( data )
+      ret.push_back( data );
   }
 
-  return true;
+  return ret;
 }
 
-Pathname KeyManagerCtx::homedir() const
+#if 1
+std::list<PublicKeyData> KeyManagerCtx::readKeyFromFile( const Pathname & keyfile_r )
 {
-  gpgme_engine_info_t enginfo = gpgme_ctx_get_engine_info(_pimpl->_ctx);
-  if (!enginfo)
-    return Pathname();
+  // bsc#1140670: GPGME does not support reading keys from a keyfile using
+  // gpgme_data_t and gpgme_op_keylist_from_data_start. Despite GPGME_KEYLIST_MODE_SIGS
+  // the signatures are missing, but we need them to create proper PublicKeyData objects.
+  // While this is not resolved, we read into a temp. keyring. Impl::_volatile helps
+  // to detect whether we can clear and import into the current context or need to
+  // create a temp. one.
+  std::list<PublicKeyData> ret;
+
+  if ( _pimpl->_volatile ) {
+    // in a volatile context we can simple clear the keyring...
+    filesystem::clean_dir( homedir() );
+    if ( importKey( keyfile_r ) )
+      ret = listKeys();
+  } else {
+    // read in a volatile context
+    ret = createForOpenPGP().readKeyFromFile( keyfile_r );
+  }
 
-  return Pathname(enginfo->home_dir);
+  return ret;
 }
-
-std::list<PublicKeyData> KeyManagerCtx::listKeys()
+#else
+std::list<PublicKeyData> KeyManagerCtx::readKeyFromFile( const Pathname & file_r )
 {
-  std::list<PublicKeyData> keys;
-  gpgme_key_t key;
+  std::list<PublicKeyData> ret;
   GpgmeErr err = GPG_ERR_NO_ERROR;
 
-  gpgme_keylist_mode_t mode = GPGME_KEYLIST_MODE_LOCAL | GPGME_KEYLIST_MODE_SIGS;
-  gpgme_set_keylist_mode (_pimpl->_ctx, mode);
-  gpgme_op_keylist_start (_pimpl->_ctx, NULL, 0);
+  AutoDispose<gpgme_data_t> data { nullptr, &gpgme_data_release };
+  if ( (err = gpgme_data_new_from_file( &(*data), file_r.c_str(), 1 )) != GPG_ERR_NO_ERROR ) {
+    ERR << "gpgme_data_new_from_file " << file_r << ": " << err << endl;
+    return ret;
+  }
 
-  while (!(err = gpgme_op_keylist_next(_pimpl->_ctx, &key))) {
-    PublicKeyData data = PublicKeyData::fromGpgmeKey(key);
-    if (data) {
-      keys.push_back(data);
-    }
-    gpgme_key_release(key);
+  // Reset gpgme_keylist_mode on return!
+  AutoDispose<gpgme_keylist_mode_t> guard { gpgme_get_keylist_mode( _pimpl->_ctx ), bind( &gpgme_set_keylist_mode, _pimpl->_ctx, _1 ) };
+  // Let listed keys include signatures (required if PublicKeyData are created from the key)
+  if ( (err = gpgme_set_keylist_mode( _pimpl->_ctx, GPGME_KEYLIST_MODE_LOCAL | GPGME_KEYLIST_MODE_SIGS )) != GPG_ERR_NO_ERROR ) {
+    ERR << "gpgme_set_keylist_mode: " << err << endl;
+    return ret;
   }
-  gpgme_op_keylist_end(_pimpl->_ctx);
-  return keys;
-}
 
-std::list<PublicKeyData> KeyManagerCtx::readKeyFromFile(const Pathname &file)
-{
-  //seems GPGME does not support reading keys from a keyfile using
-  //gpgme_data_t and gpgme_op_keylist_from_data_start, this always
-  //return unsupported errors. However importing and listing the key works.
-  zypp::Pathname realHomedir = homedir();
-
-  zypp::filesystem::TmpDir tmpKeyring;
-  if (!setHomedir(tmpKeyring.path()))
-    return std::list<PublicKeyData>();
-
-  if (!importKey(file)) {
-    setHomedir(realHomedir);
-    return std::list<PublicKeyData>();
+  if ( (err = gpgme_op_keylist_from_data_start( _pimpl->_ctx, data, 0 )) != GPG_ERR_NO_ERROR ) {
+    ERR << "gpgme_op_keylist_from_data_start " << file_r << ": " << err << endl;
+    return ret;
+  }
+  // Close list operation on return!
+  AutoDispose<gpgme_ctx_t> guard2 { _pimpl->_ctx, &gpgme_op_keylist_end };
+
+  AutoDispose<gpgme_key_t> key { nullptr, &gpgme_key_release };
+  for ( ; gpgme_op_keylist_next( _pimpl->_ctx, &(*key) ) == GPG_ERR_NO_ERROR; key.getDispose()( key ) ) {
+    PublicKeyData data { PublicKeyData::fromGpgmeKey( key ) };
+    if ( data )
+      ret.push_back( data );
   }
 
-  std::list<PublicKeyData> keys = listKeys();
-  setHomedir(realHomedir);
-  return keys;
+  return ret;
 }
+#endif
 
 bool KeyManagerCtx::verify(const Pathname &file, const Pathname &signature)
 {
-  if ( !PathInfo( file ).isExist() || !PathInfo( signature ).isExist() )
-    return false;
-
   return _pimpl->verifySignaturesFprs(file, signature);
 }
 
index 5845d8d..25315fb 100644 (file)
@@ -31,19 +31,34 @@ namespace zypp
 class KeyManagerCtx
 {
     public:
-        typedef shared_ptr<KeyManagerCtx> Ptr;
-
-        /** Creates a new KeyManagerCtx for PGP */
-        static Ptr createForOpenPGP();
-
-        /** Changes the keyring directory */
-        bool setHomedir (const Pathname & keyring_r);
-        Pathname homedir ()const;
+       /** Creates a new KeyManagerCtx for PGP using a volatile temp. homedir/keyring.
+        *
+        * Mainly used with methods, which need a context but do not need a keyring
+        * (like \ref readKeyFromFile or \ref readSignatureFingerprints).
+        *
+        * \note The underlying keyring is intentionally NOT the users keyring.
+        * Think of it as a volatile keyring whose content may get cleared anytime.
+        *
+        * \throws KeyRingException if context can not be created or set up
+        */
+       static KeyManagerCtx createForOpenPGP();
+
+       /** Creates a new KeyManagerCtx for PGP using a custom homedir/keyring.
+        *
+        * \note If you explicitly pass an empty \c Pathname, no homedir/keyring
+        * will be set and GPGME will use it's defaults.
+        *
+        * \throws KeyRingException if context can not be created or set up
+        */
+       static KeyManagerCtx createForOpenPGP( const Pathname & keyring_r );
+
+       /** Return the homedir/keyring. */
+       Pathname homedir() const;
 
         /**  Returns a list of all public keys found in the current keyring */
         std::list<PublicKeyData> listKeys();
 
-        /** Returns a list of all \sa PublicKeyData found in \a file */
+        /** Returns a list of all \a PublicKeyData found in \a file */
         std::list<PublicKeyData> readKeyFromFile(const Pathname & file);
 
         /** Tries to verify \a file using \a signature, returns true on success */
@@ -62,12 +77,10 @@ class KeyManagerCtx
         std::list<std::string> readSignatureFingerprints(const Pathname & signature);
 
     private:
-      class Impl;
-
       KeyManagerCtx();
 
+      class Impl;
       RW_pointer<Impl> _pimpl; ///< Pointer to implementation
-
 };
 
 }
index 51ebcd0..7cea27d 100644 (file)
@@ -162,14 +162,8 @@ namespace zypp
       const std::list<PublicKeyData> & getData( const Pathname & keyring_r, Cache & cache_r ) const
       {
         if ( cache_r.hasChanged() ) {
-          shared_ptr<KeyManagerCtx> ctx = KeyManagerCtx::createForOpenPGP();
-          if (ctx) {
-            if (ctx->setHomedir(keyring_r)) {
-              std::list<PublicKeyData> foundKeys = ctx->listKeys();
-              cache_r._data.swap(foundKeys);
-            }
-          }
-          MIL << "Found keys: " << cache_r._data  << endl;
+         cache_r._data = KeyManagerCtx::createForOpenPGP( keyring_r ).listKeys();
+         MIL << "Found keys: " << cache_r._data  << endl;
         }
         return cache_r._data;
       }
@@ -392,10 +386,7 @@ namespace zypp
 
   void KeyRing::Impl::dumpPublicKey( const std::string & id, const Pathname & keyring, std::ostream & stream )
   {
-    KeyManagerCtx::Ptr ctx = KeyManagerCtx::createForOpenPGP();
-    if (!ctx || !ctx->setHomedir(keyring))
-      return;
-    ctx->exportKey(id, stream);
+    KeyManagerCtx::createForOpenPGP( keyring ).exportKey(id, stream);
   }
 
   filesystem::TmpFile KeyRing::Impl::dumpPublicKeyToTmp( const std::string & id, const Pathname & keyring )
@@ -600,31 +591,16 @@ namespace zypp
                                   % keyfile.asString()
                                   % keyring.asString() ));
 
-    KeyManagerCtx::Ptr ctx = KeyManagerCtx::createForOpenPGP();
-    if(!ctx || !ctx->setHomedir(keyring))
-      ZYPP_THROW(KeyRingException(_("Failed to import key.")));
-
     cachedPublicKeyData.setDirty( keyring );
-    if(!ctx->importKey(keyfile))
+    if ( ! KeyManagerCtx::createForOpenPGP( keyring ).importKey( keyfile ) )
       ZYPP_THROW(KeyRingException(_("Failed to import key.")));
   }
 
   void KeyRing::Impl::deleteKey( const std::string & id, const Pathname & keyring )
   {
-    KeyManagerCtx::Ptr ctx = KeyManagerCtx::createForOpenPGP();
-    if(!ctx) {
-      ZYPP_THROW(KeyRingException(_("Failed to delete key.")));
-    }
-
-    if(!ctx->setHomedir(keyring)) {
-      ZYPP_THROW(KeyRingException(_("Failed to delete key.")));
-    }
-
-    if(!ctx->deleteKey(id)){
-      ZYPP_THROW(KeyRingException(_("Failed to delete key.")));
-    }
-
     cachedPublicKeyData.setDirty( keyring );
+    if ( ! KeyManagerCtx::createForOpenPGP( keyring ).deleteKey( id ) )
+      ZYPP_THROW(KeyRingException(_("Failed to delete key.")));
   }
 
   std::string KeyRing::Impl::readSignatureKeyId( const Pathname & signature )
@@ -634,13 +610,8 @@ namespace zypp
 
     MIL << "Determining key id of signature " << signature << endl;
 
-    KeyManagerCtx::Ptr ctx = KeyManagerCtx::createForOpenPGP();
-    if(!ctx) {
-      return std::string();
-    }
-
-    std::list<std::string> fprs = ctx->readSignatureFingerprints(signature);
-    if (fprs.size()) {
+    std::list<std::string> fprs = KeyManagerCtx::createForOpenPGP().readSignatureFingerprints( signature );
+    if ( ! fprs.empty() ) {
       std::string &id = fprs.back();
       MIL << "Determined key id [" << id << "] for signature " << signature << endl;
       return id;
@@ -650,11 +621,7 @@ namespace zypp
 
   bool KeyRing::Impl::verifyFile( const Pathname & file, const Pathname & signature, const Pathname & keyring )
   {
-    KeyManagerCtx::Ptr ctx = KeyManagerCtx::createForOpenPGP();
-    if (!ctx || !ctx->setHomedir(keyring))
-      return false;
-
-    return ctx->verify(file, signature);
+    return KeyManagerCtx::createForOpenPGP( keyring ).verify( file, signature );
   }
 
   ///////////////////////////////////////////////////////////////////
index 9a6a239..5eed597 100644 (file)
@@ -47,7 +47,9 @@ IMPL_PTR_TYPE(MediaSetAccess);
   {
     try
     {
-      release();
+      media::MediaManager manager;
+      for ( const auto & mm : _medias )
+       manager.close( mm.second );
     }
     catch(...) {} // don't let exception escape a dtor.
   }
index 2987cfa..4580d7c 100644 (file)
@@ -393,6 +393,7 @@ namespace zypp
       : _dontUseThisPtrDirectly( new filesystem::TmpFile( sharedFile_r ) )
     { readFromFile(); }
 
+    // private from keyring
     Impl( const filesystem::TmpFile & sharedFile_r, const PublicKeyData & keyData_r )
       : _dontUseThisPtrDirectly( new filesystem::TmpFile( sharedFile_r ) )
       , _keyData( keyData_r )
@@ -404,6 +405,7 @@ namespace zypp
       }
     }
 
+    // private from keyring
     Impl( const PublicKeyData & keyData_r )
       : _keyData( keyData_r )
     {}
@@ -419,23 +421,12 @@ namespace zypp
       { return _hiddenKeys; }
 
     protected:
-      std::string _initHomeDir()       ///< readFromFile helper to prepare the 'gpg --homedir'
-      { Pathname ret( zypp::myTmpDir() / "PublicKey" ); filesystem::assert_dir( ret ); return ret.asString(); }
-
       void readFromFile()
       {
         PathInfo info( path() );
         MIL << "Reading pubkey from " << info.path() << " of size " << info.size() << " and sha1 " << filesystem::checksum(info.path(), "sha1") << endl;
 
-        //@TODO is this still required? KeyManagerCtx creates a homedir on the fly
-        static std::string tmppath( _initHomeDir() );
-
-        KeyManagerCtx::Ptr ctx = KeyManagerCtx::createForOpenPGP();
-        if (!ctx || !ctx->setHomedir(tmppath)) {
-          ZYPP_THROW( Exception( std::string("Can't read public key data: Setting the keyring path failed!")) );
-        }
-
-        std::list<PublicKeyData> keys = ctx->readKeyFromFile(path());
+        std::list<PublicKeyData> keys = KeyManagerCtx::createForOpenPGP().readKeyFromFile( path() );
         switch ( keys.size() )
         {
           case 0:
index 246aff8..059c8a4 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <solv/solvversion.h>
 
-#include "zypp/base/String.h"
 #include "zypp/base/InputStream.h"
 #include "zypp/base/LogTools.h"
 #include "zypp/base/Gettext.h"
@@ -39,7 +38,6 @@
 #include "zypp/MediaSetAccess.h"
 #include "zypp/ExternalProgram.h"
 #include "zypp/ManagedFile.h"
-#include "zypp/KeyManager.h"
 
 #include "zypp/parser/RepoFileReader.h"
 #include "zypp/parser/ServiceFileReader.h"
diff --git a/zypp/base/Fd.cc b/zypp/base/Fd.cc
deleted file mode 100644 (file)
index 29887ea..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file      zypp/base/Fd.cc
- *
-*/
-extern "C"
-{
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-}
-
-#include <iostream>
-
-#include "zypp/base/Exception.h"
-#include "zypp/base/Fd.h"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-  ///////////////////////////////////////////////////////////////////
-  namespace base
-  { /////////////////////////////////////////////////////////////////
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : Fd::Fd
-    // METHOD TYPE : Ctor
-    //
-    Fd::Fd( const Pathname & file_r, int open_flags, mode_t mode )
-    : m_fd( -1 )
-    {
-      m_fd = open( file_r.asString().c_str(), open_flags, mode );
-      if ( m_fd == -1 )
-        ZYPP_THROW_ERRNO_MSG( Exception, std::string("open ")+file_r.asString() );
-    }
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : Fd::close
-    // METHOD TYPE : void
-    //
-    void Fd::close()
-    {
-      if ( m_fd != -1 )
-        {
-          ::close( m_fd );
-          m_fd = -1;
-        }
-    }
-
-    /////////////////////////////////////////////////////////////////
-  } // namespace base
-  ///////////////////////////////////////////////////////////////////
-  /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
diff --git a/zypp/base/Fd.h b/zypp/base/Fd.h
deleted file mode 100644 (file)
index ba489d2..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file      zypp/base/Fd.h
- *
-*/
-#ifndef ZYPP_BASE_FD_H
-#define ZYPP_BASE_FD_H
-
-#include "zypp/Pathname.h"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
-  ///////////////////////////////////////////////////////////////////
-  namespace base
-  { /////////////////////////////////////////////////////////////////
-
-    ///////////////////////////////////////////////////////////////////
-    //
-    // CLASS NAME : Fd
-    //
-    /** Assert \c close called on open filedescriptor.
-     * \code
-     * ...
-     * scoped_ptr<Fd> fd; // calls close when going out of scope
-     * try {
-     *   fd.reset( new Fd( "/some/file" ) );
-     * } catch ( ... ) {
-     *   // open failed.
-     * }
-     * read( fd->fd(), ... ),
-     * \endcode
-     *
-     * \ingroup g_RAII
-     * \todo It's dumb. Openflags and more related functions (read/write..)
-     * could be added.
-    */
-    class Fd
-    {
-      NON_COPYABLE( Fd );
-    public:
-      /** Ctor opens file.
-       * \throw EXCEPTION If open fails.
-      */
-      Fd( const Pathname & file_r, int open_flags, mode_t mode = 0 );
-
-      /** Move ctor */
-      Fd( Fd && rhs )
-      : m_fd( -1 )
-      { std::swap( m_fd, rhs.m_fd ); }
-
-      /** Move assign */
-      Fd & operator=( Fd && rhs )
-      { if ( this != &rhs ) std::swap( m_fd, rhs.m_fd ); return *this; }
-
-      /** Dtor closes file. */
-      ~Fd()
-      { close(); }
-
-      /** Explicitly close the file. */
-      void close();
-
-      /** Test for valid filedescriptor. */
-      bool isOpen() const
-      { return m_fd != -1; }
-
-      /** Return the filedescriptor. */
-      int fd() const
-      { return m_fd; }
-
-      /** Return the filedescriptor. */
-      int operator*() const
-      { return m_fd; }
-
-    private:
-      /** The filedescriptor. */
-      int m_fd;
-    };
-    ///////////////////////////////////////////////////////////////////
-
-    /////////////////////////////////////////////////////////////////
-  } // namespace base
-  ///////////////////////////////////////////////////////////////////
-  /////////////////////////////////////////////////////////////////
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_BASE_FD_H
index fbe2c75..286712a 100644 (file)
@@ -18,12 +18,6 @@ extern "C"
 #endif
 }
 
-#ifndef HAVE_UDEV
-#if HAVE_HAL
-#include "zypp/target/hal/HalContext.h"
-#endif
-#endif
-
 #include <cstring> // strerror
 #include <cstdlib> // getenv
 #include <iostream>
@@ -65,13 +59,9 @@ namespace zypp
       typedef std::list<MediaSource> DeviceList;
 
       //////////////////////////////////////////////////////////////////
-      /// \brief Try to detect cd/dvd devices using hal/udev
+      /// \brief Try to detect cd/dvd devices using udev
       ///
       /// Returns an empty device list on error.
-      ///
-      /// \todo I took the code more or less as it was from MediaCD::detectDevices
-      /// into this function. Semantic between HAL and UDEV seems to be slightly
-      /// different, esp. in supportingDVD mode. This should be investigated and fixed.
       //////////////////////////////////////////////////////////////////
       DeviceList systemDetectDevices( bool supportingDVD_r )
       {
@@ -136,62 +126,6 @@ namespace zypp
        {
          WAR << "Did not find any CD/DVD device." << endl;
        }
-#elif HAVE_HAL
-       using namespace zypp::target::hal;
-       try
-       {
-         HalContext hal(true);
-
-         std::vector<std::string> drv_udis;
-         drv_udis = hal.findDevicesByCapability("storage.cdrom");
-
-         DBG << "Found " << drv_udis.size() << " cdrom drive udis" << std::endl;
-         for(size_t d = 0; d < drv_udis.size(); d++)
-         {
-           HalDrive drv( hal.getDriveFromUDI( drv_udis[d]));
-
-           if( drv)
-           {
-             bool supportsDVD=false;
-             if( supportingDVD_r)
-             {
-               std::vector<std::string> caps;
-               try {
-                 caps = drv.getCdromCapabilityNames();
-               }
-               catch(const HalException &e)
-               {
-                 ZYPP_CAUGHT(e);
-               }
-
-               std::vector<std::string>::const_iterator ci;
-               for( ci=caps.begin(); ci != caps.end(); ++ci)
-               {
-                 if( *ci == "dvd")
-                   supportsDVD = true;
-               }
-             }
-
-             MediaSource media("cdrom", drv.getDeviceFile(),
-                     drv.getDeviceMajor(),
-                     drv.getDeviceMinor());
-                 DBG << "Found " << drv_udis[d] << ": "
-                 << media.asString() << std::endl;
-                 if( supportingDVD_r && supportsDVD)
-                 {
-                   detected.push_front(media);
-                 }
-                 else
-                 {
-                   detected.push_back(media);
-                 }
-           }
-         }
-       }
-       catch(const zypp::target::hal::HalException &e)
-       {
-         ZYPP_CAUGHT(e);
-       }
 #endif
        return detected;
       }
@@ -330,7 +264,7 @@ namespace zypp
 
     if ( detected.empty() )
     {
-      WAR << "CD/DVD drive detection with HAL/UDEV failed! Guessing..." << std::endl;
+      WAR << "CD/DVD drive detection with UDEV failed! Guessing..." << std::endl;
       PathInfo dvdinfo( "/dev/dvd" );
       PathInfo cdrinfo( "/dev/cdrom" );
       if ( dvdinfo.isBlk() )
index 41ad500..af4c5f7 100644 (file)
@@ -25,7 +25,6 @@
 #include "zypp/media/MediaUserAuth.h"
 #include "zypp/media/CredentialManager.h"
 #include "zypp/media/CurlConfig.h"
-#include "zypp/thread/Once.h"
 #include "zypp/Target.h"
 #include "zypp/ZYppFactory.h"
 #include "zypp/ZConfig.h"
@@ -52,40 +51,13 @@ using namespace zypp::base;
 
 namespace
 {
-  zypp::thread::OnceFlag g_InitOnceFlag = PTHREAD_ONCE_INIT;
-  zypp::thread::OnceFlag g_FreeOnceFlag = PTHREAD_ONCE_INIT;
-
-  extern "C" void _do_free_once()
-  {
-    curl_global_cleanup();
-  }
-
-  extern "C" void globalFreeOnce()
-  {
-    zypp::thread::callOnce(g_FreeOnceFlag, _do_free_once);
-  }
-
-  extern "C" void _do_init_once()
-  {
-    CURLcode ret = curl_global_init( CURL_GLOBAL_ALL );
-    if ( ret != 0 )
-    {
-      WAR << "curl global init failed" << endl;
-    }
-
-    //
-    // register at exit handler ?
-    // this may cause trouble, because we can protect it
-    // against ourself only.
-    // if the app sets an atexit handler as well, it will
-    // cause a double free while the second of them runs.
-    //
-    //std::atexit( globalFreeOnce);
-  }
-
   inline void globalInitOnce()
   {
-    zypp::thread::callOnce(g_InitOnceFlag, _do_init_once);
+    // function-level static <=> std::call_once
+    static bool once __attribute__ ((__unused__)) = ( [] {
+      if ( curl_global_init( CURL_GLOBAL_ALL ) != 0 )
+       WAR << "curl global init failed" << endl;
+    } (), true );
   }
 
   int log_curl(CURL *curl, curl_infotype info,
@@ -1273,7 +1245,7 @@ bool MediaCurl::doGetDoesFileExist( const Pathname & filename ) const
     ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
   }
 
-  FILE *file = ::fopen( "/dev/null", "w" );
+  AutoFILE file { ::fopen( "/dev/null", "w" ) };
   if ( !file ) {
       ERR << "fopen failed for /dev/null" << endl;
       curl_easy_setopt( _curl, CURLOPT_NOBODY, 0L);
@@ -1290,9 +1262,8 @@ bool MediaCurl::doGetDoesFileExist( const Pathname & filename ) const
       ZYPP_THROW(MediaWriteException("/dev/null"));
   }
 
-  ret = curl_easy_setopt( _curl, CURLOPT_WRITEDATA, file );
+  ret = curl_easy_setopt( _curl, CURLOPT_WRITEDATA, (*file) );
   if ( ret != 0 ) {
-      ::fclose(file);
       std::string err( _curlError);
       curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
       curl_easy_setopt( _curl, CURLOPT_NOBODY, 0L);
@@ -1339,10 +1310,6 @@ bool MediaCurl::doGetDoesFileExist( const Pathname & filename ) const
     }
   }
 
-  // if the code is not zero, close the file
-  if ( ok != 0 )
-      ::fclose(file);
-
   // as we are not having user interaction, the user can't cancel
   // the file existence checking, a callback or timeout return code
   // will be always a timeout.
@@ -1412,34 +1379,34 @@ void MediaCurl::doGetFileCopy(const Pathname & filename , const Pathname & targe
     if( assert_dir( dest.dirname() ) )
     {
       DBG << "assert_dir " << dest.dirname() << " failed" << endl;
-      Url url(getFileUrl(filename));
-      ZYPP_THROW( MediaSystemException(url, "System error on " + dest.dirname().asString()) );
-    }
-    string destNew = target.asString() + ".new.zypp.XXXXXX";
-    char *buf = ::strdup( destNew.c_str());
-    if( !buf)
-    {
-      ERR << "out of memory for temp file name" << endl;
-      Url url(getFileUrl(filename));
-      ZYPP_THROW(MediaSystemException(url, "out of memory for temp file name"));
+      ZYPP_THROW( MediaSystemException(getFileUrl(filename), "System error on " + dest.dirname().asString()) );
     }
 
-    int tmp_fd = ::mkostemp( buf, O_CLOEXEC );
-    if( tmp_fd == -1)
+    ManagedFile destNew { target.extend( ".new.zypp.XXXXXX" ) };
+    AutoFILE file;
     {
-      free( buf);
-      ERR << "mkstemp failed for file '" << destNew << "'" << endl;
-      ZYPP_THROW(MediaWriteException(destNew));
-    }
-    destNew = buf;
-    free( buf);
+      AutoFREE<char> buf { ::strdup( (*destNew).c_str() ) };
+      if( ! buf )
+      {
+       ERR << "out of memory for temp file name" << endl;
+       ZYPP_THROW(MediaSystemException(getFileUrl(filename), "out of memory for temp file name"));
+      }
+
+      AutoFD tmp_fd { ::mkostemp( buf, O_CLOEXEC ) };
+      if( tmp_fd == -1 )
+      {
+       ERR << "mkstemp failed for file '" << destNew << "'" << endl;
+       ZYPP_THROW(MediaWriteException(destNew));
+      }
+      destNew = ManagedFile( (*buf), filesystem::unlink );
 
-    FILE *file = ::fdopen( tmp_fd, "we" );
-    if ( !file ) {
-      ::close( tmp_fd);
-      filesystem::unlink( destNew );
-      ERR << "fopen failed for file '" << destNew << "'" << endl;
-      ZYPP_THROW(MediaWriteException(destNew));
+      file = ::fdopen( tmp_fd, "we" );
+      if ( ! file )
+      {
+       ERR << "fopen failed for file '" << destNew << "'" << endl;
+       ZYPP_THROW(MediaWriteException(destNew));
+      }
+      tmp_fd.resetDispose();   // don't close it here! ::fdopen moved ownership to file
     }
 
     DBG << "dest: " << dest << endl;
@@ -1462,8 +1429,6 @@ void MediaCurl::doGetFileCopy(const Pathname & filename , const Pathname & targe
     }
     catch (Exception &e)
     {
-      ::fclose( file );
-      filesystem::unlink( destNew );
       curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
       curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, 0L);
       ZYPP_RETHROW(e);
@@ -1497,22 +1462,20 @@ void MediaCurl::doGetFileCopy(const Pathname & filename , const Pathname & targe
       {
         ERR << "Failed to chmod file " << destNew << endl;
       }
-      if (::fclose( file ))
+
+      file.resetDispose();     // we're going to close it manually here
+      if ( ::fclose( file ) )
       {
         ERR << "Fclose failed for file '" << destNew << "'" << endl;
         ZYPP_THROW(MediaWriteException(destNew));
       }
+
       // move the temp file into dest
       if ( rename( destNew, dest ) != 0 ) {
         ERR << "Rename failed" << endl;
         ZYPP_THROW(MediaWriteException(dest));
       }
-    }
-    else
-    {
-      // close and remove the temp file
-      ::fclose( file );
-      filesystem::unlink( destNew );
+      destNew.resetDispose();  // no more need to unlink it
     }
 
     DBG << "done: " << PathInfo(dest) << endl;
index 14e4af6..28202ac 100644 (file)
@@ -18,8 +18,6 @@
 #include "zypp/media/MediaManager.h"
 #include "zypp/media/MediaHandler.h"
 #include "zypp/media/Mount.h"
-#include "zypp/thread/Mutex.h"
-#include "zypp/thread/MutexLock.h"
 
 #include "zypp/base/String.h"
 #include "zypp/base/Logger.h"
@@ -34,19 +32,10 @@ namespace zypp
   namespace media
   { //////////////////////////////////////////////////////////////////
 
-    using zypp::thread::Mutex;
-    using zypp::thread::MutexLock;
-
     //////////////////////////////////////////////////////////////////
     namespace // anonymous
     { ////////////////////////////////////////////////////////////////
 
-
-      // -------------------------------------------------------------
-      // STATIC
-      static Mutex  g_Mutex;
-
-
       // -------------------------------------------------------------
       struct ManagedMedia
       {
@@ -156,8 +145,6 @@ namespace zypp
     public:
       ~MediaManager_Impl()
       {
-        MutexLock glock(g_Mutex);
-
         try
         {
           // remove depending (iso) handlers first
@@ -242,7 +229,6 @@ namespace zypp
     //////////////////////////////////////////////////////////////////
     MediaManager::MediaManager()
     {
-      MutexLock glock(g_Mutex);
       if( !m_impl)
       {
         m_impl.reset( new MediaManager_Impl());
@@ -258,8 +244,6 @@ namespace zypp
     MediaAccessId
     MediaManager::open(const Url &url, const Pathname &preferred_attach_point)
     {
-      MutexLock glock(g_Mutex);
-
       // create new access handler for it
       MediaAccessRef handler( new MediaAccess());
       MediaVerifierRef verifier( new NoVerifier());
@@ -280,8 +264,6 @@ namespace zypp
     void
     MediaManager::close(MediaAccessId accessId)
     {
-      MutexLock glock(g_Mutex);
-
       //
       // The MediaISO handler internally requests an accessId
       // of a "parent" handler providing the iso file.
@@ -316,8 +298,6 @@ namespace zypp
     bool
     MediaManager::isOpen(MediaAccessId accessId) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMediaMap::iterator it( m_impl->mediaMap.find(accessId));
       return it != m_impl->mediaMap.end() &&
              it->second.handler->isOpen();
@@ -327,8 +307,6 @@ namespace zypp
     std::string
     MediaManager::protocol(MediaAccessId accessId) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       return ref.handler->protocol();
@@ -338,8 +316,6 @@ namespace zypp
          bool
     MediaManager::downloads(MediaAccessId accessId) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       return ref.handler->downloads();
@@ -349,8 +325,6 @@ namespace zypp
     Url
     MediaManager::url(MediaAccessId accessId) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       return ref.handler->url();
@@ -361,8 +335,6 @@ namespace zypp
     MediaManager::addVerifier(MediaAccessId           accessId,
                               const MediaVerifierRef &verifier)
     {
-      MutexLock glock(g_Mutex);
-
       if( !verifier)
         ZYPP_THROW(MediaException("Invalid verifier reference"));
 
@@ -379,8 +351,6 @@ namespace zypp
     void
     MediaManager::delVerifier(MediaAccessId accessId)
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       MediaVerifierRef verifier( new NoVerifier());
@@ -395,16 +365,12 @@ namespace zypp
     bool
     MediaManager::setAttachPrefix(const Pathname &attach_prefix)
     {
-      MutexLock glock(g_Mutex);
-
       return MediaHandler::setAttachPrefix(attach_prefix);
     }
 
     // ---------------------------------------------------------------
     void MediaManager::attach(MediaAccessId accessId)
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       DBG << "attach(id=" << accessId << ")" << std::endl;
@@ -473,8 +439,6 @@ namespace zypp
     void
     MediaManager::release(MediaAccessId accessId, const std::string & ejectDev)
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       DBG << "release(id=" << accessId;
@@ -517,8 +481,6 @@ namespace zypp
     void
     MediaManager::releaseAll()
     {
-      MutexLock glock(g_Mutex);
-
       MIL << "Releasing all attached media" << std::endl;
 
       ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
@@ -554,8 +516,6 @@ namespace zypp
     void
     MediaManager::disconnect(MediaAccessId accessId)
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       ref.handler->disconnect();
@@ -565,8 +525,6 @@ namespace zypp
     bool
     MediaManager::isAttached(MediaAccessId accessId) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       return ref.handler->isAttached();
@@ -575,8 +533,6 @@ namespace zypp
     // ---------------------------------------------------------------
     bool MediaManager::isSharedMedia(MediaAccessId accessId) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       return ref.handler->isSharedMedia();
@@ -586,8 +542,6 @@ namespace zypp
     bool
     MediaManager::isDesiredMedia(MediaAccessId accessId) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       if( !ref.handler->isAttached())
@@ -616,8 +570,6 @@ namespace zypp
     MediaManager::isDesiredMedia(MediaAccessId           accessId,
                                  const MediaVerifierRef &verifier) const
     {
-      MutexLock glock(g_Mutex);
-
       MediaVerifierRef v(verifier);
       if( !v)
         ZYPP_THROW(MediaException("Invalid verifier reference"));
@@ -653,8 +605,6 @@ namespace zypp
     Pathname
     MediaManager::localRoot(MediaAccessId accessId) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       Pathname path;
@@ -667,8 +617,6 @@ namespace zypp
     MediaManager::localPath(MediaAccessId accessId,
                             const Pathname & pathname) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       Pathname path;
@@ -681,8 +629,6 @@ namespace zypp
                               const Pathname &filename,
                               const ByteCount &expectedFileSize ) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       ref.checkDesired(accessId);
@@ -703,8 +649,6 @@ namespace zypp
     MediaManager::setDeltafile(MediaAccessId   accessId,
                               const Pathname &filename ) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       ref.checkDesired(accessId);
@@ -717,8 +661,6 @@ namespace zypp
     MediaManager::provideDir(MediaAccessId   accessId,
                              const Pathname &dirname) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       ref.checkDesired(accessId);
@@ -731,8 +673,6 @@ namespace zypp
     MediaManager::provideDirTree(MediaAccessId   accessId,
                                  const Pathname &dirname) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       ref.checkDesired(accessId);
@@ -745,8 +685,6 @@ namespace zypp
     MediaManager::releaseFile(MediaAccessId   accessId,
                               const Pathname &filename) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       ref.checkAttached(accessId);
@@ -759,8 +697,6 @@ namespace zypp
     MediaManager::releaseDir(MediaAccessId   accessId,
                              const Pathname &dirname) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       ref.checkAttached(accessId);
@@ -774,8 +710,6 @@ namespace zypp
     MediaManager::releasePath(MediaAccessId   accessId,
                               const Pathname &pathname) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       ref.checkAttached(accessId);
@@ -790,8 +724,6 @@ namespace zypp
                           const Pathname         &dirname,
                           bool                    dots) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       // FIXME: ref.checkDesired(accessId); ???
@@ -807,8 +739,6 @@ namespace zypp
                           const Pathname         &dirname,
                           bool                    dots) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       // FIXME: ref.checkDesired(accessId); ???
@@ -821,7 +751,6 @@ namespace zypp
     bool
     MediaManager::doesFileExist(MediaAccessId  accessId, const Pathname & filename ) const
     {
-      MutexLock glock(g_Mutex);
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       // FIXME: ref.checkDesired(accessId); ???
@@ -836,7 +765,6 @@ namespace zypp
                                      std::vector<std::string> & devices,
                                      unsigned int & index) const
     {
-      MutexLock glock(g_Mutex);
       ManagedMedia &ref( m_impl->findMM(accessId));
       return ref.handler->getDetectedDevices(devices, index);
     }
@@ -846,7 +774,6 @@ namespace zypp
     time_t
     MediaManager::getMountTableMTime()
     {
-      MutexLock glock(g_Mutex);
       return MediaManager_Impl::getMountTableMTime();
     }
 
@@ -855,8 +782,6 @@ namespace zypp
     MountEntries
     MediaManager::getMountEntries()
     {
-      MutexLock glock(g_Mutex);
-
       return MediaManager_Impl::getMountEntries();
     }
 
@@ -868,8 +793,6 @@ namespace zypp
       if( path.empty() || path == "/" || !PathInfo(path).isDir())
         return false;
 
-      MutexLock glock(g_Mutex);
-
       //
       // check against our current attach points
       //
@@ -935,8 +858,6 @@ namespace zypp
     AttachedMedia
     MediaManager::getAttachedMedia(MediaAccessId &accessId) const
     {
-      MutexLock glock(g_Mutex);
-
       ManagedMedia &ref( m_impl->findMM(accessId));
 
       return ref.handler->attachedMedia();
@@ -946,8 +867,6 @@ namespace zypp
     AttachedMedia
     MediaManager::findAttachedMedia(const MediaSourceRef &media) const
     {
-      MutexLock glock(g_Mutex);
-
       if( !media || media->type.empty())
         return AttachedMedia();
 
@@ -968,8 +887,6 @@ namespace zypp
     void
     MediaManager::forceReleaseShared(const MediaSourceRef &media)
     {
-      MutexLock glock(g_Mutex);
-
       if( !media || media->type.empty())
         return;
 
index cb035fd..faed227 100644 (file)
@@ -182,16 +182,13 @@ namespace zypp
      *       Optional parameter, containing a comma separated list of
      *       block device names to use, e.g.: "/dev/sr0,/dev/sr1".
      *       <br>
-     *       The device names will be verified using a HAL query. If one
-     *       of the provided devices is not usable (not a block device,
-     *       or does not support required media type), an exception is
-     *       thrown.
+     *       The device names will be verified. If one of the provided
+     *       devices is not usable (not a block device, or does not
+     *       support required media type), an exception is thrown.
      *       <br>
-     *       If the devices parameter is not provided (or empty), all
-     *       avaliable CD/DVD drives 'detected' using a HAL query. The
-     *       preferred drive (used as first drive) is the drive pointed
-     *       to by the symlink "/dev/dvd" ("dvd" scheme only) or
-     *       "/dev/cdrom".
+     *       If the devices parameter is not provided (or empty), available
+     *       CD/DVD drives will be auto-detected. The preferred device is
+     *       the one denoted by "/dev/dvd" ("dvd" scheme only) or "/dev/cdrom".
      *   - Authority:
      *     A non-empty authority URL component (e.g. containing a host
      *     name) is not allowed.
index 670a4f3..d172c2d 100644 (file)
@@ -26,6 +26,7 @@
 #include "zypp/base/Logger.h"
 #include "zypp/media/MediaMultiCurl.h"
 #include "zypp/media/MetaLinkParser.h"
+#include "zypp/ManagedFile.h"
 
 using namespace std;
 using namespace zypp::base;
@@ -1300,35 +1301,36 @@ void MediaMultiCurl::doGetFileCopy( const Pathname & filename , const Pathname &
   if( assert_dir( dest.dirname() ) )
   {
     DBG << "assert_dir " << dest.dirname() << " failed" << endl;
-    Url url(getFileUrl(filename));
-    ZYPP_THROW( MediaSystemException(url, "System error on " + dest.dirname().asString()) );
-  }
-  string destNew = target.asString() + ".new.zypp.XXXXXX";
-  char *buf = ::strdup( destNew.c_str());
-  if( !buf)
-  {
-    ERR << "out of memory for temp file name" << endl;
-    Url url(getFileUrl(filename));
-    ZYPP_THROW(MediaSystemException(url, "out of memory for temp file name"));
+    ZYPP_THROW( MediaSystemException(getFileUrl(filename), "System error on " + dest.dirname().asString()) );
   }
 
-  int tmp_fd = ::mkostemp( buf, O_CLOEXEC );
-  if( tmp_fd == -1)
+  ManagedFile destNew { target.extend( ".new.zypp.XXXXXX" ) };
+  AutoFILE file;
   {
-    free( buf);
-    ERR << "mkstemp failed for file '" << destNew << "'" << endl;
-    ZYPP_THROW(MediaWriteException(destNew));
-  }
-  destNew = buf;
-  free( buf);
-
-  FILE *file = ::fdopen( tmp_fd, "we" );
-  if ( !file ) {
-    ::close( tmp_fd);
-    filesystem::unlink( destNew );
-    ERR << "fopen failed for file '" << destNew << "'" << endl;
-    ZYPP_THROW(MediaWriteException(destNew));
+    AutoFREE<char> buf { ::strdup( (*destNew).c_str() ) };
+    if( ! buf )
+    {
+      ERR << "out of memory for temp file name" << endl;
+      ZYPP_THROW(MediaSystemException(getFileUrl(filename), "out of memory for temp file name"));
+    }
+
+    AutoFD tmp_fd { ::mkostemp( buf, O_CLOEXEC ) };
+    if( tmp_fd == -1 )
+    {
+      ERR << "mkstemp failed for file '" << destNew << "'" << endl;
+      ZYPP_THROW(MediaWriteException(destNew));
+    }
+    destNew = ManagedFile( (*buf), filesystem::unlink );
+
+    file = ::fdopen( tmp_fd, "we" );
+    if ( ! file )
+    {
+      ERR << "fopen failed for file '" << destNew << "'" << endl;
+      ZYPP_THROW(MediaWriteException(destNew));
+    }
+    tmp_fd.resetDispose();     // don't close it here! ::fdopen moved ownership to file
   }
+
   DBG << "dest: " << dest << endl;
   DBG << "temp: " << destNew << endl;
 
@@ -1347,15 +1349,13 @@ void MediaMultiCurl::doGetFileCopy( const Pathname & filename , const Pathname &
   curl_easy_setopt(_curl, CURLOPT_HTTPHEADER, _customHeadersMetalink);
   // change to our own progress funcion
   curl_easy_setopt(_curl, CURLOPT_PROGRESSFUNCTION, &progressCallback);
-  curl_easy_setopt(_curl, CURLOPT_PRIVATE, file);
+  curl_easy_setopt(_curl, CURLOPT_PRIVATE, (*file) );  // important to pass the FILE* explicitly (passing through varargs)
   try
     {
       MediaCurl::doGetFileCopyFile(filename, dest, file, report, expectedFileSize_r, options);
     }
   catch (Exception &ex)
     {
-      ::fclose(file);
-      filesystem::unlink(destNew);
       curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
       curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, 0L);
       curl_easy_setopt(_curl, CURLOPT_HTTPHEADER, _customHeaders);
@@ -1398,24 +1398,23 @@ void MediaMultiCurl::doGetFileCopy( const Pathname & filename , const Pathname &
       // some proxies do not store the content type, so also look at the file to find
       // out if we received a metalink (bnc#649925)
       fflush(file);
-      if (looks_like_metalink(Pathname(destNew)))
+      if (looks_like_metalink(destNew))
        ismetalink = true;
     }
 
   if (ismetalink)
     {
       bool userabort = false;
-      fclose(file);
-      file = NULL;
       Pathname failedFile = ZConfig::instance().repoCachePath() / "MultiCurl.failed";
+      file = nullptr;  // explicitly close destNew before the parser reads it.
       try
        {
          MetaLinkParser mlp;
-         mlp.parse(Pathname(destNew));
+         mlp.parse(destNew);
          MediaBlockList bl = mlp.getBlockList();
          vector<Url> urls = mlp.getUrls();
          XXX << bl << endl;
-         file = fopen(destNew.c_str(), "w+e");
+         file = fopen((*destNew).c_str(), "w+e");
          if (!file)
            ZYPP_THROW(MediaWriteException(destNew));
          if (PathInfo(target).isExist())
@@ -1454,9 +1453,7 @@ void MediaMultiCurl::doGetFileCopy( const Pathname & filename , const Pathname &
       catch (Exception &ex)
        {
          // something went wrong. fall back to normal download
-         if (file)
-           fclose(file);
-         file = NULL;
+         file = nullptr;       // explicitly close destNew before moving it
          if (PathInfo(destNew).size() >= 63336)
            {
              ::unlink(failedFile.asString().c_str());
@@ -1464,10 +1461,9 @@ void MediaMultiCurl::doGetFileCopy( const Pathname & filename , const Pathname &
            }
          if (userabort)
            {
-             filesystem::unlink(destNew);
              ZYPP_RETHROW(ex);
            }
-         file = fopen(destNew.c_str(), "w+e");
+         file = fopen((*destNew).c_str(), "w+e");
          if (!file)
            ZYPP_THROW(MediaWriteException(destNew));
          MediaCurl::doGetFileCopyFile(filename, dest, file, report, expectedFileSize_r, options | OPTION_NO_REPORT_START);
@@ -1478,17 +1474,22 @@ void MediaMultiCurl::doGetFileCopy( const Pathname & filename , const Pathname &
     {
       ERR << "Failed to chmod file " << destNew << endl;
     }
+
+  file.resetDispose(); // we're going to close it manually here
   if (::fclose(file))
     {
       filesystem::unlink(destNew);
       ERR << "Fclose failed for file '" << destNew << "'" << endl;
       ZYPP_THROW(MediaWriteException(destNew));
     }
+
   if ( rename( destNew, dest ) != 0 )
     {
       ERR << "Rename failed" << endl;
       ZYPP_THROW(MediaWriteException(dest));
     }
+  destNew.resetDispose();      // no more need to unlink it
+
   DBG << "done: " << PathInfo(dest) << endl;
 }
 
index 48c3c98..3fd990b 100644 (file)
@@ -1127,6 +1127,8 @@ namespace zypp
     {
       // ----------------------------------------------------------------- //
       ZYppCommitPolicy policy_r( policy_rX );
+      bool explicitDryRun = policy_r.dryRun(); // explicit dry run will trigger a fileconflict check, implicit (download-only) not.
+
       ShutdownLock lck("Zypp commit running.");
 
       // Fake outstanding YCP fix: Honour restriction to media 1
@@ -1346,12 +1348,20 @@ namespace zypp
          else
          {
            DBG << "dryRun/downloadOnly: Not installing/deleting anything." << endl;
+           if ( explicitDryRun ) {
+             // if cache is preloaded, check for file conflicts
+             commitFindFileConflicts( policy_r, result );
+           }
          }
        }
       }
       else
       {
         DBG << "dryRun: Not downloading/installing/deleting anything." << endl;
+       if ( explicitDryRun ) {
+         // if cache is preloaded, check for file conflicts
+         commitFindFileConflicts( policy_r, result );
+       }
       }
 
       ///////////////////////////////////////////////////////////////////
@@ -1615,11 +1625,18 @@ namespace zypp
                 }
                 else
                 {
-                  PathInfo referenceFile( Pathname::assertprefix( _root, Pathname( "/etc/products.d" ) ) / referenceFilename );
-                  if ( ! referenceFile.isFile() || filesystem::unlink( referenceFile.path() ) != 0 )
-                  {
-                    ERR << "Delete orphan product failed: " << referenceFile << endl;
-                  }
+                 Pathname referencePath { Pathname("/etc/products.d") / referenceFilename };   // no root prefix for rpmdb lookup!
+                 if ( ! rpm().hasFile( referencePath.asString() ) )
+                 {
+                   // If it's not owned by a package, we can delete it.
+                   referencePath = Pathname::assertprefix( _root, referencePath );     // now add a root prefix
+                   if ( filesystem::unlink( referencePath ) != 0 )
+                     ERR << "Delete orphan product failed: " << referencePath << endl;
+                 }
+                 else
+                 {
+                   WAR << "Won't remove orphan product: '/etc/products.d/" << referenceFilename << "' is owned by a package." << endl;
+                 }
                 }
               }
             }
diff --git a/zypp/target/hal/HalContext.cc b/zypp/target/hal/HalContext.cc
deleted file mode 100644 (file)
index 4c21ff8..0000000
+++ /dev/null
@@ -1,1269 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/target/hal/HalContext.cc
- *
- *  \brief Hardware abstaction layer library wrapper implementation.
- */
-#include "zypp/base/Gettext.h"
-#include "zypp/target/hal/HalException.h"
-//////////////////////////////////////////////////////////////////////
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-  namespace target
-  { //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-    namespace hal
-    { ////////////////////////////////////////////////////////////////
-        HalException::HalException()
-          : zypp::Exception(_("Hal Exception"))
-        {}
-        HalException::HalException(const std::string &msg_r)
-          : zypp::Exception(_("Hal Exception"))
-          , e_name()
-          , e_msg(msg_r)
-        {}
-        HalException::HalException(const std::string &err_name, const std::string &err_msg)
-          : zypp::Exception(_("Hal Exception"))
-          , e_name(err_name)
-          , e_msg(err_msg)
-        {}
-        NoHalException::NoHalException()
-       : Exception(_("Sorry, but this version of libzypp was built without HAL support."))
-      {}
-      ////////////////////////////////////////////////////////////////
-    } // namespace hal
-    //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-  } // namespace target
-  ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-
-#ifndef NO_HAL // disables zypp's HAL dependency
-
-#include "zypp/target/hal/HalContext.h"
-#include "zypp/thread/Mutex.h"
-#include "zypp/thread/MutexLock.h"
-#include "zypp/base/NonCopyable.h"
-#include "zypp/base/Logger.h"
-#include "zypp/base/String.h"
-#include "zypp/base/Gettext.h"
-
-#include <hal/libhal.h>
-#include <hal/libhal-storage.h>
-
-#include <iostream>
-
-using namespace std;
-
-//////////////////////////////////////////////////////////////////////
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-  namespace target
-  { //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-    namespace hal
-    { ////////////////////////////////////////////////////////////////
-
-      using zypp::thread::Mutex;
-      using zypp::thread::MutexLock;
-
-      ////////////////////////////////////////////////////////////////
-      namespace // anonymous
-      { //////////////////////////////////////////////////////////////
-
-
-        //////////////////////////////////////////////////////////////
-        // STATIC
-        /**
-         ** hmm... currently a global one..
-        */
-        static Mutex g_Mutex;
-
-
-        //////////////////////////////////////////////////////////////
-        /**
-         * Internal hal (dbus ) error helper class.
-         */
-        class HalError
-        {
-        public:
-          DBusError error;
-
-          HalError()  { dbus_error_init(&error); }
-          ~HalError() { dbus_error_free(&error); }
-
-          inline bool         isSet() const
-          {
-            return dbus_error_is_set(&error);
-          }
-
-          inline HalException halException(const std::string &msg = std::string()) const
-          {
-            if( isSet() && error.name != NULL && error.message != NULL) {
-              return HalException(error.name, error.message);
-            }
-            else if( !msg.empty()) {
-              return HalException(msg);
-            }
-            else {
-              return HalException();
-            }
-          }
-        };
-
-
-        // -----------------------------------------------------------
-        inline void
-        VERIFY_CONTEXT(const zypp::RW_pointer<HalContext_Impl> &h)
-        {
-          if( !h)
-          {
-            ZYPP_THROW(HalException(_("HalContext not connected")));
-          }
-        }
-
-        // -----------------------------------------------------------
-        inline void
-        VERIFY_DRIVE(const zypp::RW_pointer<HalDrive_Impl> &d)
-        {
-          if( !d)
-          {
-            ZYPP_THROW(HalException(_("HalDrive not initialized")));
-          }
-        }
-
-        // -----------------------------------------------------------
-        inline void
-        VERIFY_VOLUME(const zypp::RW_pointer<HalVolume_Impl> &v)
-        {
-          if( !v)
-          {
-            ZYPP_THROW(HalException(_("HalVolume not initialized")));
-          }
-        }
-
-        //////////////////////////////////////////////////////////////
-      } // anonymous
-      ////////////////////////////////////////////////////////////////
-
-      ////////////////////////////////////////////////////////////////
-      std::ostream &
-      HalException::dumpOn( std::ostream & str ) const
-      {
-        if(!e_name.empty() && !e_msg.empty())
-          return str << msg() << ": " << e_msg << " (" << e_name << ")";
-        else if(!e_msg.empty())
-          return str << msg() << ": " << e_msg;
-        else
-          return str << msg();
-      }
-
-      ////////////////////////////////////////////////////////////////
-      class HalContext_Impl
-      {
-      public:
-        HalContext_Impl();
-        ~HalContext_Impl();
-
-        DBusConnection *conn;
-        LibHalContext  *hctx;
-        bool            pcon; // private connection
-      };
-
-
-      ////////////////////////////////////////////////////////////////
-      class HalDrive_Impl
-      {
-      public:
-        zypp::RW_pointer<HalContext_Impl>  hal;
-        LibHalDrive                       *drv;
-
-        HalDrive_Impl()
-          : hal(), drv(NULL)
-        {
-        }
-
-        HalDrive_Impl(const zypp::RW_pointer<HalContext_Impl> &r,
-                      LibHalDrive *d)
-          : hal(r), drv(d)
-        {
-        }
-
-        ~HalDrive_Impl()
-        {
-          if( drv)
-            libhal_drive_free(drv);
-        }
-      };
-
-
-      ////////////////////////////////////////////////////////////////
-      class HalVolume_Impl
-      {
-      public:
-        LibHalVolume *vol;
-
-        HalVolume_Impl(LibHalVolume *v=NULL)
-          : vol(v)
-        {
-        }
-
-        ~HalVolume_Impl()
-        {
-          if( vol)
-            libhal_volume_free(vol);
-        }
-      };
-
-
-      ////////////////////////////////////////////////////////////////
-      HalContext_Impl::HalContext_Impl()
-        : conn(NULL)
-        , hctx(NULL)
-        , pcon(false) // we allways use shared connections at the moment
-      {
-        HalError err;
-
-        if( pcon)
-          conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err.error);
-        else
-          conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err.error);
-        if( !conn) {
-          ZYPP_THROW(err.halException(
-            _("Unable to create dbus connection")
-          ));
-        }
-
-        hctx = libhal_ctx_new();
-        if( !hctx)
-        {
-          if( pcon)
-              dbus_connection_close(conn);
-          dbus_connection_unref(conn);
-          conn = NULL;
-
-          ZYPP_THROW(HalException(
-            _("libhal_ctx_new: Can't create libhal context")
-          ));
-        }
-
-        if( !libhal_ctx_set_dbus_connection(hctx, conn))
-        {
-          libhal_ctx_free(hctx);
-          hctx = NULL;
-
-          if( pcon)
-            dbus_connection_close(conn);
-          dbus_connection_unref(conn);
-          conn = NULL;
-
-          ZYPP_THROW(HalException(
-            _("libhal_set_dbus_connection: Can't set dbus connection")
-          ));
-        }
-
-        if( !libhal_ctx_init(hctx, &err.error))
-        {
-          libhal_ctx_free(hctx);
-          hctx = NULL;
-
-          if( pcon)
-            dbus_connection_close(conn);
-          dbus_connection_unref(conn);
-          conn = NULL;
-
-          ZYPP_THROW(err.halException(
-            _("Unable to initalize HAL context -- hald not running?")
-          ));
-        }
-      }
-
-      // -------------------------------------------------------------
-      HalContext_Impl::~HalContext_Impl()
-      {
-        if( hctx)
-        {
-          HalError err;
-          libhal_ctx_shutdown(hctx, &err.error);
-          libhal_ctx_free( hctx);
-        }
-        if( conn)
-        {
-          if( pcon)
-            dbus_connection_close(conn);
-          dbus_connection_unref(conn);
-        }
-      }
-
-
-      ////////////////////////////////////////////////////////////////
-      HalContext::HalContext(bool autoconnect)
-        : h_impl( NULL)
-      {
-        MutexLock lock(g_Mutex);
-
-        if( autoconnect)
-          h_impl.reset( new HalContext_Impl());
-      }
-
-      // -------------------------------------------------------------
-      HalContext::HalContext(const HalContext &context)
-        : h_impl( NULL)
-      {
-        MutexLock lock(g_Mutex);
-
-        zypp::RW_pointer<HalContext_Impl>(context.h_impl).swap(h_impl);
-      }
-
-      // -------------------------------------------------------------
-      HalContext::~HalContext()
-      {
-        MutexLock  lock(g_Mutex);
-
-        h_impl.reset();
-      }
-
-      // --------------------------------------------------------------
-      HalContext &
-      HalContext::operator=(const HalContext &context)
-      {
-        MutexLock  lock(g_Mutex);
-
-        if( this == &context)
-          return *this;
-
-        zypp::RW_pointer<HalContext_Impl>(context.h_impl).swap(h_impl);
-        return *this;
-      }
-
-      // --------------------------------------------------------------
-      HalContext::operator HalContext::bool_type() const
-      {
-        MutexLock  lock(g_Mutex);
-
-        return h_impl;
-      }
-
-      // --------------------------------------------------------------
-      void
-      HalContext::connect()
-      {
-        MutexLock lock(g_Mutex);
-
-        if( !h_impl)
-          h_impl.reset( new HalContext_Impl());
-      }
-
-      // --------------------------------------------------------------
-      std::vector<std::string>
-      HalContext::getAllDevices() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError   err;
-        char     **names;
-        int        count = 0;
-
-        names = libhal_get_all_devices( h_impl->hctx, &count, &err.error);
-        if( !names)
-        {
-          ZYPP_THROW(err.halException());
-        }
-
-        std::vector<std::string> ret(names, names + count);
-        libhal_free_string_array(names);
-        return ret;
-      }
-
-      // --------------------------------------------------------------
-      HalDrive
-      HalContext::getDriveFromUDI(const std::string &udi) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        LibHalDrive *drv = libhal_drive_from_udi(h_impl->hctx, udi.c_str());
-        if( drv != NULL)
-          return HalDrive(new HalDrive_Impl( h_impl, drv));
-        else
-          return HalDrive();
-      }
-
-      // --------------------------------------------------------------
-      HalVolume
-      HalContext::getVolumeFromUDI(const std::string &udi) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        LibHalVolume *vol = libhal_volume_from_udi(h_impl->hctx, udi.c_str());
-        if( vol)
-          return HalVolume( new HalVolume_Impl(vol));
-        else
-          return HalVolume();
-      }
-
-      // --------------------------------------------------------------
-      HalVolume
-      HalContext::getVolumeFromDeviceFile(const std::string &device_file) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        LibHalVolume *vol = libhal_volume_from_device_file(h_impl->hctx,
-                                                           device_file.c_str());
-        if( vol)
-          return HalVolume( new HalVolume_Impl(vol));
-        else
-          return HalVolume();
-      }
-
-      // --------------------------------------------------------------
-      std::vector<std::string>
-      HalContext::findDevicesByCapability(const std::string &capability) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError   err;
-        char     **names;
-        int        count = 0;
-
-        names = libhal_find_device_by_capability(h_impl->hctx,
-                                                 capability.c_str(),
-                                                 &count, &err.error);
-        if( !names)
-        {
-          ZYPP_THROW(err.halException());
-        }
-
-        std::vector<std::string> ret(names, names + count);
-        libhal_free_string_array(names);
-        return ret;
-      }
-
-      // --------------------------------------------------------------
-      bool
-      HalContext::getDevicePropertyBool  (const std::string &udi,
-                                          const std::string &key) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        dbus_bool_t   ret;
-
-        ret = libhal_device_get_property_bool  (h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                &err.error);
-        if( err.isSet())
-        {
-          ZYPP_THROW(err.halException());
-        }
-        return ret;
-      }
-
-      // --------------------------------------------------------------
-      int32_t
-      HalContext::getDevicePropertyInt32 (const std::string &udi,
-                                          const std::string &key) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        dbus_int32_t  ret;
-
-        ret = libhal_device_get_property_int   (h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                &err.error);
-        if( err.isSet())
-        {
-          ZYPP_THROW(err.halException());
-        }
-        return ret;
-      }
-
-      // --------------------------------------------------------------
-      uint64_t
-      HalContext::getDevicePropertyUInt64(const std::string &udi,
-                                          const std::string &key) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        dbus_uint64_t ret;
-
-        ret = libhal_device_get_property_uint64(h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                &err.error);
-        if( err.isSet())
-        {
-          ZYPP_THROW(err.halException());
-        }
-        return ret;
-      }
-
-      // --------------------------------------------------------------
-      double
-      HalContext::getDevicePropertyDouble(const std::string &udi,
-                                          const std::string &key) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        double        ret;
-
-        ret = libhal_device_get_property_bool  (h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                &err.error);
-        if( err.isSet())
-        {
-          ZYPP_THROW(err.halException());
-        }
-        return ret;
-      }
-
-
-      // --------------------------------------------------------------
-      std::string
-      HalContext::getDevicePropertyString(const std::string &udi,
-                                          const std::string &key) const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        std::string   ret;
-        char         *ptr;
-
-        ptr = libhal_device_get_property_string(h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                &err.error);
-        if( err.isSet())
-        {
-          ZYPP_THROW(err.halException());
-        }
-        if( ptr != NULL)
-        {
-          ret = ptr;
-          free(ptr);
-        }
-        return ret;
-      }
-
-      // --------------------------------------------------------------
-      void
-      HalContext::setDevicePropertyBool  (const std::string &udi,
-                                          const std::string &key,
-                                          bool               value)
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        dbus_bool_t   ret;
-
-        ret = libhal_device_set_property_bool  (h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                value ? 1 : 0,
-                                                &err.error);
-        if( !ret)
-        {
-          ZYPP_THROW(err.halException());
-        }
-      }
-
-      // --------------------------------------------------------------
-      void
-      HalContext::setDevicePropertyInt32 (const std::string &udi,
-                                          const std::string &key,
-                                          int32_t            value)
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        dbus_bool_t   ret;
-
-        ret = libhal_device_set_property_int   (h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                value,
-                                                &err.error);
-        if( !ret)
-        {
-          ZYPP_THROW(err.halException());
-        }
-      }
-
-      // --------------------------------------------------------------
-      void
-      HalContext::setDevicePropertyUInt64(const std::string &udi,
-                                          const std::string &key,
-                                          uint64_t           value)
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        dbus_bool_t   ret;
-
-        ret = libhal_device_set_property_uint64(h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                value,
-                                                &err.error);
-        if( !ret)
-        {
-          ZYPP_THROW(err.halException());
-        }
-      }
-
-      // --------------------------------------------------------------
-      void
-      HalContext::setDevicePropertyDouble(const std::string &udi,
-                                          const std::string &key,
-                                          double             value)
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        dbus_bool_t   ret;
-
-        ret = libhal_device_set_property_double(h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                value,
-                                                &err.error);
-        if( !ret)
-        {
-          ZYPP_THROW(err.halException());
-        }
-      }
-
-      // --------------------------------------------------------------
-      void
-      HalContext::setDevicePropertyString(const std::string &udi,
-                                          const std::string &key,
-                                          const std::string &value)
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        dbus_bool_t   ret;
-
-        ret = libhal_device_set_property_string(h_impl->hctx,
-                                                udi.c_str(),
-                                                key.c_str(),
-                                                value.c_str(),
-                                                &err.error);
-        if( !ret)
-        {
-          ZYPP_THROW(err.halException());
-        }
-      }
-
-      // --------------------------------------------------------------
-      void
-      HalContext::removeDeviceProperty(const std::string &udi,
-                                       const std::string &key)
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_CONTEXT(h_impl);
-
-        HalError      err;
-        dbus_bool_t   ret;
-
-        ret = libhal_device_remove_property(h_impl->hctx,
-                                            udi.c_str(),
-                                            key.c_str(),
-                                            &err.error);
-        if( !ret)
-        {
-          ZYPP_THROW(err.halException());
-        }
-      }
-
-      ////////////////////////////////////////////////////////////////
-      HalDrive::HalDrive()
-        : d_impl( NULL)
-      {
-      }
-
-      // --------------------------------------------------------------
-      HalDrive::HalDrive(HalDrive_Impl *impl)
-        : d_impl( NULL)
-      {
-        MutexLock  lock(g_Mutex);
-
-        d_impl.reset(impl);
-      }
-
-      // --------------------------------------------------------------
-      HalDrive::HalDrive(const HalDrive &drive)
-        : d_impl( NULL)
-      {
-        MutexLock  lock(g_Mutex);
-
-        zypp::RW_pointer<HalDrive_Impl>(drive.d_impl).swap(d_impl);
-      }
-
-      // --------------------------------------------------------------
-      HalDrive::~HalDrive()
-      {
-        MutexLock  lock(g_Mutex);
-
-        d_impl.reset();
-      }
-
-      // --------------------------------------------------------------
-      HalDrive &
-      HalDrive::operator=(const HalDrive &drive)
-      {
-        MutexLock  lock(g_Mutex);
-
-        if( this == &drive)
-          return *this;
-
-        zypp::RW_pointer<HalDrive_Impl>(drive.d_impl).swap(d_impl);
-        return *this;
-      }
-
-      // --------------------------------------------------------------
-      HalDrive::operator HalDrive::bool_type() const
-      {
-        MutexLock  lock(g_Mutex);
-
-        return d_impl;
-      }
-
-      // --------------------------------------------------------------
-      std::string
-      HalDrive::getUDI() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_DRIVE(d_impl);
-
-        const char *ptr = libhal_drive_get_udi(d_impl->drv);
-        return std::string(ptr ? ptr : "");
-      }
-
-      // --------------------------------------------------------------
-      std::string
-      HalDrive::getTypeName() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_DRIVE(d_impl);
-
-        const char *ptr = libhal_drive_get_type_textual(d_impl->drv);
-        return std::string(ptr ? ptr : "");
-      }
-
-      // --------------------------------------------------------------
-      std::string
-      HalDrive::getDeviceFile() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_DRIVE(d_impl);
-
-        return std::string(libhal_drive_get_device_file(d_impl->drv));
-      }
-
-      // --------------------------------------------------------------
-      unsigned int
-      HalDrive::getDeviceMajor() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_DRIVE(d_impl);
-
-        return libhal_drive_get_device_major(d_impl->drv);
-      }
-
-      // --------------------------------------------------------------
-      unsigned int
-      HalDrive::getDeviceMinor() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_DRIVE(d_impl);
-
-        return libhal_drive_get_device_minor(d_impl->drv);
-      }
-
-      // --------------------------------------------------------------
-      bool
-      HalDrive::usesRemovableMedia() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_DRIVE(d_impl);
-
-        return libhal_drive_uses_removable_media(d_impl->drv);
-      }
-
-      // --------------------------------------------------------------
-      std::vector<std::string>
-      HalDrive::getCdromCapabilityNames() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_DRIVE(d_impl);
-
-        std::vector<std::string> ret;
-        LibHalDriveCdromCaps     caps;
-
-        /*
-        ** FIXME: there is no textual variant :-(
-        **        using property key names...
-        */
-        caps = libhal_drive_get_cdrom_caps(d_impl->drv);
-
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDROM)
-          ret.push_back("cdrom");
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDR)
-          ret.push_back("cdr");
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_CDRW)
-          ret.push_back("cdrw");
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRAM)
-          ret.push_back("dvdram");
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDROM)
-          ret.push_back("dvd");
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDR)
-          ret.push_back("dvdr");
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRW)
-          ret.push_back("dvdrw");
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSR)
-          ret.push_back("dvdplusr");
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRW)
-          ret.push_back("dvdplusrw");
-        if(caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRDL)
-          ret.push_back("dvdplusrdl");
-
-        return ret;
-
-#if 0
-        if( libhal_drive_get_type(d_impl->drv) != LIBHAL_DRIVE_TYPE_CDROM)
-          ZYPP_THROW(HalException(_("Not a CDROM drive")));
-
-        /*
-        ** FIXME: we use property keys matching
-        **          "storage.cdrom.cd*"
-        **          "storage.cdrom.dvd*"
-        ** but this may print other bool keys,
-        ** that are not CDROM caps.
-        */
-        LibHalPropertySet         *props;
-        HalError                   err;
-
-        props = libhal_device_get_all_properties(d_impl->hal->hctx,
-                                                 getUDI().c_str(),
-                                                 &err.error);
-        if( !props)
-          ZYPP_THROW(err.halException());
-
-        std::vector<std::string>   ret(1, getTypeName());
-        std::string                key;
-        std::string                dvd("storage.cdrom.dvd");
-        std::string                cd ("storage.cdrom.cd");
-
-        LibHalPropertySetIterator  it;
-        for(libhal_psi_init(&it, props);
-            libhal_psi_has_more(&it);
-            libhal_psi_next(&it))
-        {
-          if( libhal_psi_get_type(&it) == LIBHAL_PROPERTY_TYPE_BOOLEAN &&
-              libhal_psi_get_bool(&it))
-          {
-            key = libhal_psi_get_key(&it);
-            if( key.compare(0, cd.size(), cd) == 0)
-            {
-              ret.push_back(key.substr(sizeof("storage.cdrom.")-1));
-            }
-            else
-            if( key.compare(0, dvd.size(), dvd) == 0)
-            {
-              ret.push_back(key.substr(sizeof("storage.cdrom.")-1));
-            }
-          }
-        }
-        libhal_free_property_set(props);
-
-        return ret;
-#endif
-      }
-
-      // --------------------------------------------------------------
-      std::vector<std::string>
-      HalDrive::findAllVolumes() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_DRIVE(d_impl);
-
-        char     **names;
-        int        count = 0;
-
-        names = libhal_drive_find_all_volumes(d_impl->hal->hctx,
-                                              d_impl->drv,
-                                              &count);
-
-        std::vector<std::string> ret;
-        ret.assign(names, names + count);
-        libhal_free_string_array(names);
-        return ret;
-      }
-
-
-      ////////////////////////////////////////////////////////////////
-      HalVolume::HalVolume()
-        : v_impl( NULL)
-      {}
-
-      HalVolume::HalVolume(HalVolume_Impl *impl)
-        : v_impl( NULL)
-      {
-        MutexLock  lock(g_Mutex);
-
-        v_impl.reset(impl);
-      }
-
-      // --------------------------------------------------------------
-      HalVolume::HalVolume(const HalVolume &volume)
-        : v_impl( NULL)
-      {
-        MutexLock  lock(g_Mutex);
-
-        zypp::RW_pointer<HalVolume_Impl>(volume.v_impl).swap(v_impl);
-      }
-
-      // --------------------------------------------------------------
-      HalVolume::~HalVolume()
-      {
-        MutexLock  lock(g_Mutex);
-
-        v_impl.reset();
-      }
-
-      // --------------------------------------------------------------
-      HalVolume &
-      HalVolume::operator=(const HalVolume &volume)
-      {
-        MutexLock  lock(g_Mutex);
-
-        if( this == &volume)
-          return *this;
-
-        zypp::RW_pointer<HalVolume_Impl>(volume.v_impl).swap(v_impl);
-        return *this;
-      }
-
-      // --------------------------------------------------------------
-      HalVolume::operator HalVolume::bool_type() const
-      {
-        MutexLock  lock(g_Mutex);
-
-        return v_impl;
-      }
-
-      // --------------------------------------------------------------
-      std::string
-      HalVolume::getUDI() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_VOLUME(v_impl);
-
-        const char *ptr = libhal_volume_get_udi(v_impl->vol);
-        return std::string(ptr ? ptr : "");
-      }
-
-      // --------------------------------------------------------------
-      std::string
-      HalVolume::getDeviceFile() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_VOLUME(v_impl);
-
-        return std::string(libhal_volume_get_device_file(v_impl->vol));
-      }
-
-      // --------------------------------------------------------------
-      unsigned int
-      HalVolume::getDeviceMajor() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_VOLUME(v_impl);
-
-        return libhal_volume_get_device_major(v_impl->vol);
-      }
-
-      // --------------------------------------------------------------
-      unsigned int
-      HalVolume::getDeviceMinor() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_VOLUME(v_impl);
-
-        return libhal_volume_get_device_minor(v_impl->vol);
-      }
-
-      // --------------------------------------------------------------
-      bool
-      HalVolume::isDisc() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_VOLUME(v_impl);
-
-        return libhal_volume_is_disc(v_impl->vol);
-      }
-
-      // --------------------------------------------------------------
-      bool
-      HalVolume::isPartition() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_VOLUME(v_impl);
-
-        return libhal_volume_is_partition(v_impl->vol);
-      }
-
-      // --------------------------------------------------------------
-      bool
-      HalVolume::isMounted() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_VOLUME(v_impl);
-
-        return libhal_volume_is_mounted(v_impl->vol);
-      }
-
-      // --------------------------------------------------------------
-      std::string
-      HalVolume::getFSType() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_VOLUME(v_impl);
-
-        return std::string( libhal_volume_get_fstype(v_impl->vol));
-      }
-
-      // --------------------------------------------------------------
-      std::string
-      HalVolume::getFSUsage() const
-      {
-        MutexLock  lock(g_Mutex);
-        VERIFY_VOLUME(v_impl);
-
-        LibHalVolumeUsage usage( libhal_volume_get_fsusage(v_impl->vol));
-        std::string       ret;
-        switch( usage)
-        {
-          case  LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM:
-            ret = "filesystem";
-          break;
-          case LIBHAL_VOLUME_USAGE_PARTITION_TABLE:
-            ret = "partitiontable";
-          break;
-          case LIBHAL_VOLUME_USAGE_RAID_MEMBER:
-            return "raid";
-          break;
-          case LIBHAL_VOLUME_USAGE_CRYPTO:
-            ret = "crypto";
-          break;
-          case LIBHAL_VOLUME_USAGE_UNKNOWN:
-          default:
-          break;
-        }
-        return ret;
-      }
-
-      // --------------------------------------------------------------
-      std::string
-      HalVolume::getMountPoint() const
-      {
-        VERIFY_VOLUME(v_impl);
-
-        return std::string( libhal_volume_get_mount_point(v_impl->vol));
-      }
-
-
-      ////////////////////////////////////////////////////////////////
-    } // namespace hal
-    //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-  } // namespace target
-  ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-#else // NO_HAL
-#include "zypp/target/hal/HalContext.h"
-#include "zypp/target/hal/HalException.h"
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-  namespace target
-  { //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-    namespace hal
-    { ////////////////////////////////////////////////////////////////
-
-      std::ostream &
-      HalException::dumpOn( std::ostream & str ) const
-      { return str; }
-
-      // --------------------------------------------------------------
-      class HalContext_Impl
-      {};
-      class HalDrive_Impl
-      {};
-      class HalVolume_Impl
-      {};
-
-      // --------------------------------------------------------------
-      HalContext::HalContext(bool)
-      { ZYPP_THROW( NoHalException() ); }
-      HalContext::~HalContext()
-      {}
-      HalContext &
-      HalContext::operator=(const HalContext &)
-      { return *this; }
-      HalContext::operator HalContext::bool_type() const
-      { return 0; }
-      void
-      HalContext::connect()
-      {}
-      std::vector<std::string>
-      HalContext::getAllDevices() const
-      { return std::vector<std::string>(); }
-      HalDrive
-      HalContext::getDriveFromUDI(const std::string &) const
-      { return HalDrive(); }
-      HalVolume
-      HalContext::getVolumeFromUDI(const std::string &) const
-      { return HalVolume(); }
-      HalVolume
-      HalContext::getVolumeFromDeviceFile(const std::string &) const
-      { return HalVolume(); }
-      std::vector<std::string>
-      HalContext::findDevicesByCapability(const std::string &) const
-      { return std::vector<std::string>(); }
-      bool
-      HalContext::getDevicePropertyBool(const std::string &, const std::string &) const
-      { return false; }
-      void
-      HalContext::setDevicePropertyBool  (const std::string &, const std::string &, bool value)
-      {}
-      void
-      HalContext::removeDeviceProperty(const std::string &, const std::string &)
-      {}
-      std::string
-      HalContext::getDevicePropertyString(const std::string &, const std::string &) const
-      { return ""; }
-      // --------------------------------------------------------------
-      HalDrive::HalDrive()
-      { ZYPP_THROW( NoHalException() ); }
-      HalDrive::~HalDrive()
-      {}
-      HalDrive &
-      HalDrive::operator=(const HalDrive &)
-      { return *this; }
-      HalDrive::operator HalDrive::bool_type() const
-      { return 0; }
-      std::string
-      HalDrive::getUDI() const
-      { return std::string(); }
-      std::string
-      HalDrive::getTypeName() const
-      { return std::string(); }
-      std::string
-      HalDrive::getDeviceFile() const
-      { return std::string(); }
-      unsigned int
-      HalDrive::getDeviceMinor() const
-      { return 0; }
-      unsigned int
-      HalDrive::getDeviceMajor() const
-      { return 0; }
-      bool
-      HalDrive::usesRemovableMedia() const
-      { return false; }
-      std::vector<std::string>
-      HalDrive::getCdromCapabilityNames() const
-      { return std::vector<std::string>(); }
-      std::vector<std::string>
-      HalDrive::findAllVolumes() const
-      { return std::vector<std::string>(); }
-
-      // --------------------------------------------------------------
-      HalVolume::HalVolume()
-      { ZYPP_THROW( NoHalException() ); }
-      HalVolume::~HalVolume()
-      {}
-      HalVolume &
-      HalVolume::operator=(const HalVolume &)
-      { return *this; }
-      HalVolume::operator HalVolume::bool_type() const
-      { return 0; }
-      std::string
-      HalVolume::getUDI() const
-      { return std::string(); }
-      std::string
-      HalVolume::getDeviceFile() const
-      { return std::string(); }
-      unsigned int
-      HalVolume::getDeviceMinor() const
-      { return 0; }
-      unsigned int
-      HalVolume::getDeviceMajor() const
-      { return 0; }
-      bool
-      HalVolume::isDisc() const
-      { return false; }
-      bool
-      HalVolume::isPartition() const
-      { return false; }
-      bool
-      HalVolume::isMounted() const
-      { return false; }
-      std::string
-      HalVolume::getFSType() const
-      { return std::string(); }
-      std::string
-      HalVolume::getFSUsage() const
-      { return std::string(); }
-      std::string
-      HalVolume::getMountPoint() const
-      { return std::string(); }
-
-      ////////////////////////////////////////////////////////////////
-    } // namespace hal
-    //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-  } // namespace target
-  ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-#endif // NO_HAL
-
-/*
-** vim: set ts=2 sts=2 sw=2 ai et:
-*/
diff --git a/zypp/target/hal/HalContext.h b/zypp/target/hal/HalContext.h
deleted file mode 100644 (file)
index d32a26a..0000000
+++ /dev/null
@@ -1,346 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/target/hal/HalContext.h
- *
- *  \brief Hardware abstaction layer library wrapper.
- */
-#ifndef ZYPP_TARGET_HAL_HALCONTEXT_H
-#define ZYPP_TARGET_HAL_HALCONTEXT_H
-
-#include "zypp/target/hal/HalException.h"
-#include "zypp/base/PtrTypes.h"
-#include <string>
-#include <vector>
-#include <stdint.h>
-
-//////////////////////////////////////////////////////////////////////
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-  namespace target
-  { //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-    namespace hal
-    { ////////////////////////////////////////////////////////////////
-
-
-      // -------------------------------------------------------------
-      /** @{
-       * Forward declarations.
-       */
-      class HalDrive;
-      class HalVolume;
-
-      class HalDrive_Impl;
-      class HalVolume_Impl;
-      class HalContext_Impl;
-      /** }@ */
-
-
-      ////////////////////////////////////////////////////////////////
-      //
-      // CLASS NAME : HalContext
-      //
-      /** Hardware abstaction layer context.
-       *
-       * Hal context wrapper. It manages the dbus connection and is
-       * the entry point to query drives, volumes and other information.
-       *
-       * @todo: wrap more functions.
-       */
-      class HalContext
-      {
-      public:
-        typedef
-        zypp::RW_pointer<HalContext_Impl>::unspecified_bool_type  bool_type;
-
-        HalContext(bool autoconnect=false);
-        HalContext(const HalContext &context);
-        ~HalContext();
-
-        HalContext&
-        operator=(const HalContext &context);
-
-        /**
-         * Verifies if the context is initialized.
-         */
-        operator bool_type() const;
-
-        /**
-         */
-        void
-        connect();
-
-        /**
-         * Retrieve UDI's of all devices.
-         * \return Vector with device UDI's.
-         */
-        std::vector<std::string>
-        getAllDevices() const;
-
-        /**
-         * Construct a HalDrive object for the specified UDI.
-         * \param  The \p udi of the drive.
-         * \return The HalDrive object.
-         */
-        HalDrive
-        getDriveFromUDI(const std::string &udi) const;
-
-        /**
-         * Construct a HalVolume object for the specified UDI.
-         * \param  The \p udi of the volume.
-         * \return The HalVolume object.
-         */
-        HalVolume
-        getVolumeFromUDI(const std::string &udi) const;
-
-        HalVolume
-        getVolumeFromDeviceFile(const std::string &device_file) const;
-
-        /**
-         * Retrieve UDI's of all devices with a capability.
-         * \param  The \p capability name
-         * \return Vector with device UDI's.
-         */
-        std::vector<std::string>
-        findDevicesByCapability(const std::string &capability) const;
-
-        bool
-        getDevicePropertyBool  (const std::string &udi,
-                                const std::string &key) const;
-
-        int32_t
-        getDevicePropertyInt32 (const std::string &udi,
-                                const std::string &key) const;
-
-        uint64_t
-        getDevicePropertyUInt64(const std::string &udi,
-                                const std::string &key) const;
-
-        double
-        getDevicePropertyDouble(const std::string &udi,
-                                const std::string &key) const;
-
-        std::string
-        getDevicePropertyString(const std::string &udi,
-                                const std::string &key) const;
-
-        void
-        setDevicePropertyBool  (const std::string &udi,
-                                const std::string &key,
-                                bool               value);
-
-        void
-        setDevicePropertyInt32 (const std::string &udi,
-                                const std::string &key,
-                                int32_t            value);
-
-        void
-        setDevicePropertyUInt64(const std::string &udi,
-                                const std::string &key,
-                                uint64_t           value);
-
-        void
-        setDevicePropertyDouble(const std::string &udi,
-                                const std::string &key,
-                                double             value);
-
-        void
-        setDevicePropertyString(const std::string &udi,
-                                const std::string &key,
-                                const std::string &value);
-
-        void
-        removeDeviceProperty(const std::string &udi,
-                             const std::string &key);
-
-      private:
-
-        zypp::RW_pointer<HalContext_Impl> h_impl;
-      };
-
-
-      ////////////////////////////////////////////////////////////////
-      //
-      // CLASS NAME : HalDrive
-      //
-      /** Hardware abstaction layer storage drive object.
-       *
-       * @todo: wrap more functions.
-       */
-      class HalDrive
-      {
-      public:
-        typedef
-        zypp::RW_pointer<HalDrive_Impl>::unspecified_bool_type    bool_type;
-
-        HalDrive();
-        HalDrive(const HalDrive &drive);
-        ~HalDrive();
-
-        HalDrive&
-        operator=(const HalDrive &drive);
-
-        operator bool_type() const;
-
-        std::string
-        getUDI() const;
-
-        std::string
-        getTypeName() const;
-
-        /**
-         * \return The drive's device file name.
-         */
-        std::string
-        getDeviceFile() const;
-
-        /**
-         * \return The drive's device file major number.
-         */
-        unsigned int
-        getDeviceMajor() const;
-
-        /**
-         * \return The drive's device minor number.
-         */
-        unsigned int
-        getDeviceMinor() const;
-
-        /**
-         * \return True, if drive uses removable media.
-         */
-        bool
-        usesRemovableMedia() const;
-
-        /*
-        ** Returns the media type names supported by the drive.
-        **
-        ** Since hal does not implement a textual form here, we
-        ** are using the drive type and property names from
-        ** "storage.cdrom.*" namespace:
-        **   cdrom, cdr, cdrw, dvd, dvdr, dvdrw, dvdram,
-        **   dvdplusr, dvdplusrw, dvdplusrdl
-        **
-        ** FIXME: Should we provide own LibHalDriveCdromCaps?
-        */
-        std::vector<std::string>
-        getCdromCapabilityNames() const;
-
-        /**
-         * Retrieve UDI's of all volumes of this drive.
-         * \return Vector with volume UDI's.
-         */
-        std::vector<std::string>
-        findAllVolumes() const;
-
-      private:
-        friend class HalContext;
-
-        HalDrive(HalDrive_Impl *impl);
-
-        zypp::RW_pointer<HalDrive_Impl>   d_impl;
-      };
-
-
-      ////////////////////////////////////////////////////////////////
-      //
-      // CLASS NAME : HalVolume
-      //
-      /** Hardware abstaction layer storage volume object.
-       *
-       * @todo: wrap more functions.
-       */
-      class HalVolume
-      {
-      public:
-        typedef
-        zypp::RW_pointer<HalVolume_Impl>::unspecified_bool_type   bool_type;
-
-        HalVolume();
-        HalVolume(const HalVolume &volume);
-        ~HalVolume();
-
-        HalVolume&
-        operator=(const HalVolume &volume);
-
-        operator bool_type() const;
-
-        std::string
-        getUDI() const;
-
-        /**
-         * \return The Volume drive's device file name.
-         */
-        std::string
-        getDeviceFile() const;
-
-        /**
-         * \return The Volume drive's device major number.
-         */
-        unsigned int
-        getDeviceMajor() const;
-
-        /**
-         * \return The Volume drive's device minor number.
-         */
-        unsigned int
-        getDeviceMinor() const;
-
-        bool
-        isDisc() const;
-
-        bool
-        isPartition() const;
-
-        bool
-        isMounted() const;
-
-        /**
-         * \return The filesystem name on the volume.
-         */
-        std::string
-        getFSType() const;
-
-        /**
-         * \return The filesystem usage purpose.
-         */
-        std::string
-        getFSUsage() const;
-
-        /**
-         * \return The mount point of the volume.
-         */
-        std::string
-        getMountPoint() const;
-
-      private:
-        friend class HalContext;
-        friend class HalDrive;
-        HalVolume(HalVolume_Impl *impl);
-
-        zypp::RW_pointer<HalVolume_Impl>  v_impl;
-      };
-
-
-      ////////////////////////////////////////////////////////////////
-    } // namespace hal
-    //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-  } // namespace target
-  ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-
-#endif // ZYPP_TARGET_HAL_HALCONTEXT_H
-
-/*
-** vim: set ts=2 sts=2 sw=2 ai et:
-*/
diff --git a/zypp/target/hal/HalException.h b/zypp/target/hal/HalException.h
deleted file mode 100644 (file)
index 00865a7..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/target/hal/HalException.h
- *
- *  \brief Hardware abstaction layer library wrapper.
- */
-#ifndef ZYPP_TARGET_HAL_HALEXCEPTION_H
-#define ZYPP_TARGET_HAL_HALEXCEPTION_H
-
-#include "zypp/base/Exception.h"
-#include "zypp/base/String.h"
-
-//////////////////////////////////////////////////////////////////////
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-  namespace target
-  { //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-    namespace hal
-    { ////////////////////////////////////////////////////////////////
-
-
-      ////////////////////////////////////////////////////////////////
-      //
-      // CLASS NAME : HalException
-      //
-      /** Hardware abstaction layer exception.
-       * Just inherits Exception to separate hal exceptions.
-       */
-      class HalException: public zypp::Exception
-      {
-      public:
-        /** Default constructor.
-         * Use \ref ZYPP_THROW to throw exceptions.
-         */
-        HalException();
-
-        /** Constructor taking complete hal error message.
-         * This constructor is used to generate custom error
-         * messages, in case, that no DBUS error is avaliable.
-         * Use \ref ZYPP_THROW to throw exceptions.
-         */
-        HalException(const std::string &msg_r);
-
-        /** Constructor taking HAL (DBUS) error message components.
-         * Use \ref ZYPP_THROW to throw exceptions.
-         */
-        HalException(const std::string &err_name, const std::string &err_msg);
-
-        /** Destructor.
-         */
-        virtual ~HalException() throw() {};
-
-        /**
-         * \return The HAL (DBUS) error name component.
-         */
-        const std::string & errorName() const
-        {
-          return e_name;
-        }
-
-        /**
-         * \return The HAL (DBUS) error message component.
-         */
-        const std::string & errorMessage() const
-        {
-          return e_msg;
-        }
-
-      protected:
-        virtual std::ostream & dumpOn( std::ostream & str ) const;
-
-      private:
-        std::string e_name;
-        std::string e_msg;
-      };
-
-      /** Exception thrown if we were built without hal support (-DNO_HAL).
-       */
-      struct NoHalException: public Exception
-      { NoHalException(); };
-
-      ////////////////////////////////////////////////////////////////
-    } // namespace hal
-    //////////////////////////////////////////////////////////////////
-    //////////////////////////////////////////////////////////////////
-  } // namespace target
-  ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-
-#endif // ZYPP_TARGET_HAL_HALEXCEPTION_H
-
-/*
-** vim: set ts=2 sts=2 sw=2 ai et:
-*/
index f7253e5..edf6ff5 100644 (file)
@@ -117,8 +117,8 @@ public:
 //
 ///////////////////////////////////////////////////////////////////
 
-Pathname         librpmDb::_defaultRoot;       // Remembered arg to last dbAccess call
-Pathname         librpmDb::_defaultDbPath;     // Remembered arg to last dbAccess call
+Pathname         librpmDb::_defaultRoot  ( "/" );
+Pathname         librpmDb::_defaultDbPath( "/var/lib/rpm" );
 librpmDb::constPtr librpmDb::_defaultDb;
 bool             librpmDb::_dbBlocked    ( true );
 
diff --git a/zypp/thread/Mutex.cc b/zypp/thread/Mutex.cc
deleted file mode 100644 (file)
index 7862d6b..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/thread/Mutex.cc
- */
-#include "zypp/thread/Mutex.h"
-#include "zypp/thread/MutexException.h"
-#include "zypp/base/Gettext.h"
-
-
-//////////////////////////////////////////////////////////////////////
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-
-  ////////////////////////////////////////////////////////////////////
-  namespace thread
-  { //////////////////////////////////////////////////////////////////
-
-    // -------------------------------------------------------------
-    Mutex::Mutex()
-    {
-      pthread_mutexattr_t attr;
-
-      int ret = pthread_mutexattr_init(&attr);
-      if( ret != 0)
-      {
-        ZYPP_THROW_ERRNO_MSG(zypp::thread::MutexException,
-        _("Can't initialize mutex attributes"));
-      }
-
-      ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
-      if( ret != 0)
-      {
-        ZYPP_THROW_ERRNO_MSG(MutexException,
-        _("Can't set recursive mutex attribute"));
-      }
-
-      ret = pthread_mutex_init(&m_mutex, &attr);
-      if( ret != 0)
-      {
-        ZYPP_THROW_ERRNO_MSG(MutexException,
-        _("Can't initialize recursive mutex"));
-      }
-    }
-
-    // -------------------------------------------------------------
-    Mutex::~Mutex()
-    {
-      if( pthread_mutex_destroy(&m_mutex) != 0 && errno == EBUSY)
-      {
-        // try to unlock and to destroy again...
-        if( pthread_mutex_unlock(&m_mutex) == 0)
-        {
-            pthread_mutex_destroy(&m_mutex);
-        }
-        /*
-        else
-        {
-          ZYPP_THROW_ERRNO_MSG(MutexException,
-          _("Can't destroy mutex owned by another thread"));
-        }
-        */
-      }
-    }
-    // -------------------------------------------------------------
-    void Mutex::lock()
-    {
-      if( pthread_mutex_lock(&m_mutex) != 0)
-      {
-        ZYPP_THROW_ERRNO_MSG(MutexException,
-        _("Can't acquire the mutex lock"));
-      }
-    }
-
-    // -------------------------------------------------------------
-    void Mutex::unlock()
-    {
-      if( pthread_mutex_unlock(&m_mutex) != 0)
-      {
-        ZYPP_THROW_ERRNO_MSG(MutexException,
-        _("Can't release the mutex lock"));
-      }
-    }
-
-    // -------------------------------------------------------------
-    bool Mutex::trylock()
-    {
-      return (pthread_mutex_trylock(&m_mutex) == 0);
-    }
-
-
-    //////////////////////////////////////////////////////////////////
-  } // namespace thread
-  ////////////////////////////////////////////////////////////////////
-
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-
-/*
-** vim: set ts=2 sts=2 sw=2 ai et:
-*/
diff --git a/zypp/thread/Mutex.h b/zypp/thread/Mutex.h
deleted file mode 100644 (file)
index 285f83a..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/thread/Mutex.h
- */
-#ifndef   ZYPP_THREAD_MUTEX_H
-#define   ZYPP_THREAD_MUTEX_H
-
-#include "zypp/base/NonCopyable.h"
-#include "zypp/thread/MutexException.h"
-#include <pthread.h>
-
-//////////////////////////////////////////////////////////////////////
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-  namespace thread
-  { //////////////////////////////////////////////////////////////////
-
-
-    typedef pthread_mutex_t RecursiveMutex_t;
-
-
-    ////////////////////////////////////////////////////////////////
-    //
-    // CLASS NAME : Mutex
-    //
-    /** A recursive Mutex.
-     */
-    class Mutex: public zypp::base::NonCopyable
-    {
-    public:
-      /** Create a new recursive Mutex object.
-       * \throws MutexException on initialization failure.
-       */
-      Mutex();
-
-      /** Destroys this Mutex object.
-       */
-      ~Mutex();
-
-      /** Acquire ownership of this Mutex object.
-       * This call will block if another thread has ownership of
-       * this Mutex. When it returns, the current thread is the
-       * owner of this Mutex object.
-       *
-       * In the same thread, this recursive mutex can be acquired
-       * multiple times.
-       *
-       * \throws MutexException if the maximum number of recursive
-       *         locks for mutex has been exceeded.
-       */
-      void lock();
-
-      /** Release ownership of this Mutex object.
-       * If another thread is waiting to acquire the ownership of
-       * this mutex it will stop blocking and acquire ownership
-       * when this call returns.
-       *
-       * \throws MutexException if the current thread does not
-       *         own the mutex.
-       */
-      void unlock();
-
-      /** Try to acquire ownership of this Mutex object.
-       * This call will return false if another thread has ownership
-       * of this Mutex or the maximum number of recursive locks for
-       * mutex has been exceeded.
-       * When it returns true, the current thread is the owner of
-       * this Mutex object.
-       *
-       * \return true, if ownership was acquired.
-       */
-      bool trylock();
-
-    private:
-      RecursiveMutex_t m_mutex;
-    };
-
-
-    //////////////////////////////////////////////////////////////////
-  } // namespace thread
-  ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-
-#endif // ZYPP_THREAD_MUTEX_H
-/*
-** vim: set ts=2 sts=2 sw=2 ai et:
-*/
diff --git a/zypp/thread/MutexException.h b/zypp/thread/MutexException.h
deleted file mode 100644 (file)
index f7355c1..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/thread/MutexException.h
- *
-*/
-#ifndef   ZYPP_THREAD_MUTEXEXCEPTION_H
-#define   ZYPP_THREAD_MUTEXEXCEPTION_H
-
-#include "zypp/base/Exception.h"
-
-
-//////////////////////////////////////////////////////////////////////
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-
-  ////////////////////////////////////////////////////////////////////
-  namespace thread
-  { //////////////////////////////////////////////////////////////////
-
-
-    ////////////////////////////////////////////////////////////////
-    //
-    // CLASS NAME : MutexException
-    //
-    /** Exception type thrown on mutex errors.
-     */
-    class MutexException: public zypp::Exception
-    {
-    public:
-      MutexException()
-        : zypp::Exception( ::zypp::Exception::strErrno(errno))
-      {}
-
-      MutexException(const std::string &msg)
-        : zypp::Exception( msg)
-      {}
-
-      virtual ~MutexException() throw()
-      {}
-    };
-
-
-    //////////////////////////////////////////////////////////////////
-  } // namespace thread
-  ////////////////////////////////////////////////////////////////////
-
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-
-#endif // ZYPP_THREAD_MUTEXEXCEPTION_H
-/*
-** vim: set ts=2 sts=2 sw=2 ai et:
-*/
diff --git a/zypp/thread/MutexLock.h b/zypp/thread/MutexLock.h
deleted file mode 100644 (file)
index e8871d0..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/thread/MutexLock.h
- *
-*/
-#ifndef   ZYPP_THREAD_MUTEXLOCK_H
-#define   ZYPP_THREAD_MUTEXLOCK_H
-
-#include "zypp/thread/Mutex.h"
-#include <cassert>
-
-
-//////////////////////////////////////////////////////////////////////
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-  namespace thread
-  { //////////////////////////////////////////////////////////////////
-
-
-    // -------------------------------------------------------------
-    class MutexLock
-    {
-    public:
-      explicit MutexLock(Mutex &mutex, bool init_locked=true)
-        : m_mutex(&mutex)
-        , m_locked(false)
-      {
-        if(init_locked)
-          lock();
-      }
-
-      MutexLock(const MutexLock &ref)
-        : m_mutex( ref.m_mutex)
-        , m_locked(ref.m_locked)
-      {
-        ref.m_locked = false;
-      }
-
-      ~MutexLock()
-      {
-        try
-        {
-          if( m_locked)
-            unlock();
-        }
-        catch( ... )
-        {
-          // don't let exceptions escape
-        }
-      }
-
-      void lock()
-      {
-        assert(m_locked == false);
-        m_mutex->lock();
-        m_locked = true;
-      }
-
-      void unlock()
-      {
-        assert(m_locked == true);
-        m_mutex->unlock();
-        m_locked = false;
-      }
-
-      bool trylock()
-      {
-        assert(m_locked == false);
-        m_locked = m_mutex->trylock();
-        return m_locked;
-      }
-
-      bool locked()
-      {
-        return m_locked;
-      }
-
-    private:
-      Mutex        *m_mutex;
-      mutable bool  m_locked;
-      //friend class Condition;
-    };
-
-
-    //////////////////////////////////////////////////////////////////
-  } // namespace thread
-  ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-
-#endif // ZYPP_THREAD_MUTEXLOCK_H
-/*
-** vim: set ts=2 sts=2 sw=2 ai et:
-*/
diff --git a/zypp/thread/Once.h b/zypp/thread/Once.h
deleted file mode 100644 (file)
index 036cf58..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*---------------------------------------------------------------------\
-|                          ____ _   __ __ ___                          |
-|                         |__  / \ / / . \ . \                         |
-|                           / / \ V /|  _/  _/                         |
-|                          / /__ | | | | | |                           |
-|                         /_____||_| |_| |_|                           |
-|                                                                      |
-\---------------------------------------------------------------------*/
-/** \file zypp/thread/Once.h
- *
-*/
-#ifndef   ZYPP_THREAD_ONCE_H
-#define   ZYPP_THREAD_ONCE_H
-
-#include <pthread.h>
-
-
-//////////////////////////////////////////////////////////////////////
-namespace zypp
-{ ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-  namespace thread
-  { //////////////////////////////////////////////////////////////////
-
-
-    /** The initialization value for OnceFlag variables. */
-    #define ZYPP_ONCE_INIT  PTHREAD_ONCE_INIT
-
-
-    /** The OnceFlag variable type.
-     */
-    typedef pthread_once_t OnceFlag;
-
-
-    /**
-     * Call once function.
-     *
-     * The purpose of callOnce is to ensure that a piece of initialization
-     * code is executed at most once.
-     * The OnceFlag \p flag has to point to a static or extern variable,
-     * that was statically initialized to ZYPP_ONCE_INIT.
-     *
-     * The first time callOnce is called with a given \p onceFlag argument,
-     * it calls \p fuct with no argument and changes the value of \p flag
-     * to indicate that the function has been run.
-     * Subsequent calls with the same once flag does nothing.
-     */
-    void callOnce(OnceFlag& flag, void (*func)());
-
-    inline void callOnce(OnceFlag& flag, void (*func)())
-    {
-      pthread_once(&flag, func);
-    }
-
-    //////////////////////////////////////////////////////////////////
-  } // namespace thread
-  ////////////////////////////////////////////////////////////////////
-  ////////////////////////////////////////////////////////////////////
-} // namespace zypp
-//////////////////////////////////////////////////////////////////////
-
-#endif // ZYPP_THREAD_ONCE_H
-/*
-** vim: set ts=2 sts=2 sw=2 ai et:
-*/