Turn the snippet reading user information from /etc/passwd in a slightly
more generic function, so there is no need to copy&paste for other
details.

Mostly code motion.
---
 customize/ssh_key.ml | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/customize/ssh_key.ml b/customize/ssh_key.ml
index a4e4a51..7c482e7 100644
--- a/customize/ssh_key.ml
+++ b/customize/ssh_key.ml
@@ -106,13 +106,15 @@ let do_ssh_inject_unix (g : Guestfs.guestfs) user 
selector =
 
   (* Get user's home directory. *)
   g#aug_init "/" 0;
-  let home_dir =
+  let read_user_detail what =
     try
-      let expr = sprintf "/files/etc/passwd/%s/home" user in
+      let expr = sprintf "/files/etc/passwd/%s/%s" user what in
       g#aug_get expr
     with G.Error _ ->
       error (f_"ssh-inject: the user %s does not exist on the guest")
-        user in
+        user
+  in
+  let home_dir = read_user_detail "home" in
   g#aug_close ();
 
   (* Create ~user/.ssh if it doesn't exist. *)
-- 
2.5.5

_______________________________________________
Libguestfs mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libguestfs

Reply via email to