On 20.01.15 14:48, Richard W.M. Jones wrote:
On Tue, Jan 20, 2015 at 04:25:20PM +0200, Shahar Havivi wrote:
> > > + let pos = (String.length os) - 36 in
> > > + let mp = String.sub os 0 (pos-1) in
> > > + let uuid = String.sub os pos 36 in
> >
> > What is the significance of 36 here?
> the length of uuid.
That code above will throw an exception if you pass a too-short -os
parameter.
How about this, which should be a little bit easier to understand:
let mp, uuid =
let fields = string_nsplit "/" os in (* ... "data-center"
"UUID" *)
let fields = List.rev fields in (* "UUID" "data-center" ...
*)
match fields with
| "" :: uuid :: rest (* handles trailing "/" case
*)
| uuid :: rest
when String.length uuid = 36 ->
let mp = String.concat "/" (List.rev rest) in
mp, uuid
| _ ->
error (f_"vdsm: invalid -os parameter does not contain a valid UUID: %s")
os
Looks better, I will give it a try
Or perhaps something with regexps ...
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