[Libguestfs] [PATCH 1/2] mllib: add and use last_part_of

Richard W.M. Jones rjones at redhat.com
Wed Jul 1 17:38:27 UTC 2015


On Wed, Jul 01, 2015 at 06:47:31PM +0200, Pino Toscano wrote:
> On Wednesday 01 July 2015 17:36:20 Richard W.M. Jones wrote:
> > On Wed, Jul 01, 2015 at 05:49:06PM +0200, Pino Toscano wrote:
> > > Collect this small snippet to get the part of a string after the last
> > > occurrency of a character; replace with it the current snippets doing
> > > the same.
> > > 
> > > Should be just code motion.
> > > ---
> > >  customize/password.ml                     |  5 +++--
> > >  mllib/common_utils.ml                     |  7 +++++++
> > >  mllib/common_utils.mli                    |  3 +++
> > >  sysprep/sysprep_operation_user_account.ml |  5 +++--
> > >  v2v/convert_linux.ml                      | 10 +++-------
> > >  v2v/utils.ml                              | 16 ++++++++++------
> > >  6 files changed, 29 insertions(+), 17 deletions(-)
> > > 
> > > diff --git a/customize/password.ml b/customize/password.ml
> > > index 25ce901..d91c4b5 100644
> > > --- a/customize/password.ml
> > > +++ b/customize/password.ml
> > > @@ -98,8 +98,9 @@ let rec set_linux_passwords ?password_crypto (g : Guestfs.guestfs) root password
> > >    List.iter (
> > >      fun userpath ->
> > >        let user =
> > > -        let i = String.rindex userpath '/' in
> > > -        String.sub userpath (i+1) (String.length userpath -i-1) in
> > > +        match last_part_of userpath '/' with
> > > +        | Some x -> x
> > > +        | None -> error "password: missing '/' in %s" userpath in
> > 
> > Best to translate these strings:
> > 
> >   | None -> error (f_"password: missing '/' in %s") userpath in
> 
> Hmm I thought that, being them really internal errors (basically
> something like a "polished assert"), it would be better to not bother
> translating them.

Yes if they're internal errors, then it's best not to translate them.

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




More information about the Libguestfs mailing list