Skip to content

fix: remove double quotes from patch command path argument#108

Merged
richm merged 1 commit intolinux-system-roles:mainfrom
dgchinner:patch-fix-quotes
Mar 24, 2026
Merged

fix: remove double quotes from patch command path argument#108
richm merged 1 commit intolinux-system-roles:mainfrom
dgchinner:patch-fix-quotes

Conversation

@dgchinner
Copy link
Collaborator

@dgchinner dgchinner commented Mar 24, 2026

The patch command was wrapping the path in double quotes and also using the quote filter, resulting in double-quoted paths being passed to the patch command. The quote filter already handles proper shell escaping, so the extra double quotes are redundant and can cause issues.

Changes:

  • Remove manual double quotes around {{ __hpc_diags_patch_file.path | quote }}
  • Keep the quote filter for proper shell escaping
  • The command now generates: patch -p1 gather_azhpc_vm_diagnostics.sh '/path/to/file' instead of: patch -p1 gather_azhpc_vm_diagnostics.sh "'/path/to/file'"

Created-by-AI: Claude Sonnet 4.5

Prompt: new modification: the patch command double quotes the patch file path, please fix

Summary by Sourcery

Bug Fixes:

  • Fix incorrect double-quoting of the diagnostics patch file path by relying solely on the quote filter for shell escaping.

The patch command was wrapping the path in double quotes and also using the
quote filter, resulting in double-quoted paths being passed to the patch
command. The quote filter already handles proper shell escaping, so the
extra double quotes are redundant and can cause issues.

Changes:
- Remove manual double quotes around {{ __hpc_diags_patch_file.path | quote }}
- Keep the quote filter for proper shell escaping
- The command now generates: patch -p1 gather_azhpc_vm_diagnostics.sh '/path/to/file'
  instead of: patch -p1 gather_azhpc_vm_diagnostics.sh "'/path/to/file'"

Created-by-AI: Claude Sonnet 4.5

Prompt: new modification: the patch command double quotes the patch file path, please fix

Signed-off-by: Dave Chinner <dchinner@redhat.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 24, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the Ansible task that runs the patch command so the patch file path is only shell-escaped via the quote filter and no longer wrapped in redundant manual double quotes, preventing double-quoted paths from being passed to patch.

Sequence diagram for updated patch command invocation

sequenceDiagram
    actor Operator
    participant AnsiblePlaybook as Ansible_playbook
    participant PatchDiagnosticsTask as Patch_Diagnostics_task
    participant Shell as Shell
    participant PatchCmd as patch

    Operator->>AnsiblePlaybook: Run playbook
    AnsiblePlaybook->>PatchDiagnosticsTask: Execute task Patch Diagnostics script
    PatchDiagnosticsTask->>PatchDiagnosticsTask: Resolve __hpc_diags_patch_file.path
    PatchDiagnosticsTask->>PatchDiagnosticsTask: Apply quote filter to path
    PatchDiagnosticsTask->>Shell: Execute
    activate Shell
    Shell->>PatchCmd: patch -p1 gather_azhpc_vm_diagnostics.sh <quoted_path>
    PatchCmd-->>Shell: Apply patch using correctly escaped path
    deactivate Shell
    Shell-->>PatchDiagnosticsTask: Command result
    PatchDiagnosticsTask-->>AnsiblePlaybook: Task status
    AnsiblePlaybook-->>Operator: Playbook result
Loading

Flow diagram for command string construction in patch task

flowchart TD
    A[Start Patch Diagnostics task] --> B[Read __hpc_diags_patch_file.path]
    B --> C[Apply quote filter for shell escaping]
    C --> D[Construct cmd:
patch -p1 gather_azhpc_vm_diagnostics.sh <quoted_path>]
    D --> E[Invoke command module with cmd and chdir]
    E --> F[Shell executes patch with correctly escaped path]
    F --> G[End task]
Loading

File-Level Changes

Change Details Files
Update the patch command invocation to rely solely on the Ansible quote filter for shell-escaping the patch file path, removing redundant manual double quotes.
  • Modify the Ansible command task that patches gather_azhpc_vm_diagnostics.sh to drop explicit double quotes around the patch file path argument
  • Ensure the patch file path is still passed through the quote filter for correct shell escaping
  • Resulting patch command now uses a single-quoted, properly escaped path instead of a doubly quoted string
tasks/main.yml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Since the command module does not invoke a shell, you can avoid relying on quote and string interpolation entirely by using the list form (e.g. cmd: ['patch', '-p1', 'gather_azhpc_vm_diagnostics.sh', __hpc_diags_patch_file.path]), which will make argument handling clearer and less error-prone for future changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since the `command` module does not invoke a shell, you can avoid relying on `quote` and string interpolation entirely by using the list form (e.g. `cmd: ['patch', '-p1', 'gather_azhpc_vm_diagnostics.sh', __hpc_diags_patch_file.path]`), which will make argument handling clearer and less error-prone for future changes.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@richm richm merged commit bc9f857 into linux-system-roles:main Mar 24, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants