diff -Naurp patch-2.5.9-118-g4e89466/src/patch.c patch-patched/src/patch.c --- patch-2.5.9-118-g4e89466/src/patch.c 2009-06-05 20:25:13.000000000 -0300 +++ patch-patched/src/patch.c 2009-06-19 19:32:56.000000000 -0300 @@ -88,6 +88,7 @@ static char const *patchname; static char *rejname; static char const * volatile TMPREJNAME; static int volatile TMPREJNAME_needs_removal; +static char const *rm_command = NULL; static LINENUM maxfuzz = 2; @@ -360,7 +361,7 @@ main (int argc, char **argv) dry_run ? " and any empty ancestor directories" : ""); if (! dry_run) { - move_file (0, 0, 0, outname, 0, backup); + move_file (0, 0, 0, outname, 0, backup, rm_command); removedirs (outname); } } @@ -384,7 +385,7 @@ main (int argc, char **argv) time_t t; move_file (TMPOUTNAME, &TMPOUTNAME_needs_removal, &outst, - outname, instat.st_mode, backup); + outname, instat.st_mode, backup, NULL); if ((set_time | set_utc) && (t = pch_timestamp (! reverse)) != (time_t) -1) @@ -465,7 +466,7 @@ main (int argc, char **argv) append_to_file (TMPREJNAME, rej); else move_file (TMPREJNAME, &TMPREJNAME_needs_removal, - &rejst, rej, 0666, false); + &rejst, rej, 0666, false, NULL); } } if (!rejname) @@ -563,6 +564,7 @@ static struct option const longopts[] = {"posix", no_argument, NULL, CHAR_MAX + 7}, {"quoting-style", required_argument, NULL, CHAR_MAX + 8}, {"reject-format", required_argument, NULL, CHAR_MAX + 9}, + {"rm-command", required_argument, NULL, CHAR_MAX + 10}, {NULL, no_argument, NULL, 0} }; @@ -594,6 +596,7 @@ static char const *const option_help[] = " -m --merge Merge using conflict markers instead of creating reject files.", #endif " -E --remove-empty-files Remove output files that are empty after patching.", +" --rm-command COMMAND use COMMAND to delete files.", "", " -Z --set-utc Set times of patched files, assuming diff uses UTC (GMT).", " -T --set-time Likewise, assuming local time.", @@ -832,6 +835,9 @@ get_some_switches (void) else usage (stderr, 2); break; + case CHAR_MAX + 10: + rm_command = optarg; + break; default: usage (stderr, 2); } diff -Naurp patch-2.5.9-118-g4e89466/src/util.c patch-patched/src/util.c --- patch-2.5.9-118-g4e89466/src/util.c 2009-06-15 18:00:02.000000000 -0300 +++ patch-patched/src/util.c 2009-06-19 19:43:16.000000000 -0300 @@ -268,7 +268,8 @@ create_backup (char *to, struct stat *to void move_file (char const *from, int volatile *from_needs_removal, struct stat const *fromst, - char *to, mode_t mode, bool backup) + char *to, mode_t mode, bool backup, + char const *rm_command) { struct stat to_st; int to_errno = -1; @@ -328,8 +329,21 @@ move_file (char const *from, int volatil { if (debug & 4) say ("Removing file %s\n", quotearg (to)); - if (unlink (to) != 0 && errno != ENOENT) - pfatal ("Can't remove file %s", quotearg (to)); + if (rm_command == NULL) + { + if (unlink (to) != 0 && errno != ENOENT) + pfatal ("Can't remove file %s", quotearg (to)); + } + else + { + char *cmd = malloc (strlen (rm_command) + strlen (to) + 2); + strcpy (cmd, rm_command); + strcat (cmd, " "); + strcat (cmd, to); + if (systemic (cmd) == -1) + pfatal ("Can't execute custom command %s", quotearg (cmd)); + free (cmd); + } } } diff -Naurp patch-2.5.9-118-g4e89466/src/util.h patch-patched/src/util.h --- patch-2.5.9-118-g4e89466/src/util.h 2009-04-08 01:48:31.000000000 -0300 +++ patch-patched/src/util.h 2009-06-19 15:43:01.000000000 -0300 @@ -64,7 +64,7 @@ void init_backup_hash_table (void); void init_time (void); void xalloc_die (void) __attribute__ ((noreturn)); void create_backup (char *, struct stat *, int *, bool); -void move_file (char const *, int volatile *, struct stat const *, char *, mode_t, bool); +void move_file (char const *, int volatile *, struct stat const *, char *, mode_t, bool, char const *); void read_fatal (void) __attribute__ ((noreturn)); void remove_prefix (char *, size_t); void removedirs (char *);