Bug 11981 - patch does not respect the posix filename determination
Summary: patch does not respect the posix filename determination
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: unspecified
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-24 15:18 UTC by Shuang Liu
Modified: 2019-06-24 15:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shuang Liu 2019-06-24 15:18:17 UTC
If a filename is not given, busybox patch uses the newname in the line +++.
This does not align with the posix filename determination rule.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/patch.html
The posix filename determination said:

If the type of diff is context, the patch utility shall delete the pathname components (as specified by the -p option) from the filename on the line beginning with "---" (if copied context) or "+++" (if unified context), then test for the existence of this file relative to the current directory (or the directory specified with the -d option). If the file exists, the patch utility shall use this filename.


Steps to Reproduce:

$ echo test > test.txt
$ echo updated_test > utest.txt

$ diff -u test.txt utest.txt
--- test.txt
+++ utest.txt
@@ -1 +1 @@
-test
+updated_test

$ diff -u test.txt utest.txt > test.patch

$ busybox patch < test.patch
patching file utest.txt
Hunk 1 FAILED 1/1.
-test
+updated_test


Expected behavior with GNU patch --posix:
$ patch --posix < test.patch
patching file test.txt