realm
realm copied to clipboard
[bug] UploadTomes() function does not properly deduplicate tome names
Describe the bug The UploadTomes function uses the path name to check for duplicates instead of the Metadata.Name()
func UploadTomes(ctx context.Context, graph *ent.Client, fileSystem fs.ReadDirFS) error {
entries, err := fileSystem.ReadDir(".")
...
for _, entry := range entries {
exists, err := graph.Tome.Query().
Where(tome.Name(entry.Name())). // <-- Using path name not metadata.Name()
Exist(ctx)
if exists { // <-- Will always be false
continue
}
...
// Parse metadata
...
// Create the tome
if _, err := graph.Tome.Create().
SetName(metadata.Name) // <-- Causes "ent: constraint failed: UNIQUE constraint failed: tomes.name"
...
}
}
return nil
}
To Reproduce Call UploadTomes() twice with the same tomes.
Expected behavior Tome should continue the loop and not error.
I think this is intended refreshing a repo should use the sync button - maybe i'm misunderstanding.
There is a "continue if same tome" logic it's just implemented wrong. It doesn't affect tavern bc there is no "refresh buildin times"
I'll research it more