Backend: Sidecar file hashes may have duplicates
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
3e6c85feb2
commit
4ef19bb671
|
@ -19,7 +19,7 @@ type File struct {
|
|||
FileUUID string `gorm:"type:varbinary(36);unique_index;"`
|
||||
FileName string `gorm:"type:varbinary(600);unique_index"`
|
||||
OriginalName string `gorm:"type:varbinary(600);"`
|
||||
FileHash string `gorm:"type:varbinary(128);unique_index"`
|
||||
FileHash string `gorm:"type:varbinary(128);index"`
|
||||
FileModified time.Time
|
||||
FileSize int64
|
||||
FileType string `gorm:"type:varbinary(32)"`
|
||||
|
@ -47,7 +47,7 @@ type File struct {
|
|||
DeletedAt *time.Time `sql:"index"`
|
||||
}
|
||||
|
||||
func FindFileByHash(db *gorm.DB, fileHash string) (File, error) {
|
||||
func FirstFileByHash(db *gorm.DB, fileHash string) (File, error) {
|
||||
var file File
|
||||
|
||||
q := db.Unscoped().First(&file, "file_hash = ?", fileHash)
|
||||
|
|
|
@ -192,7 +192,7 @@ func (imp *Import) DestinationFilename(mainFile *MediaFile, mediaFile *MediaFile
|
|||
dateCreated := mainFile.DateCreated()
|
||||
|
||||
if !mediaFile.IsSidecar() {
|
||||
if f, err := entity.FindFileByHash(imp.conf.Db(), mediaFile.Hash()); err == nil {
|
||||
if f, err := entity.FirstFileByHash(imp.conf.Db(), mediaFile.Hash()); err == nil {
|
||||
existingFilename := imp.conf.OriginalsPath() + string(os.PathSeparator) + f.FileName
|
||||
return existingFilename, fmt.Errorf("\"%s\" is identical to \"%s\" (%s)", mediaFile.FileName(), f.FileName, mediaFile.Hash())
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ func (s *Repo) FindFileByID(id string) (file entity.File, err error) {
|
|||
return file, nil
|
||||
}
|
||||
|
||||
// FindFileByHash finds a file with a given hash string.
|
||||
// FirstFileByHash finds a file with a given hash string.
|
||||
func (s *Repo) FindFileByHash(fileHash string) (file entity.File, err error) {
|
||||
if err := s.db.Where("file_hash = ?", fileHash).Preload("Photo").First(&file).Error; err != nil {
|
||||
return file, err
|
||||
|
|
Loading…
Reference in a new issue