diff options
author | Andreas Gruenbacher <agruen@suse.de> | 2010-04-29 02:55:40 +0200 |
---|---|---|
committer | Andreas Gruenbacher <agruen@suse.de> | 2010-05-02 11:42:28 +0200 |
commit | 12fdbd5cec18539bd87cc89e5a917afeea831631 (patch) | |
tree | 103a02a28ec00fed912714f58dd9adad70d6a7c1 | |
parent | a41a918fe7e4f5b03a603e1b44fc180512b6ec1d (diff) | |
download | patch-12fdbd5cec18539bd87cc89e5a917afeea831631.tar.gz |
Pass up the file type and check for consistent types
* src/pch.c (intuit_diff_type, there_is_another_patch): Pass up the
file type.
* src/patch.c (main): Check for consistent file types.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/patch.c | 13 | ||||
-rw-r--r-- | src/pch.c | 9 | ||||
-rw-r--r-- | src/pch.h | 2 |
4 files changed, 22 insertions, 6 deletions
@@ -1,5 +1,9 @@ 2009-04-29 Andreas Gruenbacher <agruen@suse.de> + * src/pch.c (intuit_diff_type, there_is_another_patch): Pass up the + file type. + * src/patch.c (main): Check for consistent file types. + * src/pch.c (intuit_diff_type): Only check for reversed patches when the input file type matches the patch file type. diff --git a/src/patch.c b/src/patch.c index ba98c31..1eaa921 100644 --- a/src/patch.c +++ b/src/patch.c @@ -102,6 +102,7 @@ main (int argc, char **argv) char numbuf[LINENUM_LENGTH_BOUND + 1]; bool written_to_rejname = false; bool apply_empty_patch = false; + mode_t file_type; exit_failure = 2; program_name = argv[0]; @@ -167,7 +168,7 @@ main (int argc, char **argv) } for ( open_patch_file (patchname); - there_is_another_patch (! (inname || posixly_correct)) + there_is_another_patch (! (inname || posixly_correct), &file_type) || apply_empty_patch; reinitialize_almost_everything(), apply_empty_patch = false @@ -177,6 +178,16 @@ main (int argc, char **argv) bool mismatch = false; char *outname = NULL; + if (! skip_rest_of_patch && ! file_type) + { + say ("File %s: can't change file type from 0%o to 0%o.\n", + quotearg (inname), + pch_mode (reverse) & S_IFMT, + pch_mode (! reverse) & S_IFMT); + skip_rest_of_patch = true; + somefailed = true; + } + if (! skip_rest_of_patch) { outname = outfile ? outfile : inname; @@ -68,7 +68,7 @@ static lin p_bfake = -1; /* beg of faked up lines */ static char *p_c_function; /* the C function a hunk is in */ static char *scan_linenum (char *, lin *); -static enum diff intuit_diff_type (bool); +static enum diff intuit_diff_type (bool, mode_t *); static enum nametype best_name (char * const *, int const *); static int prefix_components (char *, bool); static size_t pget_line (size_t, int, bool, bool); @@ -213,7 +213,7 @@ maybe_reverse (char const *name, bool nonexistent, bool is_empty) /* True if the remainder of the patch file contains a diff of some sort. */ bool -there_is_another_patch (bool need_header) +there_is_another_patch (bool need_header, mode_t *file_type) { if (p_base != 0 && p_base >= p_filesize) { if (verbosity == VERBOSE) @@ -222,7 +222,7 @@ there_is_another_patch (bool need_header) } if (verbosity == VERBOSE) say ("Hmm..."); - diff_type = intuit_diff_type (need_header); + diff_type = intuit_diff_type (need_header, file_type); if (diff_type == NO_DIFF) { if (verbosity == VERBOSE) say (p_base @@ -339,7 +339,7 @@ fetchmode (char const *str) /* Determine what kind of diff is in the remaining part of the patch file. */ static enum diff -intuit_diff_type (bool need_header) +intuit_diff_type (bool need_header, mode_t *p_file_type) { file_offset this_line = 0; file_offset first_command_line = -1; @@ -703,6 +703,7 @@ intuit_diff_type (bool need_header) if (! file_type) file_type = S_IFREG; } + *p_file_type = file_type; /* To intuit `inname', the name of the file to patch, use the algorithm specified by POSIX 1003.1-2001 XCU lines 25680-26599 @@ -33,7 +33,7 @@ lin pch_repl_lines (void); lin pch_suffix_context (void); bool pch_swap (void); bool pch_write_line (lin, FILE *); -bool there_is_another_patch (bool); +bool there_is_another_patch (bool, mode_t *); char *pfetch (lin); char pch_char (lin); int another_hunk (enum diff, bool); |