From 5fa3daffb2f29b10828c4103b9b2b78220568736 Mon Sep 17 00:00:00 2001 From: RanXom Date: Mon, 13 Jul 2026 12:29:45 +0530 Subject: refactor(gallery): generate IDs from canonical paths --- internal/gallery/builder.go | 2 +- internal/gallery/id.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'internal') diff --git a/internal/gallery/builder.go b/internal/gallery/builder.go index 1964b19..60ba006 100644 --- a/internal/gallery/builder.go +++ b/internal/gallery/builder.go @@ -37,7 +37,7 @@ func (b *Builder) Build( } photos = append(photos, Photo{ - ID: generateID(file.RelativePath), + ID: generateID(file), File: file, Metadata: md, }) diff --git a/internal/gallery/id.go b/internal/gallery/id.go index b23ebf5..edb5be2 100644 --- a/internal/gallery/id.go +++ b/internal/gallery/id.go @@ -3,9 +3,19 @@ package gallery import ( "crypto/sha256" "encoding/hex" + "path/filepath" + + "github.com/RanXom/galleryd/internal/scanner" ) -func generateID(relativePath string) string { - sum := sha256.Sum256([]byte(relativePath)) +// generateID returns a deterministic identifier for a photo. +// +// IDs are generated from the cleaned root and relative path to avoid +// collisions when multiple roots contain the same directory layout. +func generateID(file scanner.File) string { + canonical := filepath.Join(file.Root, file.RelativePath) + + sum := sha256.Sum256([]byte(canonical)) + return hex.EncodeToString(sum[:]) } -- cgit v1.2.3