+sub symlink_packs ($$) {
+ my ($ibx, $pd) = @_;
+ my $ret = 0;
+ my $glob = "$ibx->{inboxdir}/git/*.git/objects/pack/*.idx";
+ for my $idx (bsd_glob($glob, GLOB_NOSORT)) {
+ my $src = substr($idx, 0, -length('.idx'));
+ my $dst = $pd . substr($src, rindex($src, '/'));
+ if (-f "$src.pack" and
+ symlink("$src.pack", "$dst.pack") and
+ symlink($idx, "$dst.idx") and
+ -f $idx) {
+ ++$ret;
+ # .promisor and .keep are optional
+ # XXX should we symlink .keep here?
+ for my $s (qw(promisor)) {
+ symlink("$src.$s", "$dst.$s") if -f "$src.$s";
+ }
+ } elsif (!$!{EEXIST}) {
+ warn "W: ln -s $src.{pack,idx} => $dst.*: $!\n";
+ unlink "$dst.pack", "$dst.idx";
+ }
+ }
+ $ret;
+}
+