mergerepo_c: Fix version-release comparison for packages when --all is used
authorTomas Mlcoch <tmlcoch@redhat.com>
Fri, 22 May 2015 10:20:51 +0000 (12:20 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Fri, 22 May 2015 10:21:04 +0000 (12:21 +0200)
src/mergerepo_c.c

index d5c2265..0f1b87c 100644 (file)
@@ -880,18 +880,25 @@ add_package(cr_Package *pkg,
                 }
 
             } else {
-
                 // Two packages has same name and arch but all param is used
 
-                int cmp_res = cr_cmp_version_str(pkg->version, c_pkg->version);
-                long pkg_release   = (pkg->release)   ? strtol(pkg->release, NULL, 10)   : 0;
-                long c_pkg_release = (c_pkg->release) ? strtol(c_pkg->release, NULL, 10) : 0;
-
-                if (cmp_res == 0 && pkg_release == c_pkg_release) {
-                    // Package with same name, arch, version and release
-                    // is already listed
-                    g_debug("Same version of package %s (%s) already exists",
-                            pkg->name, pkg->arch);
+                // We want to check if two packages are the same.
+                // We already know that name and arch matches.
+                // We need to check version and release, but we
+                // don't need any sophisticated methods, we can
+                // use plain string comparison.
+                if (!g_strcmp0(pkg->version ? pkg->version : "",
+                               c_pkg->version ? c_pkg->version : "")
+                    && !g_strcmp0(pkg->release ? pkg->release : "",
+                                  c_pkg->release ? c_pkg->release: ""))
+                {
+                    // Both packages are the same (at least by NVRA values)
+                    g_debug("Same version of package %s (ver: %s) (rel: %s) "
+                            "(arch: %s) already exists",
+                            pkg->name,
+                            pkg->version ? pkg->version : "N/A",
+                            pkg->release ? pkg->release : "N/A",
+                            pkg->arch);
                     return 0;
                 }
             }