Skip to content

Commit

Permalink
WIP: fix file.directory clobbering backupname path
Browse files Browse the repository at this point in the history
  • Loading branch information
terminalmage committed Feb 20, 2024
1 parent 736ae6c commit 050a5d3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3897,13 +3897,19 @@ def directory(
if not force:
return _error(
ret,
"File exists where the backup target {} should go".format(
backupname
),
f"File exists where the backup target {backupname} should go",
)
if __opts__["test"]:
ret["changes"][
"forced"
] = f"Existing file at backup path {backupname} would be removed"
else:
__salt__["file.remove"](backupname)
os.rename(name, backupname)

if __opts__["test"]:
ret["changes"]["backup"] = f"{name} would be renamed to {backupname}"
else:
os.rename(name, backupname)
elif force:
# Remove whatever is in the way
if os.path.isfile(name):
Expand Down

0 comments on commit 050a5d3

Please sign in to comment.