From 8ed83176406a96c50b9ce6d34ea447c1cf38fef3 Mon Sep 17 00:00:00 2001 From: Tom Doherty Date: Fri, 18 Oct 2024 11:27:36 +0100 Subject: [PATCH] Make file.symlink/_symlink_check() respect follow_symlinks Fixes: #66980 --- changelog/66980.fixed.md | 1 + salt/states/file.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelog/66980.fixed.md diff --git a/changelog/66980.fixed.md b/changelog/66980.fixed.md new file mode 100644 index 00000000000..499e1961eb1 --- /dev/null +++ b/changelog/66980.fixed.md @@ -0,0 +1 @@ +make file.symlink/_symlink_check() respect follow_symlinks diff --git a/salt/states/file.py b/salt/states/file.py index f33727a8ba5..e2907889e00 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -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, @@ -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)):