aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/gallery/builder.go2
-rw-r--r--internal/gallery/id.go14
2 files changed, 13 insertions, 3 deletions
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[:])
}