Add --follow-symlinks option for backwards compatibility

* src/common.h (follow_symlinks): New variable.
* src/patch.c (longopts): Add new --follow-symlinks option.
(get_some_switches): Recognize the new option.
* src/util.c (stat_file): Follow symlinks if requested.
* patch.man: Document the new option.
* tests/symlinks: Add test case.
This commit is contained in:
Andreas Gruenbacher 2012-09-19 02:01:25 +02:00
parent 59609b50c5
commit 293415dbcf
5 changed files with 21 additions and 1 deletions

View File

@ -600,6 +600,13 @@ diff form.
\fB\-s\fP or \fB\*=silent\fP or \fB\*=quiet\fP
Work silently, unless an error occurs.
.TP
\fB\*=follow\-symlinks\fP
When looking for input files, follow symbolic links. Replaces the symbolic
links, instead of modifying the files the symbolic links point to. Git-style
patches to symbolic links will no longer apply. This option exists for
backwards compatibility with previous versions of patch; its use is
discouraged.
.TP
\fB\-t\fP or \fB\*=batch\fP
Suppress questions like
.BR \-f ,

View File

@ -111,6 +111,7 @@ XTERN bool canonicalize;
XTERN int patch_get;
XTERN bool set_time;
XTERN bool set_utc;
XTERN bool follow_symlinks;
enum diff
{

View File

@ -726,6 +726,7 @@ static struct option const longopts[] =
{"quoting-style", required_argument, NULL, CHAR_MAX + 8},
{"reject-format", required_argument, NULL, CHAR_MAX + 9},
{"read-only", required_argument, NULL, CHAR_MAX + 10},
{"follow-symlinks", no_argument, NULL, CHAR_MAX + 11},
{NULL, no_argument, NULL, 0}
};
@ -1017,6 +1018,9 @@ get_some_switches (void)
else
usage (stderr, 2);
break;
case CHAR_MAX + 11:
follow_symlinks = true;
break;
default:
usage (stderr, 2);
}

View File

@ -1652,5 +1652,8 @@ make_tempfile (char const **name, char letter, char const *real_name,
int stat_file (char const *filename, struct stat *st)
{
return lstat (filename, st) == 0 ? 0 : errno;
int (*xstat)(char const *, struct stat *) =
follow_symlinks ? stat : lstat;
return xstat (filename, st) == 0 ? 0 : errno;
}

View File

@ -54,6 +54,11 @@ File l is not a regular file -- refusing to patch
1 out of 1 hunk ignored -- saving rejects to file l.rej
Status: 1
EOF
check 'patch --follow-symlinks < modify.diff || echo "Status: $?"' <<EOF
patching file l
EOF
# --------------------------------------------------------------
rm -f f l