diff --git a/common/mlstdutils/std_utils.ml b/common/mlstdutils/std_utils.ml index 70156d1ba..4237ea519 100644 --- a/common/mlstdutils/std_utils.ml +++ b/common/mlstdutils/std_utils.ml @@ -269,6 +269,8 @@ module String = struct else loop (i+1) in loop 0 + + let unix2dos str = replace str "\n" "\r\n" end module List = struct diff --git a/common/mlstdutils/std_utils.mli b/common/mlstdutils/std_utils.mli index 5e5242f7a..3c78f02bc 100644 --- a/common/mlstdutils/std_utils.mli +++ b/common/mlstdutils/std_utils.mli @@ -131,6 +131,11 @@ module String : sig segment of [str] which contains only bytes {!i not} in [reject]. These work exactly like the C functions [strspn] and [strcspn]. *) + val unix2dos : string -> string + (** Convert string with ordinary Unix-style line-endings to + CRLF DOS-style line-endings. + + The same as {!String.replace} [str "\n" "\r\n"]. *) end (** Override the String module from stdlib. *) diff --git a/customize/firstboot.ml b/customize/firstboot.ml index 7adea37f4..a8f4ef7c3 100644 --- a/customize/firstboot.ml +++ b/customize/firstboot.ml @@ -24,9 +24,6 @@ open Common_gettext.Gettext open Regedit -let unix2dos s = - String.concat "\r\n" (String.nsplit "\n" s) - let sanitize_name = let rex = PCRE.compile ~caseless:true "[^a-z0-9_]" in fun n -> @@ -313,7 +310,8 @@ echo uninstalling firstboot service %s -s firstboot uninstall " firstboot_dir_win srvany in - g#write (firstboot_dir // "firstboot.bat") (unix2dos firstboot_script); + g#write (firstboot_dir // "firstboot.bat") + (String.unix2dos firstboot_script); (* Open the SYSTEM hive. *) Registry.with_hive_write g (g#inspect_get_windows_system_hive root) @@ -363,7 +361,7 @@ let add_firstboot_script (g : Guestfs.guestfs) root name content = | "windows", _ -> let firstboot_dir = Windows.install_service g root in let filename = firstboot_dir // "scripts" // filename ^ ".bat" in - g#write filename (unix2dos content) + g#write filename (String.unix2dos content) | _ -> error (f_"guest type %s/%s is not supported") typ distro