Merge pull request 'Fix file names' (#17) from dedupe-files into main

Reviewed-on: https://git.ts.mattnite.net/mattnite/cairn/pulls/17
This commit is contained in:
Matthew Knight 2026-03-06 18:41:46 +00:00
commit 57d6448179
1 changed files with 5 additions and 2 deletions

View File

@ -246,7 +246,10 @@ func (h *CorpusHandler) Upload(c *gin.Context) {
runID = &uid 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 { if err := h.Store.Put(ctx, blobKey, file, header.Size); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "storing blob: " + err.Error()}) 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{ hdr := &tar.Header{
Name: filepath.Base(entry.BlobKey), Name: fmt.Sprintf("%d-%s", entry.ID, filepath.Base(entry.BlobKey)),
Mode: 0o644, Mode: 0o644,
Size: int64(len(data)), Size: int64(len(data)),
} }