Multiplay Labs

tech hits and tips from Multiplay

patch and missing directories gotcha

without comments

Just been bitten by possibly a well know gotcha with how patch worked but just in case I thought I’d share.

If you have a diff file such as the one below and use patch < mypatch to apply it, unless all of the elements in the directory name exist the new file will be created in the current working directory instead of the specified directory.

--- /dev/null   2012-09-20 15:44:00.000000000 +0000
+++ some/patch/myfile        2012-09-20 15:48:16.619282929 +0000
@@ -0,0 +1,1 @@
My patch

The fix is simple, always use -p option to specify the pathname strip count e.g. patch -p0 < mypatch

Note this also applies to multi part diff files, which can be really confusing.

Written by Dilbert

September 20th, 2012 at 5:40 pm

Posted in Hackery

Leave a Reply

You must be logged in to post a comment.