#
# 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://<realhost>:<realport>/<real-git-url>[ <options>]"
# where <real-git-url> is http://<host>/... or git://<host>/...
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.
next;
}
logm 'info', "housekeeping: subdirs $subdir: cleaning";
- my $ok = 1;
- foreach my $suffix (qw(tmp git)) {
- my $dir = "${subdir}\\.$suffix";
- my $errs;
- remove_tree($dir, { safe=>1, error=>\$errs });
- if (stat $dir) {
- $ok = 0;
- logm 'warning', "housekeeping: $dir: problems with".
- "deletion prevent cleanup:";
- foreach my $err (@$errs) {
- logm 'info', "problem deleting: $err->[0]: $err->[1]";
+ eval {
+ foreach my $suffix (qw(tmp git)) {
+ my $dir = "${subdir}\\.$suffix";
+ my $errs;
+ remove_tree($dir, { safe=>1, error=>\$errs });
+ if (stat $dir) {
+ foreach my $err (@$errs) {
+ my ($file, $message) = %$err;
+ logm 'info', "problem deleting: $file: $message";
+ }
+ die "$dir: problem deleting file(s)\n";
}
}
- }
- if ($ok) {
+ };
+ if (length $@) {
+ chomp $@;
+ logm 'warning', "housekeeping: $subdir: cleanup prevented: $@";
+ } else {
unlink $lock or hkfail "remove $lock: $!";
}
}
sub runcommand () {
servinfo "serving";
+
+ chdir $gitd or fail "chdir $gitd: $!";
+
exec qw(git-upload-pack --strict --timeout=1000 .)
or fail "exec git-upload-pack: $!";
}