stash/pkg/manager/task_migrate_hash.go
SmallCoccinelle 4a0c4c4847
Reorder waitgroup completion (#1748)
Rather than passing a pointer to a waitgroup into task.Start(..)
functions, handle the waitgroup.Done() at the callsite.

This makes waitgroup handling local to its definition rather than it
being spread out over multiple files. Tasks now simply execute, and
the policy of waiting on them is handled by the caller.
2021-09-22 13:22:59 +10:00

32 lines
695 B
Go

package manager
import (
"github.com/stashapp/stash/pkg/models"
)
// 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.
func (t *MigrateHashTask) Start() {
if !t.Scene.OSHash.Valid || !t.Scene.Checksum.Valid {
// nothing to do
return
}
oshash := t.Scene.OSHash.String
checksum := t.Scene.Checksum.String
oldHash := oshash
newHash := checksum
if t.fileNamingAlgorithm == models.HashAlgorithmOshash {
oldHash = checksum
newHash = oshash
}
MigrateHash(oldHash, newHash)
}