[packagekit] [PATCH 3/5] zypp: Remove network roundtrip for CD/DVD detection

Thomas Perl thomas.perl at jolla.com
Wed Jan 22 02:31:50 PST 2014


The majority of package sources these days are network-based, so
it doesn't really make sense to spend a network roundtrip for each
repository just to check whether or not it is on CD/DVD. This will
still work correctly (the logic is the same that libzypp uses), but
avoid costly network roundtrips for each check.
---
 backends/zypp/pk-backend-zypp.cpp | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index 64524f8..a3c8040 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -641,17 +641,9 @@ zypp_logging ()
 gboolean
 zypp_is_changeable_media (const Url &url)
 {
-	gboolean is_cd = false;
-	try {
-		media::MediaManager mm;
-		media::MediaAccessId id = mm.open (url);
-		is_cd = mm.isChangeable (id);
-		mm.close (id);
-	} catch (const media::MediaException &e) {
-		// TODO: Do anything about this?
-	}
-
-	return is_cd;
+	// Copied from MediaManager::isChangeable() in libzypp's MediaManager.cpp
+	// This avoids a network roundtrip just to check if it's a CD/DVD.
+	return (url.getScheme() == "cd" || url.getScheme() == "dvd");
 }
 
 namespace {
-- 
1.8.5.2



More information about the PackageKit mailing list