[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 1/2] 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.
---
 sysprep/sysprep_operation_machine_id.ml | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/sysprep/sysprep_operation_machine_id.ml b/sysprep/sysprep_operation_machine_id.ml
index fbcc692..190ca5b 100644
--- a/sysprep/sysprep_operation_machine_id.ml
+++ b/sysprep/sysprep_operation_machine_id.ml
@@ -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 = {
-- 
2.1.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]