Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merge not deleting deleted scene generated files #4567

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/api/resolver_mutation_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,16 @@ func (r *mutationResolver) SceneMerge(ctx context.Context, input SceneMergeInput
values = &v
}

mgr := manager.GetInstance()
fileDeleter := &scene.FileDeleter{
Deleter: file.NewDeleter(),
FileNamingAlgo: mgr.Config.GetVideoFileNamingAlgorithm(),
Paths: mgr.Paths,
}

var ret *models.Scene
if err := r.withTxn(ctx, func(ctx context.Context) error {
if err := r.Resolver.sceneService.Merge(ctx, srcIDs, destID, *values); err != nil {
if err := r.Resolver.sceneService.Merge(ctx, srcIDs, destID, *values, fileDeleter); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/manager/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type SceneService interface {
Create(ctx context.Context, input *models.Scene, fileIDs []models.FileID, coverImage []byte) (*models.Scene, error)
AssignFile(ctx context.Context, sceneID int, fileID models.FileID) error
Merge(ctx context.Context, sourceIDs []int, destinationID int, values models.ScenePartial) error
Merge(ctx context.Context, sourceIDs []int, destinationID int, values models.ScenePartial, fileDeleter *scene.FileDeleter) error
Destroy(ctx context.Context, scene *models.Scene, fileDeleter *scene.FileDeleter, deleteGenerated, deleteFile bool) error
}

Expand Down
18 changes: 12 additions & 6 deletions pkg/scene/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import (
"github.com/stashapp/stash/pkg/txn"
)

func (s *Service) Merge(ctx context.Context, sourceIDs []int, destinationID int, scenePartial models.ScenePartial) error {
func (s *Service) Merge(
ctx context.Context,
sourceIDs []int,
destinationID int,
scenePartial models.ScenePartial,
fileDeleter *FileDeleter,
) error {
// ensure source ids are unique
sourceIDs = sliceutil.AppendUniques(nil, sourceIDs)

Expand All @@ -36,8 +42,6 @@ func (s *Service) Merge(ctx context.Context, sourceIDs []int, destinationID int,
var fileIDs []models.FileID

for _, src := range sources {
// TODO - delete generated files as needed

if err := src.LoadRelationships(ctx, s.Repository); err != nil {
return fmt.Errorf("loading scene relationships from %d: %w", src.ID, err)
}
Expand Down Expand Up @@ -71,9 +75,11 @@ func (s *Service) Merge(ctx context.Context, sourceIDs []int, destinationID int,
}

// delete old scenes
for _, srcID := range sourceIDs {
if err := s.Repository.Destroy(ctx, srcID); err != nil {
return fmt.Errorf("deleting scene %d: %w", srcID, err)
for _, src := range sources {
const deleteGenerated = true
const deleteFile = false
if err := s.Destroy(ctx, src, fileDeleter, deleteGenerated, deleteFile); err != nil {
return fmt.Errorf("deleting scene %d: %w", src.ID, err)
}
}

Expand Down
Loading