Bind and use rpmvercmp to compare versions of packages when sorting them, instead of an own string-based comparison function. --- src/librpm-c.c | 12 ++++++++++++ src/librpm.ml | 1 + src/librpm.mli | 1 + src/rpm.ml | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/librpm-c.c b/src/librpm-c.c index 1ae3bad..fc847d6 100644 --- a/src/librpm-c.c +++ b/src/librpm-c.c @@ -122,6 +122,12 @@ supermin_rpm_version (value unit) } value +supermin_rpm_vercmp (value av, value bv) +{ + return Val_int (rpmvercmp (String_val (av), String_val (bv))); +} + +value supermin_rpm_open (value debugv) { CAMLparam1 (debugv); @@ -445,6 +451,12 @@ supermin_rpm_version (value unit) } value +supermin_rpm_vercmp (value av, value bv) +{ + abort (); +} + +value supermin_rpm_open (value debugv) { abort (); diff --git a/src/librpm.ml b/src/librpm.ml index aa8d367..8c30248 100644 --- a/src/librpm.ml +++ b/src/librpm.ml @@ -19,6 +19,7 @@ external rpm_is_available : unit -> bool = "supermin_rpm_is_available" external rpm_version : unit -> string = "supermin_rpm_version" +external rpm_vercmp : string -> string -> int = "supermin_rpm_vercmp" type t diff --git a/src/librpm.mli b/src/librpm.mli index 880a038..da73911 100644 --- a/src/librpm.mli +++ b/src/librpm.mli @@ -19,6 +19,7 @@ val rpm_is_available : unit -> bool val rpm_version : unit -> string +val rpm_vercmp : string -> string -> int type t diff --git a/src/rpm.ml b/src/rpm.ml index 640a02a..ce803e1 100644 --- a/src/rpm.ml +++ b/src/rpm.ml @@ -144,7 +144,7 @@ let rpm_package_of_string str * architecture. *) let cmp { version = v1; arch = a1 } { version = v2; arch = a2 } - let i = compare_version v2 v1 in + let i = rpm_vercmp v2 v1 in if i <> 0 then i else compare_architecture a2 a1 in -- 1.9.3
Pino Toscano
2014-Nov-24 14:52 UTC
[Libguestfs] [PATCH] rpm: isolate the "packages as NA RPM list" code
Just code motion, no functional change. --- src/rpm.ml | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/rpm.ml b/src/rpm.ml index ce803e1..771022e 100644 --- a/src/rpm.ml +++ b/src/rpm.ml @@ -288,11 +288,7 @@ let rec fedora_download_all_packages pkgs dir * Use name.arch so it can download any version but only the specific * architecture. *) - let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in - let rpms = List.map ( - fun { name = name; arch = arch } -> - sprintf "%s.%s" name arch - ) rpms in + let rpms = pkgs_as_NA_rpms pkgs in let cmd sprintf "%s%s%s --destdir %s %s" @@ -309,11 +305,7 @@ let rec fedora_download_all_packages pkgs dir (* dnf doesn't create the download directory. *) mkdir tdir 0o700; - let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in - let rpms = List.map ( - fun { name = name; arch = arch } -> - sprintf "%s.%s" name arch - ) rpms in + let rpms = pkgs_as_NA_rpms pkgs in let cmd sprintf "%s download --destdir %s %s" @@ -326,11 +318,7 @@ let rec fedora_download_all_packages pkgs dir and opensuse_download_all_packages pkgs dir let tdir = !settings.tmpdir // string_random8 () in - let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in - let rpms = List.map ( - fun { name = name; arch = arch } -> - sprintf "%s.%s" name arch - ) rpms in + let rpms = pkgs_as_NA_rpms pkgs in let is_zypper_1_9_14 !zypper_major > 1 @@ -399,6 +387,13 @@ and mageia_download_all_packages pkgs dir rpm_unpack tdir dir +and pkgs_as_NA_rpms pkgs + let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in + List.map ( + fun { name = name; arch = arch } -> + sprintf "%s.%s" name arch + ) rpms + and rpm_unpack tdir dir (* Unpack each downloaded package. * -- 1.9.3
Handle debug level and packager config. --- src/rpm.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/rpm.ml b/src/rpm.ml index 771022e..46954c8 100644 --- a/src/rpm.ml +++ b/src/rpm.ml @@ -308,8 +308,14 @@ let rec fedora_download_all_packages pkgs dir let rpms = pkgs_as_NA_rpms pkgs in let cmd - sprintf "%s download --destdir %s %s" - Config.dnf (quote tdir) (quoted_list rpms) in + sprintf "%s download%s%s --destdir %s %s" + Config.dnf + (if !settings.debug >= 1 then " -v" else " -q") + (match !settings.packager_config with + | None -> "" + | Some filename -> sprintf " -c %s" (quote filename)) + (quote tdir) + (quoted_list rpms) in run_command cmd ); -- 1.9.3
Richard W.M. Jones
2014-Nov-25 14:28 UTC
Re: [Libguestfs] [PATCH] rpm: use librpm's rpmvercmp
On Mon, Nov 24, 2014 at 03:52:26PM +0100, Pino Toscano wrote:> Bind and use rpmvercmp to compare versions of packages when sorting > them, instead of an own string-based comparison function. > --- > src/librpm-c.c | 12 ++++++++++++ > src/librpm.ml | 1 + > src/librpm.mli | 1 + > src/rpm.ml | 2 +- > 4 files changed, 15 insertions(+), 1 deletion(-) > > diff --git a/src/librpm-c.c b/src/librpm-c.c > index 1ae3bad..fc847d6 100644 > --- a/src/librpm-c.c > +++ b/src/librpm-c.c > @@ -122,6 +122,12 @@ supermin_rpm_version (value unit) > } > > value > +supermin_rpm_vercmp (value av, value bv) > +{ > + return Val_int (rpmvercmp (String_val (av), String_val (bv))); > +} > + > +value > supermin_rpm_open (value debugv) > { > CAMLparam1 (debugv); > @@ -445,6 +451,12 @@ supermin_rpm_version (value unit) > } > > value > +supermin_rpm_vercmp (value av, value bv) > +{ > + abort (); > +} > + > +value > supermin_rpm_open (value debugv) > { > abort (); > diff --git a/src/librpm.ml b/src/librpm.ml > index aa8d367..8c30248 100644 > --- a/src/librpm.ml > +++ b/src/librpm.ml > @@ -19,6 +19,7 @@ > external rpm_is_available : unit -> bool = "supermin_rpm_is_available" > > external rpm_version : unit -> string = "supermin_rpm_version" > +external rpm_vercmp : string -> string -> int = "supermin_rpm_vercmp"Small detail: This is a "noalloc" function, so you can make it a bit faster: http://camltastic.blogspot.co.uk/2008/08/tip-calling-c-functions-directly-with.html ACK. Rich.> type t > > diff --git a/src/librpm.mli b/src/librpm.mli > index 880a038..da73911 100644 > --- a/src/librpm.mli > +++ b/src/librpm.mli > @@ -19,6 +19,7 @@ > val rpm_is_available : unit -> bool > > val rpm_version : unit -> string > +val rpm_vercmp : string -> string -> int > > type t > > diff --git a/src/rpm.ml b/src/rpm.ml > index 640a02a..ce803e1 100644 > --- a/src/rpm.ml > +++ b/src/rpm.ml > @@ -144,7 +144,7 @@ let rpm_package_of_string str > * architecture. > *) > let cmp { version = v1; arch = a1 } { version = v2; arch = a2 } > - let i = compare_version v2 v1 in > + let i = rpm_vercmp v2 v1 in > if i <> 0 then i > else compare_architecture a2 a1 > in > -- > 1.9.3 > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfs-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Richard W.M. Jones
2014-Nov-25 14:28 UTC
Re: [Libguestfs] [PATCH] rpm: isolate the "packages as NA RPM list" code
On Mon, Nov 24, 2014 at 03:52:27PM +0100, Pino Toscano wrote:> Just code motion, no functional change.Looks like simple code refactoring, so ACK. Rich.> src/rpm.ml | 25 ++++++++++--------------- > 1 file changed, 10 insertions(+), 15 deletions(-) > > diff --git a/src/rpm.ml b/src/rpm.ml > index ce803e1..771022e 100644 > --- a/src/rpm.ml > +++ b/src/rpm.ml > @@ -288,11 +288,7 @@ let rec fedora_download_all_packages pkgs dir > * Use name.arch so it can download any version but only the specific > * architecture. > *) > - let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in > - let rpms = List.map ( > - fun { name = name; arch = arch } -> > - sprintf "%s.%s" name arch > - ) rpms in > + let rpms = pkgs_as_NA_rpms pkgs in > > let cmd > sprintf "%s%s%s --destdir %s %s" > @@ -309,11 +305,7 @@ let rec fedora_download_all_packages pkgs dir > (* dnf doesn't create the download directory. *) > mkdir tdir 0o700; > > - let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in > - let rpms = List.map ( > - fun { name = name; arch = arch } -> > - sprintf "%s.%s" name arch > - ) rpms in > + let rpms = pkgs_as_NA_rpms pkgs in > > let cmd > sprintf "%s download --destdir %s %s" > @@ -326,11 +318,7 @@ let rec fedora_download_all_packages pkgs dir > and opensuse_download_all_packages pkgs dir > let tdir = !settings.tmpdir // string_random8 () in > > - let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in > - let rpms = List.map ( > - fun { name = name; arch = arch } -> > - sprintf "%s.%s" name arch > - ) rpms in > + let rpms = pkgs_as_NA_rpms pkgs in > > let is_zypper_1_9_14 > !zypper_major > 1 > @@ -399,6 +387,13 @@ and mageia_download_all_packages pkgs dir > > rpm_unpack tdir dir > > +and pkgs_as_NA_rpms pkgs > + let rpms = List.map rpm_of_pkg (PackageSet.elements pkgs) in > + List.map ( > + fun { name = name; arch = arch } -> > + sprintf "%s.%s" name arch > + ) rpms > + > and rpm_unpack tdir dir > (* Unpack each downloaded package. > * > -- > 1.9.3 > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfs-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Richard W.M. Jones
2014-Nov-25 14:29 UTC
Re: [Libguestfs] [PATCH] rpm: improve dnf invocation
On Mon, Nov 24, 2014 at 03:52:28PM +0100, Pino Toscano wrote:> Handle debug level and packager config. > --- > src/rpm.ml | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/src/rpm.ml b/src/rpm.ml > index 771022e..46954c8 100644 > --- a/src/rpm.ml > +++ b/src/rpm.ml > @@ -308,8 +308,14 @@ let rec fedora_download_all_packages pkgs dir > let rpms = pkgs_as_NA_rpms pkgs in > > let cmd > - sprintf "%s download --destdir %s %s" > - Config.dnf (quote tdir) (quoted_list rpms) in > + sprintf "%s download%s%s --destdir %s %s" > + Config.dnf > + (if !settings.debug >= 1 then " -v" else " -q") > + (match !settings.packager_config with > + | None -> "" > + | Some filename -> sprintf " -c %s" (quote filename)) > + (quote tdir) > + (quoted_list rpms) in > run_command cmd > );ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Seemingly Similar Threads
- [PATCH 0/4] supermin: use dnf on Mageia
- [PATCH 0/2] supermin: use librpm for rpm support
- [supermin PATCH 0/5] rpm: fix package selection w/ multilib
- [PATCH] rpm: isolate the "packages as NA RPM list" code
- [supermin PATCH 1/2] rpm: extend the Multiple_matches exception