Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return error if patch file passed to state file.patch is malformed #59806

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/59806.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return error if patch file passed to state file.patch is malformed.
4 changes: 4 additions & 0 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7265,6 +7265,10 @@ def _patch(patch_file, options=None, dry_run=False):

pre_check = _patch(patch_file, patch_opts)
if pre_check["retcode"] != 0:
if not os.path.exists(patch_rejects) or os.path.getsize(patch_rejects) == 0:
ret["comment"] = pre_check["stderr"]
ret["result"] = False
return ret
# Try to reverse-apply hunks from rejects file using a dry-run.
msciciel marked this conversation as resolved.
Show resolved Hide resolved
# If this returns a retcode of 0, we know that the patch was
# already applied. Rejects are written from the base of the
Expand Down
3 changes: 2 additions & 1 deletion tests/pytests/integration/states/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ def test_patch_directory_template(
- source: {all_patch_template}
- template: "jinja"
- context: {context}
- strip: 1
""".format(
base_dir=tmp_path, all_patch_template=all_patch_template, context=context
)
Expand All @@ -945,7 +946,7 @@ def test_patch_directory_template(
# Check to make sure the patch was applied okay
state_run = next(iter(ret.data.values()))
assert state_run["result"] is True
assert state_run["comment"] == "Patch was already applied"
assert state_run["comment"] == "Patch successfully applied"

# Re-run the state, should succeed and there should be a message about
# a partially-applied hunk.
Expand Down
Loading