Bug 11981

Summary: patch does not respect the posix filename determination
Product: Busybox Reporter: Shuang Liu <shuangistan>
Component: Standard ComplianceAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

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