problem with patch command not work

whired123

New Member
Joined
Nov 15, 2021
Messages
22
Reaction score
0
Credits
153
Hello everyone, I'll show you the situation right away.

Code:
$ pwd
/var/tmp/tmp.Ov42tdafyq

$ echo OLD > old

$ echo NEW > new

Let's do some tests

Code:
$ diff -u $PWD/old $PWD/new | tee file.patch
--- /var/tmp/tmp.Ov42tdafyq/old    2024-09-01 14:59:23.806596090 +0200
+++ /var/tmp/tmp.Ov42tdafyq/new    2024-09-01 14:59:23.806596090 +0200
@@ -1 +1 @@
-OLD
+NEW

$ patch -d/ -p0 --dry-run < file.patch
checking file /var/tmp/tmp.Ov42tdafyq/old

Now a little attention


Code:
$ mv old old2

$ diff -u $PWD/old2 $PWD/new | tee file.patch
--- /var/tmp/tmp.Ov42tdafyq/old2    2024-09-01 14:59:23.806596090 +0200
+++ /var/tmp/tmp.Ov42tdafyq/new    2024-09-01 14:59:23.806596090 +0200
@@ -1 +1 @@
-OLD
+NEW

$ patch -d/ -p0 --dry-run < file.patch
checking file /var/tmp/tmp.Ov42tdafyq/new
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] 
Skipping patch.
1 out of 1 hunk ignored

Why?
 


According to man patch

-R or --reverse
Assume that this patch was created with the old and new files swapped. (Yes, I'm afraid that does happen occasionally, human nature being what it is.) patch attempts to swap each hunk around before applying it.

It does nothing because you swapped files but when you do so you also need -R option.
 
And how did patch notice this?
Does patch have the power to spy on the commands I give from the terminal (mv old old2)?
I seems so, and it's not that hard to detect when patch file says replace line that says "old" with "old" which makes no sense.
What ever is replaced is supposed to be different, if a line is completely the same then the logic is that file was swapped so you're prompted to reverse it.
 
I seems so,

So patch can interface with the terminal, or maybe with the file system?
It's basically a kind of spyware o_O

and it's not that hard to detect when patch file says replace line that says "old" with "old" which makes no sense.

Where does it say to replace "old" with "old"?
 
Code:
patch -d/ -p0 --dry-run < file.patch
checking file /var/tmp/tmp.Ov42tdafyq/new
Reversed (or previously applied) patch detected! Assume -R? [n]
Apply anyway? [n]
Skipping patch.
1 out of 1 hunk ignored
Your problem is there is no -R option in your code then i it says Assume -R [n] it should be [y]
this will apply newer parts of a newer patch skipping the parts already patched by a previous patch - no it is no spyware it looks for certain files to be patched but you told it no
 
Where does it say to replace "old" with "old"?
I apologize for the mistake, it appeared to me as if you swapped them.

I did investigate this mystery but maybe figured out what's happening.

if you run stat old and stat old2 you'll see timestamps.

Example:

Bash:
echo OLD > old
echo NEW > new
cp old old2

stat old
File: old
<snip>
Birth: 19:41:11.317257863 +0200
stat old2
File: old2
<snip>
Birth: 2024-09-01 19:41:23.961603307 +0200
stat new
File: new
<snip>
Birth: 2024-09-01 19:41:15.901382694 +0200

My testing did not bear any fruit with this though...

In the case above old2 is newer than new according to timestamps so I though patch sees this as not acceptable but it's not that, for ex. recreating timestamps:

Bash:
rm new
echo NEW > new
diff -u $PWD/old2 $PWD/new | tee file2.patch
patch --dry-run < file2.patch
Does not fix the problem.

But I'm sure it has something to do with timestamps, this is the only info about the files other than contents.
 
But I'm sure it has something to do with timestamps, this is the only info about the files other than contents.
@whired123
I figured out what's happening! file name to which you move or copy has to be same length in terms of letters lol

Example that makes it work:

Bash:
echo OLD > old
echo NEW > new
mv old ol2
diff -u $PWD/ol2 $PWD/new | tee file.patch
patch --dry-run < file.patch

However if the new file name is not 3 letters like "old" is, then it's problem:

Bash:
echo OLD > old
echo NEW > new
mv old not3letters
diff -u $PWD/not3letters $PWD/new | tee file.patch
patch --dry-run < file.patch

I guess nobody knows why, and who ever programmed the patch command must be either a genius or something far worse hahah
 
Last edited:

Members online


Top