Skip to content

Commit

Permalink
Make file.symlink/_symlink_check() respect follow_symlinks
Browse files Browse the repository at this point in the history
Fixes: #66980
  • Loading branch information
Tom Doherty committed Oct 22, 2024
1 parent ef2fb24 commit 8865c2e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/66980.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make file.symlink/_symlink_check() respect follow_symlinks
8 changes: 5 additions & 3 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,12 +983,14 @@ def _set_symlink_ownership(path, user, group, win_owner):
return _check_symlink_ownership(path, user, group, win_owner)


def _symlink_check(name, target, force, user, group, win_owner):
def _symlink_check(name, target, force, user, group, win_owner, follow_symlinks=False):
"""
Check the symlink function
"""
changes = {}
if not os.path.exists(name) and not __salt__["file.is_link"](name):
exists = os.path.exists if follow_symlinks else os.path.lexists

if not exists(name) and not __salt__["file.is_link"](name):
changes["new"] = name
return (
None,
Expand Down Expand Up @@ -1788,7 +1790,7 @@ def symlink(
return _error(ret, msg)

tresult, tcomment, tchanges = _symlink_check(
name, target, force, user, group, win_owner
name, target, force, user, group, win_owner, follow_symlinks
)

if not os.path.isdir(os.path.dirname(name)):
Expand Down
7 changes: 7 additions & 0 deletions tests/pytests/unit/modules/file/test_file_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,10 @@ def test_symlink_lexists_called_follow_symlinks_false():
filemod.symlink(tfile, a_link, follow_symlinks=False)
lexists.assert_called()
exists.assert_not_called()

lexists.reset_mock()
exists.reset_mock()

filemod.symlink(tfile, a_link, follow_symlinks=True)
lexists.assert_not_called()
exists.assert_called()

0 comments on commit 8865c2e

Please sign in to comment.