diff options
author | Milan Bouchet-Valat <nalimilan@club.fr> | 2010-08-21 15:08:26 +0200 |
---|---|---|
committer | Milan Bouchet-Valat <nalimilan@club.fr> | 2010-08-21 15:18:12 +0200 |
commit | 588884656b257a06be3703a96ee1a347e7c3aac5 (patch) | |
tree | d9ebf7e86ffa00a90ee18c45ef900dc34bbb093b | |
parent | 942f9320a4e8571d94749e7461683d76b40fa9c5 (diff) |
Support erase_home flag when creating user
This flag causes home dir to be erased, leaving platform tools
to fill it with skel files. This has no effect if path to home
dir isn't specified (meaning default).
-rw-r--r-- | Users/Users.pm | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Users/Users.pm b/Users/Users.pm index d2b6812..c195140 100644 --- a/Users/Users.pm +++ b/Users/Users.pm @@ -557,11 +557,23 @@ sub add_user # When using default prefix, we assume the directory exists. if ($$user[$HOME]) { - my ($home_parents); + my $home_parents, $erase_home; $home_parents = $$user[$HOME]; $home_parents =~ s/\/+[^\/]+\/*$//; &Utils::File::run ($tool_mkdir, "-p", $home_parents); + + $erase_home = $$user[$HOME_FLAGS] & (1 << 3); + + # Remove home if asked, it will be created from scratch by platform tools + if ($erase_home && -e $$user[$HOME] && $$user[$HOME] ne "/") + { + # Remove trailing slash(es) to avoid issues with rm on symlinks + $$user[$HOME] =~ s|/*$||; + + @command = ("rm", "-Rf", $$user[$HOME]); + &Utils::File::run (@command); + } } # max value means default UID or GID here |