sysprep: machine_id: simplify implementation

Instead of rm + touch, just truncate the file if existing.
In case there was no file previously, now nothing is created, as most
probably the system was fine even without it.

Also, turn the single path into a list, so more machine-id files can be
handled at once.
This commit is contained in:
Pino Toscano
2015-07-29 13:36:23 +02:00
parent dbbf4b8afe
commit bc598ff52a

View File

@@ -21,15 +21,12 @@ open Common_gettext.Gettext
module G = Guestfs
let machine_id_perform g root side_effects =
let machine_id_perform (g : Guestfs.guestfs) root side_effects =
let typ = g#inspect_get_type root in
if typ <> "windows" then (
let path = "/etc/machine-id" in
(try g#rm path with G.Error _ -> ());
(try
g#touch path;
side_effects#created_file ()
with G.Error _ -> ());
let paths = [ "/etc/machine-id"; ] in
let paths = List.filter g#is_file paths in
List.iter g#truncate paths
)
let op = {