Fix file names

This commit is contained in:
Matthew Knight 2026-03-06 10:35:34 -08:00
parent 54ec7cac27
commit 2370d666c0
No known key found for this signature in database
1 changed files with 5 additions and 2 deletions

View File

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