From caa21cb448c15548fa471711e517da2f689ddfad Mon Sep 17 00:00:00 2001 From: Abhishek Shroff Date: Sun, 17 Mar 2024 00:01:28 +0530 Subject: [PATCH] Update mod time when member resources are deleted --- internal/library/library.go | 40 ++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/internal/library/library.go b/internal/library/library.go index 4412feac..ac0110fe 100644 --- a/internal/library/library.go +++ b/internal/library/library.go @@ -37,31 +37,39 @@ func (l Library) ReadDir(ctx context.Context, id uuid.UUID, includeRoot bool, re } func (l Library) DeleteRecursive(ctx context.Context, id uuid.UUID, hardDelete bool) error { - query := l.db.Queries().DeleteRecursive - if hardDelete { - query = l.db.Queries().HardDeleteRecursive - } - deleted, err := query(ctx, id) - if err == nil && hardDelete { - for _, res := range deleted { - if !res.Dir { - l.cs.Delete(res.ID) + return l.db.RunInTx(ctx, func(q *sql.Queries) error { + p, err := q.ResourceById(ctx, id) + if err != nil { + return err + } + + query := q.DeleteRecursive + if hardDelete { + query = q.HardDeleteRecursive + } + deleted, err := query(ctx, id) + if err == nil && hardDelete { + for _, res := range deleted { + if !res.Dir { + l.cs.Delete(res.ID) + } } } - } - return err + + if p.Parent != nil { + return q.UpdateResourceModified(ctx, *p.Parent) + } + return nil + }) + } func (l Library) CreateResource(ctx context.Context, id uuid.UUID, parent uuid.UUID, name string, dir bool) error { return l.db.RunInTx(ctx, func(q *sql.Queries) error { - if err := q.CreateResource(ctx, sql.CreateResourceParams{ID: id, Parent: &parent, Name: name, Dir: dir}); err != nil { return err } - if err := q.UpdateResourceModified(ctx, parent); err != nil { - return err - } - return nil + return q.UpdateResourceModified(ctx, parent) }) }