#613605 patch -b and -V options, overwrites file.orig despite manpage description

Package:
patch
Source:
patch
Description:
Apply a diff file to an original
Submitter:
ant
Date:
2022-01-13 12:36:03 UTC
Severity:
normal
#613605#5
Date:
2011-02-16 03:01:41 UTC
From:
To:
hello,

  the following description in the manpage says (below), but
when using patch -b and not specifying -V, it clobbers the .orig
file instead of using the numbered or t method as explained
as the default.  from the description i was expecting a file
name like X.c.orig.0 to be created if X.c.orig already existed.

  i'm not sure what the actual intended default is, but i'm pretty
sure some people don't want their .orig files overwritten.

  the added text to the simple method that reflects current behavior
would be something like:

  "simple overwrites the file.orig if it already exists."

  thanks for your attention,  having much fun, enjoying
wheezy/testing  :)


==================

     -V method  or  --version-control=method
....

          existing  or  nil
             Make  numbered backups of files that already have them, otherwise
simple
             backups.  This is the default.

          numbered  or  t
             Make numbered backups.  The numbered backup file name  for  F  is
F.~N~
             where N is the version number.

          simple  or  never
             Make  simple  backups.  The -B or --prefix, -Y or --basename-
prefix, and
             -z or --suffix options specify the simple backup file name.  If
none  of
             these  options are given, then a simple backup suffix is used; it
is the
             value of the SIMPLE_BACKUP_SUFFIX environment variable if  set,
and  is
             .orig otherwise.

#613605#10
Date:
2011-02-17 08:17:21 UTC
From:
To:
  simple example:

==========

me@ant(15)~/tmp$ cat a
a
me@ant(16)~/tmp$ cat b
a\nb
me@ant(17)~/tmp$ echo "a" > b
me@ant(18)~/tmp$ echo "b" >> b
me@ant(19)~/tmp$ cat a
a
me@ant(20)~/tmp$ cat b
a
b
me@ant(21)~/tmp$ diff -C 3 a b
*** a	2011-02-17 02:27:51.000000000 -0500
--- b	2011-02-17 02:28:53.000000000 -0500
***************
*** 1 ****
--- 1,2 ----
  a
+ b
me@ant(22)~/tmp$ diff -C 3 a b > ab.diff
me@ant(23)~/tmp$ ls
total 12
-rw-r--r-- 1 me me   2 Feb 17 02:27 a
-rw-r--r-- 1 me me 132 Feb 17 02:29 ab.diff
-rw-r--r-- 1 me me   4 Feb 17 02:28 b
me@ant(24)~/tmp$ patch --dry-run -b a ab.diff
patching file a
me@ant(25)~/tmp$ ls
total 12
-rw-r--r-- 1 me me   2 Feb 17 02:27 a
-rw-r--r-- 1 me me 132 Feb 17 02:29 ab.diff
-rw-r--r-- 1 me me   4 Feb 17 02:28 b
me@ant(26)~/tmp$ touch a.orig
me@ant(27)~/tmp$ patch --dry-run -b a ab.diff
patching file a
me@ant(28)~/tmp$ ls
total 12
-rw-r--r-- 1 me me   2 Feb 17 02:27 a
-rw-r--r-- 1 me me 132 Feb 17 02:29 ab.diff
-rw-r--r-- 1 me me   0 Feb 17 02:30 a.orig
-rw-r--r-- 1 me me   4 Feb 17 02:28 b
me@ant(29)~/tmp$ patch -b a ab.diff
patching file a
me@ant(30)~/tmp$ ls
total 16
-rw-r--r-- 1 me me   4 Feb 17 02:31 a
-rw-r--r-- 1 me me 132 Feb 17 02:29 ab.diff
-rw-r--r-- 1 me me   2 Feb 17 02:27 a.orig
-rw-r--r-- 1 me me   4 Feb 17 02:28 b

#
# whups, where did a.orig go?
#

me@ant(31)~/tmp$ diff -C 3 a.orig a
*** a.orig	2011-02-17 02:27:51.000000000 -0500
--- a	2011-02-17 02:31:19.000000000 -0500
***************
*** 1 ****
--- 1,2 ----
  a
+ b
me@ant(32)~/tmp$ diff -C 3 a.orig a > ab.newdiff
me@ant(33)~/tmp$ patch -b a.orig ab.newdiff
patching file a.orig
me@ant(34)~/tmp$ ls
total 24
-rw-r--r-- 1 me me   4 Feb 17 02:31 a
-rw-r--r-- 1 me me 132 Feb 17 02:29 ab.diff
-rw-r--r-- 1 me me 137 Feb 17 03:12 ab.newdiff
-rw-r--r-- 1 me me   4 Feb 17 03:12 a.orig
-rw-r--r-- 1 me me   2 Feb 17 02:27 a.orig.orig
-rw-r--r-- 1 me me   4 Feb 17 02:28 b
me@ant(35)~/tmp$

#
# this is really strange...
#
#   a.orig.orig now gets created?  i stop here now...
#
===================

#613605#15
Date:
2019-08-22 23:04:47 UTC
From:
To:
I looked at the documentation and the examples provided here and they
are working as documented. I don't think there is a bug here.

Now, in theory, it might be nice to have a flag which prevents old .orig
files from being overwritten. I can see how that would be beneficial.
But the examples provided here are working as intended.

- Jesse

#613605#20
Date:
2022-01-12 22:43:26 UTC
From:
To:
Sorry, but I disagree and think this is a bug in Debian 11, GNU patch
2.7.6.  -b forces a backup file, and the manual says of "-V existing":

   Make numbered backups of files that already have them, otherwise
simple backups.  This is the default.

This example shows that the first patch application creates a backup
file, and the second patch application overwrites it and does not
instead create a numbered file:

     $ echo 1 > a
     $ cp a b
     $ echo 2 >> b
     $ diff a b > diff1
     $ patch -b -V existing a < diff1
     patching file a
     $ ls -C
     a  a.orig  b  diff1  diff2
     $ echo 3 >> b
     $ diff a b > diff2
     $ patch -b -V existing a < diff2
     patching file a
     $ ls -C
     a  a.orig  b  diff1  diff2
     $ cat a.orig
     1
     2

#613605#25
Date:
2022-01-13 12:32:45 UTC
From:
To:
I think I understand the manual text now.  I read it as create numbered
files only if the backup file exists, but I now see it can be read as
create numbered files only if other numbered files already exist.  I
think "have them" is unclear. Maybe the text should be clarified to:

     Make numbered backups of files that already have numbered backups,
otherwise simple backups.  This is the default.