sonda/internal/duplicates/types.go
tgiachi 65edfc4918 feat(storage): candidates for duplicates, file fingerprints and removing a copy from the index
Candidates are the playable files whose title another file shares. A fingerprint is kept only for the file that was read (same size and date), and a scan that finds the file changed forgets it. Removing a copy moves its listens to the track that stays, because they would be deleted with the track, then removes the track with its file, credits and genres. Tested on SQLite and PostgreSQL.
2026-11-12 16:37:15 +01:00

32 lines
1.4 KiB
Go

package duplicates
import "errors"
// Why a removal is refused. The API turns each into its own answer.
var (
// ErrTrackNotFound: a track that was named does not exist (any more).
ErrTrackNotFound = errors.New("no such track")
// ErrDisabled: the operator has not allowed Sonda to delete files (library.allow_delete).
ErrDisabled = errors.New("deleting files is not allowed: turn on library.allow_delete")
// ErrScanRunning: a scan is running, and what it reads and what is removed must not meet.
ErrScanRunning = errors.New("a scan is running")
// ErrInvalid: the tracks named are not copies of one song, or the request makes no sense.
ErrInvalid = errors.New("these tracks are not copies of the same song")
// ErrChanged: a file is not what the index says (another size or date, a link, gone), or the
// copy to keep is not there any more. Nothing is removed; a new scan brings the index up to date.
ErrChanged = errors.New("a file changed since it was scanned")
// ErrReadOnly: the folder cannot be written to.
ErrReadOnly = errors.New("the music folder is read-only")
)
// FileRecord is a file as the index knows it: where it is and what it looked like when it was scanned.
type FileRecord struct {
FileID int64
TrackID int64
Root string // the path of its library
RelPath string // relative to the library
SizeBytes int64
MTimeUnix int64
Hash string // SHA-256, empty until read
Missing bool // flagged as not found by a scan
}