How to patch a file that resides in /Applications (patch can't find file to patch at input line)?
I am trying to patch 5 files within an Mac application bundle using the Terminal patch
command. The files to be patch are specified using an absolute file path (the file name and path start with a slash).
The output when running $ sudo patch -i ~/custom.patch
is:
can't find file to patch at input line 3
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|--- /Applications/Xyz.app/Contents/Resources/dashboard.js
|+++ /Applications/Xyz.app/Contents/Resources/dashboard.js
--------------------------
File to patch: ^C
I have verified that the file /Applications/Xyz.app/Contents/Resources/dashboard.js does exist using at the specified file path using the ls
command.
Regression:
- Tried to run the patch command from root folder using
$ cd /
- Tried to run the patch command from root folder with the first slash removed, that results in an almost identical result:
can't find file to patch at input line 3
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|--- Applications/Xyz.app/Contents/Resources/dashboard.js
|+++ Applications/Xyz.app/Contents/Resources/dashboard.js
--------------------------
File to patch: ^C
How can multiple files within a Mac OS X Application bundle be patched using patch
?
Solution 1:
I think the problem is that you are not specifying the p option.
From the manual for patch:
For example, supposing the file name in the patch file was
/u/howard/src/blurfl/blurfl.c
setting -p0 gives the entire file name unmodified, -p1 gives
u/howard/src/blurfl/blurfl.c
without the leading slash, -p4 gives
blurfl/blurfl.c
and not specifying -p at all just gives you
blurfl.c.
Whatever you end up with is looked for either in the current directory,
or the directory specified by the -d option.
So the command should be something like:
patch -p0 <custom.patch
or you could specify the directory to which the patch should be applied:
patch -d /path/to/dir <custom.patch