On Tuesday 02 September 2014 16:54:12 Richard W.M. Jones wrote:
On Tue, Sep 02, 2014 at 05:33:26PM +0200, Pino Toscano wrote:
> Query using augeas for the home directory of an user, instead of
> hardcoding /home/<username>.
> ---
>
> sysprep/sysprep_operation_user_account.ml | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/sysprep/sysprep_operation_user_account.ml
> b/sysprep/sysprep_operation_user_account.ml index 3d88ffc..dc194f4
> 100644
> --- a/sysprep/sysprep_operation_user_account.ml
> +++ b/sysprep/sysprep_operation_user_account.ml
> @@ -84,6 +84,8 @@ let user_account_perform ~verbose ~quiet g root
> side_effects =>
> String.sub userpath (i+1) (String.length userpath -i-1)
> in
>
> if uid >= uid_min && uid <= uid_max
>
> && check_remove_user username then (
>
> + (* Get the home before removing the passwd entry. *)
> + let home_dir = g#aug_get (userpath ^ "/home") in
I suspect you'll want to catch an exception here (G.Error I _think_?)
Hm ok.
Not sure how to handle the exception -- perhaps by ignoring the user
and continuing to the next one, and certainly by not deleting any
directories ...
So should the user still be removed? In such case, I guess something
like (simplified):
let home_dir =
try Some g#aug_get (userpath ^ "/home")
with _ ->
if verbose then warning "Cannot get the home directory for $user";
None in
...
match home_dir with
| None -> ()
| Some dir -> g#rm_rf dir
?
--
Pino Toscano