Pino Toscano
2019-Jan-23 11:29 UTC
[Libguestfs] [supermin PATCH 1/2] rpm: extend the Multiple_matches exception
Add the package that raised the issue, so it can be used to provide
better diagnostic.
---
src/librpm-c.c | 15 ++++++++++-----
src/librpm.ml | 4 ++--
src/librpm.mli | 2 +-
3 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/librpm-c.c b/src/librpm-c.c
index 3bd25a2..75ca4d7 100644
--- a/src/librpm-c.c
+++ b/src/librpm-c.c
@@ -66,10 +66,15 @@ librpm_handle_closed (void)
}
static void
-librpm_raise_multiple_matches (int occurrences)
+librpm_raise_multiple_matches (value pkgv, int occurrences)
{
- caml_raise_with_arg (*caml_named_value ("librpm_multiple_matches"),
- Val_int (occurrences));
+ CAMLparam1 (pkgv);
+
+ value args[] = { pkgv, Val_int (occurrences) };
+ caml_raise_with_args (*caml_named_value
("librpm_multiple_matches"),
+ 2, args);
+
+ CAMLnoreturn;
}
#define Librpm_val(v) (*((struct librpm_data *)Data_custom_val(v)))
@@ -296,7 +301,7 @@ supermin_rpm_pkg_requires (value rpmv, value pkgv)
fflush (stdout);
}
if (count != 1)
- librpm_raise_multiple_matches (count);
+ librpm_raise_multiple_matches (pkgv, count);
h = rpmdbNextIterator (iter);
assert (h != NULL);
@@ -413,7 +418,7 @@ supermin_rpm_pkg_filelist (value rpmv, value pkgv)
fflush (stdout);
}
if (count != 1)
- librpm_raise_multiple_matches (count);
+ librpm_raise_multiple_matches (pkgv, count);
h = rpmdbNextIterator (iter);
assert (h != NULL);
diff --git a/src/librpm.ml b/src/librpm.ml
index 4eeba77..b6f9ff8 100644
--- a/src/librpm.ml
+++ b/src/librpm.ml
@@ -23,7 +23,7 @@ external rpm_vercmp : string -> string -> int =
"supermin_rpm_vercmp" "noalloc"
type t
-exception Multiple_matches of int
+exception Multiple_matches of string * int
external rpm_open : ?debug:int -> t = "supermin_rpm_open"
external rpm_close : t -> unit = "supermin_rpm_close"
@@ -49,4 +49,4 @@ external rpm_pkg_whatprovides : t -> string -> string
array = "supermin_rpm_pkg_
external rpm_pkg_filelist : t -> string -> rpmfile_t array =
"supermin_rpm_pkg_filelist"
let () - Callback.register_exception "librpm_multiple_matches"
(Multiple_matches 0)
+ Callback.register_exception "librpm_multiple_matches"
(Multiple_matches ("", 0))
diff --git a/src/librpm.mli b/src/librpm.mli
index 5229be6..53b4b2c 100644
--- a/src/librpm.mli
+++ b/src/librpm.mli
@@ -31,7 +31,7 @@ val rpm_vercmp : string -> string -> int
type t
(** The librpm handle. *)
-exception Multiple_matches of int
+exception Multiple_matches of string * int
val rpm_open : ?debug:int -> t
(** Open the librpm (transaction set) handle. *)
--
2.20.1
Pino Toscano
2019-Jan-23 11:29 UTC
[Libguestfs] [supermin PATCH 2/2] Print Librpm.Multiple_matches exceptions
Print a better diagnostic for them, so it is more clear which package
is detected as present multiple times.
---
src/supermin.ml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/supermin.ml b/src/supermin.ml
index f9798f9..71d8b64 100644
--- a/src/supermin.ml
+++ b/src/supermin.ml
@@ -298,6 +298,8 @@ let () error "error: %s: %s: %s" fname
(Unix.error_message code) param
| Failure msg -> (* from failwith/failwithf *)
error "failure: %s" msg
+ | Librpm.Multiple_matches (package, count) -> (* from librpm *)
+ error "RPM error: %d occurrences for %s" count package
| Invalid_argument msg -> (* probably should never happen *)
error "internal error: invalid argument: %s" msg
| Assert_failure (file, line, char) -> (* should never happen *)
--
2.20.1
Richard W.M. Jones
2019-Jan-24 12:51 UTC
Re: [Libguestfs] [supermin PATCH 2/2] Print Librpm.Multiple_matches exceptions
On Wed, Jan 23, 2019 at 12:29:50PM +0100, Pino Toscano wrote:> Print a better diagnostic for them, so it is more clear which package > is detected as present multiple times. > --- > src/supermin.ml | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/src/supermin.ml b/src/supermin.ml > index f9798f9..71d8b64 100644 > --- a/src/supermin.ml > +++ b/src/supermin.ml > @@ -298,6 +298,8 @@ let () > error "error: %s: %s: %s" fname (Unix.error_message code) param > | Failure msg -> (* from failwith/failwithf *) > error "failure: %s" msg > + | Librpm.Multiple_matches (package, count) -> (* from librpm *) > + error "RPM error: %d occurrences for %s" count package > | Invalid_argument msg -> (* probably should never happen *) > error "internal error: invalid argument: %s" msg > | Assert_failure (file, line, char) -> (* should never happen *)Looks good, so ACK series Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org