- At most two covers are built at the same time: a page of albums asked for at once could decode dozens of large pictures together. - A change to an album's files marks its record stale and moves a generation instead of deleting the row. A build that started before the change is not saved over it and starts again, so a "no cover" found too early cannot win for a day. - A cover that was found is checked again after a week, so a picture replaced in a folder is noticed. - For CD1/Disc 2 folders the picture in the folder above is used. Folder pictures are read one at a time, and the pixel count is computed in 64 bits. - Stored files are synced before they get their name, an empty one counts as missing, and old temporary files from a crash are removed. - Files without track or disc numbers sort the same on both databases. - storage.data_dir defaults next to the SQLite database, so a service started from another folder does not need a writable working directory. - Tests: a listener who leaves, a change during a build, the build limit, a named pipe, an embedded picture of a file outside the library that exists, builds that really overlap.
33 lines
743 B
Go
33 lines
743 B
Go
//go:build unix
|
|
|
|
package images
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"path/filepath"
|
|
"syscall"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Opening a named pipe waits for a writer: a pipe called cover.jpg must not hang the build.
|
|
func TestAPipeCalledCoverDoesNotHangTheBuild(t *testing.T) {
|
|
r := newRig(t)
|
|
if err := syscall.Mkfifo(filepath.Join(r.root, "Album One", "cover.jpg"), 0o644); err != nil {
|
|
t.Skip("cannot create a FIFO:", err)
|
|
}
|
|
done := make(chan error, 1)
|
|
go func() {
|
|
_, err := r.svc.AlbumCover(context.Background(), 1, Large)
|
|
done <- err
|
|
}()
|
|
select {
|
|
case err := <-done:
|
|
if !errors.Is(err, ErrNoCover) {
|
|
t.Errorf("err = %v, want no cover", err)
|
|
}
|
|
case <-time.After(5 * time.Second):
|
|
t.Fatal("the build hung on a named pipe")
|
|
}
|
|
}
|