Skip to content

apply_patch move to same path deletes the file #45310

Closed

Description

@wzsxxa

Description

When apply_patch processes a Move directive where the destination path is the same as the source file path, it writes the new content then immediately removes the file — deleting what was just written. The file ends up missing instead of updated.

Steps to reproduce

  1. Have a file same.txt with content old content
  2. Apply a patch that updates the file and moves it to the same path:
*** Begin Patch
*** Update File: same.txt
*** Move to: same.txt
@@
-old content
+new content
*** End Patch
  1. The file is deleted instead of containing new content

Root cause

In the case "move" branch, when movePath === filePath, the sequence is write(movePath, newContent) → remove(filePath), which removes the file just written. Since both paths resolve to the same absolute path, the remove undoes the write.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions