X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=chiark-utils.git;a=blobdiff_plain;f=scripts%2Fgit-cache-proxy;h=eafbb8af8e513a104e5a8d6d406be540cb0b38a6;hp=540188bc73797dc0e4308e8efa61e84e277ab155;hb=af4bb0898fec62b74871cbd30762209bb388ccca;hpb=2d867f1a7f27bd3ea2b59f2600f0477d51979aca diff --git a/scripts/git-cache-proxy b/scripts/git-cache-proxy index 540188b..eafbb8a 100755 --- a/scripts/git-cache-proxy +++ b/scripts/git-cache-proxy @@ -2,6 +2,12 @@ # # git caching proxy +# Suitable only for exposing to semi-trusted clients: clients are not +# supposed to be able to take over the server. However, clients can +# probably deny service to each other because the current +# implementation is not very good at handling various out-of-course +# situations (notably, clients which are too slow). + # usage: run it on some port, and then clone or fetch # "git://:/[ ]" # where is http:///... or git:///... @@ -14,11 +20,22 @@ # fetch=try use what is in the cache if the fetch/clone fails # timeout= length of time to allow for fetch/clone +# example inetd.conf line: +# 9419 stream tcp nowait git-cache /usr/bin/git-cache-proxy git-cache-proxy +# you'll need to +# adduser git-cache +# mkdir /var/cache/git-cache-proxy +# chown git-cache /var/cache/git-cache-proxy + +# git-cache-proxy +# Copyright 2010 Tony Finch +# Copyright 2013 Ian Jackson +# # git-cache-proxy is free software; you can redistribute it and/or # modify them under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 3, or (at # your option) any later version. -# +# # git-cache-proxy is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU @@ -359,10 +376,10 @@ sub clonefetch () { servinfo "sharing"; lockfile \*LOCK, $lock, LOCK_SH; # NB releases and relocks - if (chdir $gitd) { + if (stat $gitd) { return 1; } - $!==ENOENT or fail "chdir $gitd: $!"; + $!==ENOENT or fail "stat $gitd: $!"; # Well, err, someone must have taken the lock in between # and garbage collected it. How annoying. @@ -396,7 +413,7 @@ sub housekeeping () { if (stat $dir) { $ok = 0; logm 'warning', "housekeeping: $dir: problems with". - "deletion prevent cleanup:"; + " deletion prevent cleanup:"; foreach my $err (@$errs) { logm 'info', "problem deleting: $err->[0]: $err->[1]"; } @@ -446,6 +463,9 @@ sub housekeepingcheck ($$) { sub runcommand () { servinfo "serving"; + + chdir $gitd or fail "chdir $gitd: $!"; + exec qw(git-upload-pack --strict --timeout=1000 .) or fail "exec git-upload-pack: $!"; }