mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
Improve oshash collision detection and logging (#713)
* Log colliding file when setting hash * Check for existing using both hashes
This commit is contained in:
parent
5992ff8706
commit
0874852fa8
1 changed files with 27 additions and 7 deletions
|
|
@ -178,12 +178,20 @@ func (t *ScanTask) scanScene() {
|
|||
return
|
||||
}
|
||||
|
||||
// check if oshash clashes with existing scene
|
||||
dupe, _ := qb.FindByOSHash(oshash)
|
||||
if dupe != nil {
|
||||
logger.Errorf("OSHash for file %s is the same as that of %s", t.FilePath, dupe.Path)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
tx := database.DB.MustBeginTx(ctx, nil)
|
||||
err = qb.UpdateOSHash(scene.ID, oshash, tx)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
_ = tx.Rollback()
|
||||
tx.Rollback()
|
||||
return
|
||||
} else if err := tx.Commit(); err != nil {
|
||||
logger.Error(err.Error())
|
||||
}
|
||||
|
|
@ -197,6 +205,13 @@ func (t *ScanTask) scanScene() {
|
|||
return
|
||||
}
|
||||
|
||||
// check if checksum clashes with existing scene
|
||||
dupe, _ := qb.FindByChecksum(checksum)
|
||||
if dupe != nil {
|
||||
logger.Errorf("MD5 for file %s is the same as that of %s", t.FilePath, dupe.Path)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
tx := database.DB.MustBeginTx(ctx, nil)
|
||||
err = qb.UpdateChecksum(scene.ID, checksum, tx)
|
||||
|
|
@ -240,15 +255,20 @@ func (t *ScanTask) scanScene() {
|
|||
}
|
||||
}
|
||||
|
||||
// check for scene by checksum and oshash - MD5 should be
|
||||
// redundant, but check both
|
||||
if checksum != "" {
|
||||
scene, _ = qb.FindByChecksum(checksum)
|
||||
}
|
||||
|
||||
if scene == nil {
|
||||
scene, _ = qb.FindByOSHash(oshash)
|
||||
}
|
||||
|
||||
sceneHash := oshash
|
||||
|
||||
if t.fileNamingAlgorithm == models.HashAlgorithmMd5 {
|
||||
sceneHash = checksum
|
||||
scene, _ = qb.FindByChecksum(sceneHash)
|
||||
} else if t.fileNamingAlgorithm == models.HashAlgorithmOshash {
|
||||
scene, _ = qb.FindByOSHash(sceneHash)
|
||||
} else {
|
||||
logger.Error("unknown file naming algorithm")
|
||||
return
|
||||
}
|
||||
|
||||
t.makeScreenshots(videoFile, sceneHash)
|
||||
|
|
|
|||
Loading…
Reference in a new issue