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)), }