[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    patch command doesn't respect "\ No newline at end of file"
From:       Bryan Green <bryan () aetheros ! com>
Date:       2023-01-12 23:17:44
Message-ID: CAOxiEDZD9tPs-YGow9xFDgLQbegcGpFO06OJNZM5=1sMqteHdg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


The busybox version of the patch command is not handling patches correctly
which end with "\ No newline at end of file".
If the patch is from a file with a newline to one without, the patch
command "succeeds" but does not remove the newline.
If the patch is from a file without a newline to one with a newline, the
patch command fails with a "Hunk ... FAILED" error.

I'm using busybox v1.23.2, but I don't see any source code changes since
then that would affect this behavior.

Here is a log to show how I reproduced the issue.

# echo -n line > nonewline
/data # hexdump -Cv nonewline
00000000  6c 69 6e 65                                       |line|
00000004
# echo line > withnewline
# hexdump -Cv withnewline
00000000  6c 69 6e 65 0a                                    |line.|
00000005
# diff withnewline nonewline > rmnewline.patch
# cat rmnewline.patch
--- withnewline
+++ nonewline
@@ -1 +1 @@
-line
+line
\ No newline at end of file
# cp withnewline withnewline.tmp
# patch withnewline.tmp rmnewline.patch
patching file withnewline.tmp
# hexdump -Cv withnewline.tmp
00000000  6c 69 6e 65 0a                                    |line.|
00000005
/data # diff nonewline withnewline > addnewline.patch
/data # cat addnewline.patch
--- nonewline
+++ withnewline
@@ -1 +1 @@
-line
\ No newline at end of file
+line
/data # cp nonewline nonewline.tmp
/data # patch nonewline.tmp addnewline.patch
patching file nonewline.tmp
Hunk 1 FAILED 1/1.
-line

[Attachment #5 (text/html)]

<div dir="ltr">The busybox version of the patch command is not handling patches \
correctly which end with &quot;\ No newline at end of file&quot;.<br>If the patch is \
from a file with a newline to one without, the patch command &quot;succeeds&quot; but \
does not remove the newline.<br>If the patch is from a file without a newline to one \
with a newline, the patch command fails with a &quot;Hunk ... FAILED&quot; \
error.<br><br>I&#39;m using busybox v1.23.2, but I don&#39;t see any source code \
changes since then that would affect this behavior.<br><br>Here is a log to show how \
I reproduced the issue.<br><br><div># echo -n line &gt; nonewline</div><div>/data # \
hexdump -Cv nonewline<br>00000000   6c 69 6e 65                                       \
|line|<br>00000004<br></div><div># echo line &gt; withnewline</div><div># hexdump -Cv \
withnewline<br>00000000   6c 69 6e 65 0a                                              \
|line.|<br>00000005</div># diff withnewline nonewline &gt; rmnewline.patch<br># cat \
rmnewline.patch<br>--- withnewline<br>+++ nonewline<br>@@ -1 +1 \
@@<br>-line<br>+line<br><div>\ No newline at end of file</div><div># cp withnewline \
withnewline.tmp</div># patch withnewline.tmp rmnewline.patch<br>patching file \
withnewline.tmp<br># hexdump -Cv withnewline.tmp<br>00000000   6c 69 6e 65 0a         \
|line.|<br>00000005<br>/data # diff nonewline withnewline &gt; \
addnewline.patch<br>/data # cat addnewline.patch<br>--- nonewline<br>+++ \
withnewline<br>@@ -1 +1 @@<br>-line<br>\ No newline at end of file<br>+line<br>/data \
# cp nonewline nonewline.tmp<br>/data # patch nonewline.tmp \
addnewline.patch<br>patching file nonewline.tmp<br>Hunk 1 FAILED \
1/1.<br>-line<br><br><br></div>



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic