Added more symlink funtionality

Cleaned up some of the comments/doc language
This commit is contained in:
Mickey Malone 2013-09-25 22:21:27 -05:00
parent 8c91eb3558
commit 2675f34079
2 changed files with 22 additions and 10 deletions

View file

@ -308,11 +308,9 @@
# - roots
#
# Uncomment the line below if you do not want the file_server to follow
# symlinks when walking the filesystem tree. This is set to True
# symlinks when walking the filesystem tree. This is set to True
# by default. Currently this only applies to the default roots
# fileserver_backend. Leave this option commented if you are using the
# state module file.recurse with symlinks set to True unless your symlinks
# are only 1 deep.
# fileserver_backend.
#
#fileserver_followsymlinks: False
#

View file

@ -1351,6 +1351,7 @@ def recurse(name,
exclude_pat=None,
maxdepth=None,
keep_symlinks=False,
force_symlinks=False,
**kwargs):
'''
Recurse through a subdirectory on the master and copy said subdirectory
@ -1388,7 +1389,7 @@ def recurse(name,
The permissions mode to set any files created
sym_mode
the permissions mode to set on any symlink created
The permissions mode to set on any symlink created
template
If this setting is applied then the named templating engine will be
@ -1441,8 +1442,17 @@ def recurse(name,
or immediate subdirectories
keep_symlinks
Keep symlinks when copying from the source. Set this to True if
keeping symlinks intact is desired.
Keep symlinks when copying from the source. This option will cause
the copy operation to terminate at the symlink. If you are after
rsync-ish behavior, then set this to True.
force_symlinks
Force symlink creation. This option will force the symlink creation.
If a file or directory is obstructing symlink creation it will be
recursively removed so that symlink creation can proceed. This
option is usually not needed except in special circumstances. It
is a very powerful option, and can cripple a system if used
inappropriately.
'''
user = _test_owner(kwargs, user=user)
ret = {'name': name,
@ -1580,8 +1590,9 @@ def recurse(name,
require=None)
merge_ret(path, _ret)
# Process symlinks and return the updated filenames list to be processed
# Process symlinks and return the updated filenames list
def process_symlinks(filenames, symlinks):
log.debug("keep in ps {0}".format(keep))
for lname, ltarget in symlinks.items():
if not _check_include_exclude(os.path.relpath(lname, srcpath),
include_pat,
@ -1608,12 +1619,15 @@ def recurse(name,
_ret = symlink(os.path.join(name, srelpath),
ltarget,
makedirs=True,
force=force_symlinks,
user=user,
group=group,
mode=sym_mode)
if not _ret:
continue
merge_ret(os.path.join(name,srelpath),_ret)
# Add the path to the keep set in case clean is set to True
keep.add(os.path.join(name, srelpath))
return filenames
# If source is a list, find which in the list actually exists
source, source_hash = __salt__['file.source_list'](source, '', env)
@ -1626,9 +1640,9 @@ def recurse(name,
# use '/' since #master only runs on POSIX
srcpath = srcpath + '/'
fns_ = __salt__['cp.list_master'](env, srcpath)
# If we are instructed to keep symlinks, then process them
# If we are instructed to keep symlinks, then process them.
if keep_symlinks:
# Make this global so that emptydirs can use it if needed
# Make this global so that emptydirs can use it if needed.
symlinks = __salt__['cp.list_master_symlinks'](env, srcpath)
fns_ = process_symlinks(fns_, symlinks)
for fn_ in fns_: