Instead of failing to add the user whose home directory already exists, we
should just fix the owner of the home directory to the UID of the newly created
user.
Signed-off-by: Vratislav Podzimek <vpodzime(a)redhat.com>
---
pyanaconda/users.py | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/pyanaconda/users.py b/pyanaconda/users.py
index 7ec594c..598ac08 100644
--- a/pyanaconda/users.py
+++ b/pyanaconda/users.py
@@ -281,9 +281,22 @@ class Users:
if kwargs.get("gecos", False):
userEnt.set(libuser.GECOS, kwargs["gecos"])
- self.admin.addUser(userEnt,
mkmailspool=kwargs.get("mkmailspool", True))
+ # need to create home directory for the user or does it already exist?
+ # userEnt.get returns lists (usually with a single item)
+ mk_homedir = not os.path.exists(userEnt.get(libuser.HOMEDIRECTORY)[0])
+
+ self.admin.addUser(userEnt,
mkmailspool=kwargs.get("mkmailspool", True),
+ mkhomedir=mk_homedir)
self.admin.addGroup(groupEnt)
+ if not mk_homedir:
+ log.info("Home directory for the user %s already existed,
"
+ "fixing the owner." % user_name)
+ # home directory already existed, change owner of it properly
+ iutil.chown_dir_tree(userEnt.get(libuser.HOMEDIRECTORY)[0],
+ userEnt.get(libuser.UIDNUMBER)[0],
+ groupEnt.get(libuser.GIDNUMBER)[0])
+
if kwargs.get("password", False):
if kwargs.get("isCrypted", False):
password = kwargs["password"]
--
1.7.11.7