0

I did a patch file with

diff -Naur src/bacula.h src/bacula.h.old

and give me a file like this

--- src/bacula.h        2015-08-13 15:52:24 +0200
+++ src/bacula.h        2015-10-05 19:21:09 +0200
@@ -72,7 +72,7 @@
 #endif
 #if HAVE_UNISTD_H
 #  ifdef HAVE_HPUX_OS
-#  undef _INCLUDE_POSIX1C_SOURCE
+/*#  undef _INCLUDE_POSIX1C_SOURCE*/
 #  endif
 #include <unistd.h>
 #endif
@@ -95,6 +95,7 @@
 #if defined(_MSC_VER)
 extern "C" {
 #include "getopt.h"
+#include "fcntl.h"
 }
 #endif

When i use to patch it ask me

can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- src/bacula.h       2015-08-13 15:52:24 +0200
|+++ src/bacula.h       2015-10-05 19:21:09 +0200

I want automatically patch src/bacula.h without ask how to do? I use

patch -p1 < file.patch

  • 2
    1. is there a reason the order of your original patch is file.h first, file.h.old second, are you sure you want differences going from file.h to file.h.old? and not the other way around? 2. secondly any reason for the inconsistency file.h whereas the output you have has no mention of file.h , it keeps talking about src/bacula.h – clarity123 Oct 6 '15 at 20:18
  • I have made some changes now is more clear – elbarna Oct 6 '15 at 20:37
3

Your command patch -p1 file.patch looks for the filenames in the patch file. The -p1 strips everything in the filenames up to the first /; in your case this is the leading src/. The command therefore expects to find bacula.h in your current directory.

Incidentally, there is something very strange about the filenames you have provided as your example. They don't match, and the filenames in the patch file that should not match, do so. I would strongly recommend that that next time you copy and paste rather than free-typing.

  • I have edited the patch,of course,because bacula.h.old is the original file,i know .origin was better as extension – elbarna Oct 6 '15 at 22:10
  • @elbarna, there is no "of course"; I wasn't watching over your shoulder when you edited the patch file. Generally there should be no need to edit a patch file, but if you did it would have possibly helped to have flagged that in your question. – roaima Oct 6 '15 at 22:13
0

Solution found,you must include the complete path see example

WRONG!

--- src/bacula.h   2015-08-13 15:52:24 +0200
+++ src/bacula.h   2015-10-05 19:21:09 +0200

CORRECT!

--- bacula-7.0.5/src/bacula.h   2015-08-13 15:52:24 +0200
+++ bacula-7.0.5/src/bacula.h   2015-10-05 19:21:09 +0200

With the first incomplete path the patch works,but ask everytime to specify the path of bacula.h,with the second correct,patch -p1 < patchfile works fine and didn't ask for path

  • You need to run patch from the same directory in which you ran diff. Don't use -p1 either and it will all just work. No editing of patch files required. – roaima Oct 7 '15 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.