Richard W.M. Jones
2021-Nov-12 10:40 UTC
[Libguestfs] [PATCH v2v v2] convert/convert_windows.ml: Handle date formats with dots instead of /
If the ShortDatePattern is yy.M.d (as can happen for US locale) we may not always reformat the date for schtasks.exe correctly. For explanation and testing see: https://bugzilla.redhat.com/show_bug.cgi?id=1895323#c46 (- #c50) Thanks: Xiaodai Wang for testing and bug fix suggestions Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1895323 --- convert/convert_windows.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml index 31e16723ba..913eb0f4f1 100644 --- a/convert/convert_windows.ml +++ b/convert/convert_windows.ml @@ -400,12 +400,15 @@ popd and configure_qemu_ga files List.iter ( fun msi_path -> - (* Windows is a trashfire. https://stackoverflow.com/a/18730884 *) + (* Windows is a trashfire. + * https://stackoverflow.com/a/18730884 + * https://bugzilla.redhat.com/show_bug.cgi?id=1895323 + *) let fb_script = sprintf "\ echo Removing any previously scheduled qemu-ga installation schtasks.exe /Delete /TN Firstboot-qemu-ga /F echo Scheduling delayed installation of qemu-ga from %s -powershell.exe -command \"$d = (get-date).AddSeconds(120); $FormatHack = ($([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortDatePattern) -replace 'M+/', 'MM/') -replace 'd+/', 'dd/'; schtasks.exe /Create /SC ONCE /ST $d.ToString('HH:mm') /SD $d.ToString($FormatHack) /RU SYSTEM /TN Firstboot-qemu-ga /TR \\\"C:\\%s /forcerestart /qn /l+*vx C:\\%s.log\\\"\" +powershell.exe -command \"$d = (get-date).AddSeconds(120); $FormatHack = ($([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortDatePattern) -replace 'y+', 'yyyy') -replace 'M+', 'MM') -replace 'd+', 'dd'; schtasks.exe /Create /SC ONCE /ST $d.ToString('HH:mm') /SD $d.ToString($FormatHack) /RU SYSTEM /TN Firstboot-qemu-ga /TR \\\"C:\\%s /forcerestart /qn /l+*vx C:\\%s.log\\\"\" " msi_path msi_path msi_path in Firstboot.add_firstboot_script g inspect.i_root -- 2.32.0
Richard W.M. Jones
2021-Nov-12 13:15 UTC
[Libguestfs] [PATCH v2v v2] convert/convert_windows.ml: Handle date formats with dots instead of /
v2 was slightly broken because of mismatched parentheses. Xiaodai Wang and myself iterated on this patch and came up with a final version that was tested on Windows and works: https://github.com/libguestfs/virt-v2v/commit/d9dc6c42ae64ba92993dbd9477f003ba73fcfa2f 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
Laszlo Ersek
2021-Nov-12 13:43 UTC
[Libguestfs] [PATCH v2v v2] convert/convert_windows.ml: Handle date formats with dots instead of /
On 11/12/21 11:40, Richard W.M. Jones wrote:> If the ShortDatePattern is yy.M.d (as can happen for US locale) we may > not always reformat the date for schtasks.exe correctly. For > explanation and testing see: > > https://bugzilla.redhat.com/show_bug.cgi?id=1895323#c46 (- #c50) > > Thanks: Xiaodai Wang for testing and bug fix suggestions > Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1895323 > --- > convert/convert_windows.ml | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/convert/convert_windows.ml b/convert/convert_windows.ml > index 31e16723ba..913eb0f4f1 100644 > --- a/convert/convert_windows.ml > +++ b/convert/convert_windows.ml > @@ -400,12 +400,15 @@ popd > and configure_qemu_ga files > List.iter ( > fun msi_path -> > - (* Windows is a trashfire. https://stackoverflow.com/a/18730884 *) > + (* Windows is a trashfire. > + * https://stackoverflow.com/a/18730884 > + * https://bugzilla.redhat.com/show_bug.cgi?id=1895323 > + *) > let fb_script = sprintf "\ > echo Removing any previously scheduled qemu-ga installation > schtasks.exe /Delete /TN Firstboot-qemu-ga /F > echo Scheduling delayed installation of qemu-ga from %s > -powershell.exe -command \"$d = (get-date).AddSeconds(120); $FormatHack = ($([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortDatePattern) -replace 'M+/', 'MM/') -replace 'd+/', 'dd/'; schtasks.exe /Create /SC ONCE /ST $d.ToString('HH:mm') /SD $d.ToString($FormatHack) /RU SYSTEM /TN Firstboot-qemu-ga /TR \\\"C:\\%s /forcerestart /qn /l+*vx C:\\%s.log\\\"\" > +powershell.exe -command \"$d = (get-date).AddSeconds(120); $FormatHack = ($([System.Globalization.DateTimeFormatInfo]::CurrentInfo.ShortDatePattern) -replace 'y+', 'yyyy') -replace 'M+', 'MM') -replace 'd+', 'dd'; schtasks.exe /Create /SC ONCE /ST $d.ToString('HH:mm') /SD $d.ToString($FormatHack) /RU SYSTEM /TN Firstboot-qemu-ga /TR \\\"C:\\%s /forcerestart /qn /l+*vx C:\\%s.log\\\"\" > " > msi_path msi_path msi_path in > Firstboot.add_firstboot_script g inspect.i_root >"whatever works" (TM) Acked-by: Laszlo Ersek <lersek at redhat.com>