2020-08-06 01:21:14 +00:00
|
|
|
package manager
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
2021-10-14 23:39:48 +00:00
|
|
|
"github.com/stashapp/stash/pkg/scene"
|
2020-08-06 01:21:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MigrateHashTask renames generated files between oshash and MD5 based on the
|
|
|
|
// value of the fileNamingAlgorithm flag.
|
|
|
|
type MigrateHashTask struct {
|
|
|
|
Scene *models.Scene
|
|
|
|
fileNamingAlgorithm models.HashAlgorithm
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start starts the task.
|
2021-09-22 03:22:59 +00:00
|
|
|
func (t *MigrateHashTask) Start() {
|
2022-09-01 07:54:34 +00:00
|
|
|
if t.Scene.OSHash == "" || t.Scene.Checksum == "" {
|
2020-08-06 01:21:14 +00:00
|
|
|
// nothing to do
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-01 07:54:34 +00:00
|
|
|
oshash := t.Scene.OSHash
|
|
|
|
checksum := t.Scene.Checksum
|
2020-08-06 01:21:14 +00:00
|
|
|
|
|
|
|
oldHash := oshash
|
|
|
|
newHash := checksum
|
|
|
|
if t.fileNamingAlgorithm == models.HashAlgorithmOshash {
|
|
|
|
oldHash = checksum
|
|
|
|
newHash = oshash
|
|
|
|
}
|
|
|
|
|
2021-10-14 23:39:48 +00:00
|
|
|
scene.MigrateHash(instance.Paths, oldHash, newHash)
|
2020-08-06 01:21:14 +00:00
|
|
|
}
|