saltstack/salt — pull request #19069 by benosman (2014-12-17 23:34:34+00:00)
Title: Add allow_symlink parameter to allow enforcing real directories.

Here is a pull request for #19053.

>I have a situation where I need to ensure that a path contains a real directory, but the current file.directory state cannot determine if it is a real directory or a symlink to a directory.
>
>This is because python's os.path.isdir() method returns true for a symlinked directory too. I propose adding an 'allow_symlink' argument (probably set to True by default to not break existing sls files).
>
>If allow_symlink is false, then it should check os.path.islink(), and if that returns true then it should remove the link and create the directory.
>
>Alternatively, the existing force parameter could be used and a check made to os.path.islink() as well as os.path.isfile().

This commit implements this new allow_symlink argument to file.directory, with the default set to True to allow any existing sls files to run just as before.

If however, the allow_symlink is set to False, if it detects a symlink in place of a directory it will fail with an error, unless force is set where it will forcibly replace the symlink with a directory. (same behaviour as currently with files)

Feedback and testing appreciated!