mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix file.directory clobbering backupname path with test=True
This commit is contained in:
parent
c402aab17c
commit
fb86bf3423
1 changed files with 16 additions and 4 deletions
|
@ -3888,13 +3888,25 @@ 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}"
|
||||
ret["changes"][name] = {"directory": "new"}
|
||||
ret[
|
||||
"comment"
|
||||
] = f"{name} would be backed up and replaced with a new directory"
|
||||
ret["result"] = None
|
||||
return ret
|
||||
else:
|
||||
os.rename(name, backupname)
|
||||
elif force:
|
||||
# Remove whatever is in the way
|
||||
if os.path.isfile(name):
|
||||
|
|
Loading…
Add table
Reference in a new issue