Merge pull request #24646 from twangboy/fix_24196

Fixed user.present on existing user
This commit is contained in:
Shane Lee 2015-06-15 09:04:43 -06:00
commit a18dadad71
2 changed files with 10 additions and 4 deletions

View file

@ -162,15 +162,16 @@ def removegroup(name, group):
return ret['retcode'] == 0
def chhome(name, home):
def chhome(name, home, persist=False):
'''
Change the home directory of the user
Change the home directory of the user, pass True for persist to move files
to the new home directory if the old home directory exist.
CLI Example:
.. code-block:: bash
salt '*' user.chhome foo \\\\fileserver\\home\\foo
salt '*' user.chhome foo \\\\fileserver\\home\\foo True
'''
pre_info = info(name)
@ -184,6 +185,11 @@ def chhome(name, home):
if __salt__['cmd.retcode'](cmd, python_shell=False) != 0:
return False
if persist and home is not None and pre_info['home'] is not None:
cmd = 'move /Y {0} {1}'.format(pre_info['home'], home)
if __salt__['cmd.retcode'](cmd, python_shell=False) != 0:
log.debug('Failed to move the contents of the Home Directory')
post_info = info(name)
if post_info['home'] != pre_info['home']:
return post_info['home'] == home

View file

@ -109,7 +109,7 @@ def _changes(name,
change['home'] = home
if createhome:
newhome = home if home else lusr['home']
if not os.path.isdir(newhome):
if newhome is not None and not os.path.isdir(newhome):
change['homeDoesNotExist'] = newhome
if shell: