Skip to content

Commit

Permalink
Return error if patch file passed to state file.patch is malformed
Browse files Browse the repository at this point in the history
If patch file provided for file.patch state is malformed then state
returns `Patch was already applied` but patch is not applied.

          ID: patch_example
    Function: file.patch
        Name: /tmp/example
      Result: True
     Comment: Patch was already applied
     Started: 12:20:50.953163
    Duration: 61.558 ms
     Changes:

It is better to return error in such case.

          ID: patch_example
    Function: file.patch
        Name: /tmp/example
      Result: False
     Comment: /usr/bin/patch: **** malformed patch at line 7:
     Started: 12:33:44.915605
    Duration: 59.202 ms
     Changes:
  • Loading branch information
msciciel committed Apr 28, 2021
1 parent 66cf741 commit 6098a52
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/59806.added
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.
5 changes: 5 additions & 0 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6888,6 +6888,11 @@ 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.
# 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

0 comments on commit 6098a52

Please sign in to comment.