Skip to content

Commit

Permalink
CP-11182: Factor out findElement XML helper function
Browse files Browse the repository at this point in the history
Signed-off-by: Si Beaumont <simon.beaumont@citrix.com>
  • Loading branch information
simonjbeaumont committed Feb 17, 2015
1 parent 4621318 commit 90d579c
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions ocaml/xapi/xapi_pool_patch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,13 @@ let update_db ~__context =

exception Bad_precheck_xml of string

let parse_patch_precheck_xml patch = function
let parse_patch_precheck_xml patch xml =
let rec findElement name = function
| Element (tagName, _, (PCData head)::_)::tail -> if tagName = name then head else findElement name tail
| _::tail -> findElement name tail
| [] -> raise (Bad_precheck_xml "Could not find element %s")
in
match xml with
| Element ("error", [("errorcode", "PATCH_PRECHECK_FAILED_UNKNOWN_ERROR")], [Element("info", _, [PCData info])]) ->
(* <error errorcode="PATCH_PRECHECK_FAILED_UNKNOWN_ERROR">
<info>Any message in text - for errors that don't fit into another category</info>
Expand All @@ -537,11 +543,6 @@ let parse_patch_precheck_xml patch = function
<found>4.0.91</found>
<required>4.0.95 or newer</required>
</error> *)
let rec findElement name = function
| Element (tagName, _, (PCData head)::_)::tail -> if tagName = name then head else findElement name tail
| _::tail -> findElement name tail
| [] -> raise (Bad_precheck_xml "Could not find element %s")
in
let found = findElement "found" children in
let required = findElement "required" children in
raise (Api_errors.Server_error (Api_errors.patch_precheck_failed_wrong_server_version, [Ref.string_of patch; found; required]))
Expand All @@ -551,11 +552,6 @@ let parse_patch_precheck_xml patch = function
<found>50845c</found>
<required>^58332[pc]$</required>
</error> *)
let rec findElement name = function
| Element (tagName, _, (PCData head)::_)::tail -> if tagName = name then head else findElement name tail
| _::tail -> findElement name tail
| [] -> raise (Bad_precheck_xml "Could not find element %s")
in
let found = findElement "found" children in
let required = findElement "required" children in
raise (Api_errors.Server_error (Api_errors.patch_precheck_failed_wrong_server_build, [Ref.string_of patch; found; required]))
Expand Down

0 comments on commit 90d579c

Please sign in to comment.