Skip to content

Commit

Permalink
fixup! Eliminate unnecessary usage of List.length to check for empty …
Browse files Browse the repository at this point in the history
…lists

Signed-off-by: Andrii Sultanov <[email protected]>
  • Loading branch information
last-genius committed Jul 2, 2024
1 parent 27fd041 commit b57ff2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
19 changes: 8 additions & 11 deletions ocaml/xapi-cli-server/cli_operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,6 @@ let make_param_funs getallrecs getbyuuid record class_name def_filters
]
in
let ops =
(* If length > 0 *)
if settable <> [] then
( cli_name "param-set"
, ["uuid"]
Expand All @@ -878,7 +877,6 @@ let make_param_funs getallrecs getbyuuid record class_name def_filters
ops
in
let ops =
(* If length > 0 *)
if addable <> [] then
ops
@ [
Expand All @@ -904,7 +902,6 @@ let make_param_funs getallrecs getbyuuid record class_name def_filters
ops
in
let ops =
(* If length > 0 *)
if clearable <> [] then
ops
@ [
Expand Down Expand Up @@ -2935,7 +2932,7 @@ let event_wait_gen rpc session_id classname record_matches =
(* true if anything matches now *)
let find_any_match recs =
let ls = List.map record_matches recs in
Option.is_some (List.find_opt (fun x -> x) ls)
List.exists Fun.id ls
in
find_any_match all_recs
in
Expand Down Expand Up @@ -4068,7 +4065,7 @@ let vm_install printer rpc session_id params =
failwith "No templates matched"
| [x] ->
x.getref ()
| _ :: _ ->
| _ :: _ :: _ ->
failwith "More than one matching template found"
in
if
Expand Down Expand Up @@ -4119,7 +4116,7 @@ let console fd _printer rpc session_id params =
| [] ->
marshal fd (Command (PrintStderr "No VM found\n")) ;
raise (ExitWithError 1)
| _ :: _ ->
| _ :: _ :: _ ->
marshal fd
(Command
(PrintStderr
Expand Down Expand Up @@ -4161,7 +4158,7 @@ let vm_uninstall_common fd _printer rpc session_id params vms =
( match r.API.vDI_VBDs with
| [] | [_] ->
""
| _ :: _ ->
| _ :: _ :: _ ->
" ** WARNING: disk is shared by other VMs"
)
in
Expand Down Expand Up @@ -4491,7 +4488,7 @@ let vm_retrieve_wlb_recommendations printer rpc session_id params =
(Cli_printer.PTable
[("Host(Uuid)", "Stars, RecID, ZeroScoreReason") :: table x]
)
| _ :: _ ->
| _ :: _ :: _ ->
failwith
"Multiple VMs found. Operation can only be performed on one VM at a \
time"
Expand Down Expand Up @@ -5102,7 +5099,7 @@ let vm_cd_eject printer rpc session_id params =
failwith "No CDs found"
| [_] ->
()
| _ :: _ ->
| _ :: _ :: _ ->
failwith "Two or more CDs found. Please use vbd-eject"
) ;
let cd = List.hd cdvbds in
Expand All @@ -5126,7 +5123,7 @@ let vm_cd_insert printer rpc session_id params =
failwith ("CD " ^ cd_name ^ " not found")
| [_] ->
()
| _ :: _ ->
| _ :: _ :: _ ->
failwith
("Multiple CDs named "
^ cd_name
Expand All @@ -5152,7 +5149,7 @@ let vm_cd_insert printer rpc session_id params =
)
| [cd] ->
Client.VBD.insert ~rpc ~session_id ~vbd:cd ~vdi:(List.hd vdis)
| _ :: _ ->
| _ :: _ :: _ ->
failwith "Two or more empty CD devices found. Please use vbd-insert"
in
ignore (do_vm_op printer rpc session_id op params ["cd-name"])
Expand Down
3 changes: 2 additions & 1 deletion ocaml/xapi-cli-server/cli_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ let make_printer sock minimal =
let multi_line_xapi_minimal pval =
match pval with
| PTable rs ->
if rs <> [] && List.hd rs <> [] then
(* Check that all the sublists aren't empty before calling List.hd *)
if rs <> [] && List.for_all (fun r -> r <> []) rs then
let names = List.map (fun r -> snd (List.hd r)) rs in
let escaped_names = List.map escape_commas names in
buffer := String.concat "," escaped_names :: !buffer
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xenopsd/xc/hotplug.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ let release (task : Xenops_task.task_handle) ~xc ~xs (x : device) =
match domains_of_vm with
| [] | [_] ->
Some (get_private_data_path_of_device x)
| _ :: _ ->
| _ :: _ :: _ ->
None
in
let extra_xenserver_path = extra_xenserver_path_of_device ~xs x in
Expand Down

0 comments on commit b57ff2c

Please sign in to comment.