Fix bug bin/47367: patch(1) mishandles Oops.rej The NetBSD Project
Status: Closed Time to complete: 144 hrs Mentors: Julian Coleman Tags: C, system

From the bug report:

the patch program fails when the file to be patched does not exist.

Note, that there are two problems:

  1) the reject filename is always ./Oops.rej, and new reject files overwrite the original/previous

  2) the reject file does not contain the patch header (i.e. the name of the missing file)

For this task, both these problems should be solved.  For the first, it would be possible to create the reject filename in the correct directory, if it exists, or maybe create several OopsN,rej files (this second might be more consistent)..  In any case, if the file (e.g. Oops7 or Oops7.rej) exists, then that name should not be used (e.g. use Oops8.rej).  The screen output should display the name of the created file.

The sources for the patch program are in .../src/usr.bin/patch, or:

The submission should be in the form of a patch file that can be applied to the patch sources.

Uploaded Work
File name/URL File size Date submitted
PatchBugFix 3.1 KB January 05 2013 18:38 UTC
OptionalNameFix 264 bytes January 05 2013 18:38 UTC
PatchBugFix 3.3 KB January 07 2013 15:14 UTC
PatchBugFix 3.3 KB January 07 2013 16:21 UTC
PatchBugFix 4.1 KB January 07 2013 16:47 UTC
PatchBugFix 4.7 KB January 07 2013 17:00 UTC
PatchBugFix 4.9 KB January 07 2013 17:44 UTC
Puck Meerburg on January 4 2013 20:52 UTC Task Claimed

I would like to work on this task.

Julian Fagir on January 5 2013 18:10 UTC Task Assigned

This task has been assigned to Puck Meerburg. You have 144 hours to complete this task, good luck!

Puck Meerburg on January 5 2013 18:39 UTC Ready for review

The work on this task is ready to be reviewed.

Puck Meerburg on January 5 2013 18:43 UTC Fix


I included two patches, the main PatchBugFix (fixes patch.c, pch.c and pch.h) and the OptionalNameFix.

The PatchBugFix adds in case of a 'named patch' the header (name, date of change) of both files and puts them in top of the .rej, which is named 'Filename''num''.rej', e.g. noname0.rej and noname100.rej. It first checks for Name.rej, then Name0.rej, Name1.rej etc.

The OptionalNameFix fixes a annoyance of the default name being 'Oops', being not particularily good at telling the mistake, so the fix makes that 'noname'.






Julian Coleman on January 7 2013 10:11 UTC Almost there


This is very nice.  A few comments though:

  I think that leaving the name as "Oops" is fine, but that's more a personal preference (and it's good that this patch is optional ;-)

  If the filename "Oops" (or "Oops0", etc.) exists, then patch still creates a reject file called "Oops.rej" (or "Oops0.rej", etc).  Could you make the code check for either file name before creating the reject file?



Julian Coleman on January 7 2013 10:11 UTC Task Needs More Work

One of the mentors has sent this task back for more work. Talk to the mentor(s) assigned to this task to satisfy the requirements needed to complete this task, submit your work again and mark the task as complete once you re-submit your work.

Puck Meerburg on January 7 2013 15:15 UTC Ready for review

The work on this task is ready to be reviewed.

Julian Coleman on January 7 2013 17:59 UTC This looks good


Summary of the conversation on IRC, this latest version:

  adds a increment to the filename Oops.rej (Oops0.rej ... OopsN.rej) if either OopsN or OopsN.rej exists

  only does the incrementing and existing name checking if the original file did not exist

  preserves the existing behaviour for files that exist, and also where file.rej exists, and also if there is an existing file named "Oops".




Julian Coleman on January 7 2013 17:59 UTC Task Closed

Congratulations, this task has been completed successfully.