cmd/zoekt-indexserver: delete tmp files after indexing

These otherwise accumulate, causing indexing failures.

Change-Id: I0693a8359fdb31eb042d37bb71f4519609c8047b
diff --git a/cmd/zoekt-indexserver/main.go b/cmd/zoekt-indexserver/main.go
index 7583132..ae9659f 100644
--- a/cmd/zoekt-indexserver/main.go
+++ b/cmd/zoekt-indexserver/main.go
@@ -151,6 +151,16 @@
 func indexPendingRepos(indexDir, repoDir string, opts *Options, repos <-chan string) {
 	for dir := range repos {
 		indexPendingRepo(dir, indexDir, repoDir, opts)
+
+		// Failures (eg. timeout) will leave temp files
+		// around. We have to clean them, or they will fill up the indexing volume.
+		if failures, err := filepath.Glob(filepath.Join(indexDir, "*.tmp")); err != nil {
+			log.Printf("Glob: %v", err)
+		} else {
+			for _, f  := range failures {
+				os.Remove(f)
+			}
+		}
 	}
 }
 
@@ -168,7 +178,6 @@
 	args = append(args, dir)
 	cmd := exec.CommandContext(ctx, "zoekt-git-index", args...)
 	loggedRun(cmd)
-
 }
 
 // deleteLogs deletes old logs.