# Correct way to install a patch



## drhowarddrfine (Mar 23, 2014)

I've never had to do this before and I'm worried the Linux instruction isn't going to work right. This is for www/thttpd and the instructions are this:


> Save this file as [{{#file: thttpd.patch}} thttpd.patch]
> 
> --- thttpd-2.25b/libhttpd.c	2003-12-25 20:06:05.000000000 +0100
> +++ thttpd-2.25b-patched/libhttpd.c	2005-01-09 00:26:04.867255248 +0100
> ...


I think I'm supposed to install this like so: `patch < thttpd.patch` but then it asks which file to patch. There is only a patch-libhttpd.c in the file directory of that port and trying to use that as the file to patch only met with errors so I'm lost.


----------



## trh411 (Mar 23, 2014)

Just save the file to the /usr/ports/www/thttpd/files directory and run portmaster to install/re-install the port. The patch files will be automatically applied.


----------



## wblock@ (Mar 23, 2014)

Files in the files directory are not the whole source, usually just patches.  It may be that this patch is already in the port.

Anyway, extract the source and apply the port patches with `make patch`.  Then `cd` into the work directory, and locate the thttpd-2.25b and apply the patch.  If the patch is not in that directory, give it a full path.


----------



## wblock@ (Mar 23, 2014)

trh411 said:
			
		

> Just save the file to the /usr/ports/www/thttpd/files directory and run portmaster to install/re-install the port. The patch files will be automatically applied.



Yes, but the path in the patch has to be relative to the work/${PORTNAME} directory.  `make -V WRKSRC` will show it.


----------



## drhowarddrfine (Mar 23, 2014)

wblock@ said:
			
		

> It may be that this patch is already in the port.


It's not.


> Anyway, extract the source and apply the port patches with `make patch`.


Extract the source to where? I did that in a test directory and did `make patch` but the error is "Don't know how to make patch". So I assumed it was to be `make thttpd.patch` which got back "Patch is up to date". However, it's not in the source when I search for it. Unless I was to then do the next step:


> Then `cd` into the work directory, and locate the thttpd-2.25b and apply the patch.  If the patch is not in that directory, give it a full path.


But there is no work directory and I don't know how to "apply the patch". So I'm confused.


----------



## wblock@ (Mar 23, 2014)

`make patch` is part of the ports system.  So

```
# cd /usr/ports/www/thttpd
# make patch
# cd work
# ls
.extract_done.thttpd._usr_local	thttpd-2.25b
.patch_done.thttpd._usr_local
# patch < /pathtomypatch/thttpd.patch
```


----------



## drhowarddrfine (Mar 23, 2014)

Ok. Thanks!I must have done the `make patch` in the wrong place before but I don't understand about extracting the source in the instructions and where that fit in cause it couldn't have found it where I extracted it but I can leave that for now.

However, the patch didn't fix what I was expecting it to fix. How can I tell if the patch is actually applied? I know it's a naive question but is the build src still around that I can look at it? I don't see it in /usr/ports/distfiles or www/thttpd

EDIT: Well, I see there's a new thttpd-2.25b.tar.gz file in distfiles. I extract that but I don't see the patch applied to libhttpd.c.

EDIT2: However, running make patch and patch as above goes through all the motions of patching so, perhaps, it's not the solution to my problem though it's supposed to be.


----------



## wblock@ (Mar 23, 2014)

A build in ports first creates the work directory in /ports/www/thttpd, then extracts the distfile into it.  When you apply the patch, it changes the source in that directory.

After patching, continue to build and install the port as normal.  If `make clean` is done, the patched source and other temporary files are removed.  The original distfile will not be changed.


----------



## drhowarddrfine (Mar 23, 2014)

Ok thanks. It's not doing what I expected so I'll have to dig into this to see if I'm doing something else wrong. 

www/thttpd does not support `X-Real-IP` so I can't get the remote address from www/nginx by proxy. This patch is supposed to fix that if anyone is wondering.


----------

