mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
fixes saltstack/salt#64477 file.symlink will not replace/update existing symlink
This commit is contained in:
parent
ae14412da3
commit
77482013d6
3 changed files with 26 additions and 1 deletions
1
changelog/64477.fixed.md
Normal file
1
changelog/64477.fixed.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix file.symlink will not replace/update existing symlink
|
|
@ -1791,9 +1791,11 @@ def symlink(
|
||||||
|
|
||||||
if __salt__["file.is_link"](name):
|
if __salt__["file.is_link"](name):
|
||||||
# The link exists, verify that it matches the target
|
# The link exists, verify that it matches the target
|
||||||
if os.path.normpath(__salt__["file.readlink"](name)) == os.path.normpath(
|
if os.path.normpath(__salt__["file.readlink"](name)) != os.path.normpath(
|
||||||
target
|
target
|
||||||
):
|
):
|
||||||
|
__salt__["file.remove"](name)
|
||||||
|
else:
|
||||||
if _check_symlink_ownership(name, user, group, win_owner):
|
if _check_symlink_ownership(name, user, group, win_owner):
|
||||||
# The link looks good!
|
# The link looks good!
|
||||||
if salt.utils.platform.is_windows():
|
if salt.utils.platform.is_windows():
|
||||||
|
|
|
@ -201,3 +201,25 @@ def test_file_managed_web_source_etag_operation(
|
||||||
|
|
||||||
# The modified time of the cached file now changes
|
# The modified time of the cached file now changes
|
||||||
assert cached_file_mtime != os.path.getmtime(cached_file)
|
assert cached_file_mtime != os.path.getmtime(cached_file)
|
||||||
|
|
||||||
|
|
||||||
|
def test_file_symlink_replace_existing_link(states, tmp_path):
|
||||||
|
# symlink name and target for state
|
||||||
|
name = tmp_path / "foo"
|
||||||
|
target = tmp_path / "baz"
|
||||||
|
|
||||||
|
# create existing symlink to replace
|
||||||
|
old_target = tmp_path / "bar"
|
||||||
|
name.symlink_to(old_target)
|
||||||
|
|
||||||
|
ret = states.file.symlink(
|
||||||
|
name=str(name),
|
||||||
|
target=str(target),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert ret.filtered == {
|
||||||
|
"name": str(name),
|
||||||
|
"changes": {"new": str(name)},
|
||||||
|
"comment": f"Created new symlink {str(name)} -> {str(target)}",
|
||||||
|
"result": True,
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue