Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 11/12] convert/windows: expose "prio" parameter in install_firstboot_powershell
The "Firstboot.add_firstboot_script" function now takes an (optional) priority parameter. Because "install_firstboot_powershell" is a wrapper around "Firstboot.add_firstboot_script", enable callers of the former too to set the script run priority. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- convert/windows.mli | 6 +++--- convert/windows.ml | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/convert/windows.mli b/convert/windows.mli index d888e2db40b3..4c7f292832ac 100644 --- a/convert/windows.mli +++ b/convert/windows.mli @@ -23,7 +23,7 @@ val detect_antivirus : Types.inspect -> bool this Windows guest. *) val install_firstboot_powershell : Guestfs.guestfs -> Types.inspect -> - string -> string list -> unit -(** [install_powershell_firstboot g inspect filename code] installs a + ?prio:int -> string -> string list -> unit +(** [install_powershell_firstboot g inspect prio filename code] installs a Powershell script (the lines of code) as a firstboot script in - the Windows VM. *) + the Windows VM. If [prio] is omitted, [Firstboot.default_prio] is used. *) diff --git a/convert/windows.ml b/convert/windows.ml index fc0faef57249..8a30be10d21a 100644 --- a/convert/windows.ml +++ b/convert/windows.ml @@ -52,7 +52,8 @@ and (=~) str rex = PCRE.matches rex str * a regular batch file. *) let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } - filename code + ?(prio = Firstboot.default_prio) filename + code let tempdir = sprintf "%s/Temp" i_windows_systemroot in g#mkdir_p tempdir; let code = String.concat "\r\n" code ^ "\r\n" in @@ -67,4 +68,4 @@ let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } let ps_path = i_windows_systemroot ^ "\\Temp\\" ^ filename in let fb = sprintf "%s -ExecutionPolicy ByPass -file %s" ps_exe ps_path in - Firstboot.add_firstboot_script g i_root filename fb + Firstboot.add_firstboot_script g i_root ~prio filename fb -- 2.19.1.3.g30247aa5d201
Richard W.M. Jones
2022-Mar-08 16:17 UTC
[Libguestfs] [v2v PATCH 11/12] convert/windows: expose "prio" parameter in install_firstboot_powershell
On Tue, Mar 08, 2022 at 03:30:58PM +0100, Laszlo Ersek wrote:> The "Firstboot.add_firstboot_script" function now takes an (optional) > priority parameter. Because "install_firstboot_powershell" is a wrapper > around "Firstboot.add_firstboot_script", enable callers of the former too > to set the script run priority.I had a double-take with the "too to" (but it is correct). Maybe s/too/also/ or s/too//?> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 > Signed-off-by: Laszlo Ersek <lersek at redhat.com> > --- > convert/windows.mli | 6 +++--- > convert/windows.ml | 5 +++-- > 2 files changed, 6 insertions(+), 5 deletions(-) > > diff --git a/convert/windows.mli b/convert/windows.mli > index d888e2db40b3..4c7f292832ac 100644 > --- a/convert/windows.mli > +++ b/convert/windows.mli > @@ -23,7 +23,7 @@ val detect_antivirus : Types.inspect -> bool > this Windows guest. *) > > val install_firstboot_powershell : Guestfs.guestfs -> Types.inspect -> > - string -> string list -> unit > -(** [install_powershell_firstboot g inspect filename code] installs a > + ?prio:int -> string -> string list -> unit > +(** [install_powershell_firstboot g inspect prio filename code] installs a > Powershell script (the lines of code) as a firstboot script in > - the Windows VM. *) > + the Windows VM. If [prio] is omitted, [Firstboot.default_prio] is used. *) > diff --git a/convert/windows.ml b/convert/windows.ml > index fc0faef57249..8a30be10d21a 100644 > --- a/convert/windows.ml > +++ b/convert/windows.ml > @@ -52,7 +52,8 @@ and (=~) str rex = PCRE.matches rex str > * a regular batch file. > *) > let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } > - filename code > + ?(prio = Firstboot.default_prio) filename > + code > let tempdir = sprintf "%s/Temp" i_windows_systemroot in > g#mkdir_p tempdir; > let code = String.concat "\r\n" code ^ "\r\n" in > @@ -67,4 +68,4 @@ let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } > let ps_path = i_windows_systemroot ^ "\\Temp\\" ^ filename in > > let fb = sprintf "%s -ExecutionPolicy ByPass -file %s" ps_exe ps_path in > - Firstboot.add_firstboot_script g i_root filename fb > + Firstboot.add_firstboot_script g i_root ~prio filename fbSo this is a bit convoluted. I note you exposed default_prio in the Firstboot module which I was a little confused by, but now I see why you did it. However you didn't need to. You can instead do:> let install_firstboot_powershell g { Types.i_windows_systemroot; i_root } > - filename code > + ?prio filename code ... > - Firstboot.add_firstboot_script g i_root filename fb > + Firstboot.add_firstboot_script g i_root ?prio filename fb?prio has type 'int option'. So ACK with that change, and drop default_prio from Firstboot too. When pushing this patch, don't forget to update the common submodule in the same commit! Thanks, 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