From 2370d666c01486028ce2cd9df93b79c1bb00fb26 Mon Sep 17 00:00:00 2001 From: Matthew Knight Date: Fri, 6 Mar 2026 10:35:34 -0800 Subject: [PATCH] Fix file names --- internal/handler/targets.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/handler/targets.go b/internal/handler/targets.go index 77a7f5b..6fac1fb 100644 --- a/internal/handler/targets.go +++ b/internal/handler/targets.go @@ -246,7 +246,10 @@ func (h *CorpusHandler) Upload(c *gin.Context) { runID = &uid } - blobKey := fmt.Sprintf("corpus/%s/%s/%s", target.RepoName, target.Name, header.Filename) + // Use a unique prefix to avoid filename collisions across runs. + var entryCount int64 + h.DB.WithContext(ctx).Model(&models.CorpusEntry{}).Where("target_id = ?", targetID).Count(&entryCount) + blobKey := fmt.Sprintf("corpus/%s/%s/%d-%s", target.RepoName, target.Name, entryCount, header.Filename) if err := h.Store.Put(ctx, blobKey, file, header.Size); err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": "storing blob: " + err.Error()}) @@ -362,7 +365,7 @@ func (h *CorpusHandler) DownloadAll(c *gin.Context) { } hdr := &tar.Header{ - Name: filepath.Base(entry.BlobKey), + Name: fmt.Sprintf("%d-%s", entry.ID, filepath.Base(entry.BlobKey)), Mode: 0o644, Size: int64(len(data)), }