mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Handle file rescan (#2951)
* Fire handlers when file updated or moved * Create galleries as needed * Clean empty galleries * Handle cleaning zip folders when path changed * Fix gallery association on duplicate images * Re-create missing folder-based galleries
This commit is contained in:
@@ -13,6 +13,7 @@ const (
|
||||
type hookManager struct {
|
||||
postCommitHooks []TxnFunc
|
||||
postRollbackHooks []TxnFunc
|
||||
postCompleteHooks []TxnFunc
|
||||
}
|
||||
|
||||
func (m *hookManager) register(ctx context.Context) context.Context {
|
||||
@@ -27,20 +28,26 @@ func hookManagerCtx(ctx context.Context) *hookManager {
|
||||
return m
|
||||
}
|
||||
|
||||
func executePostCommitHooks(ctx context.Context) {
|
||||
m := hookManagerCtx(ctx)
|
||||
for _, h := range m.postCommitHooks {
|
||||
func executeHooks(ctx context.Context, hooks []TxnFunc) {
|
||||
for _, h := range hooks {
|
||||
// ignore errors
|
||||
_ = h(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func executePostCommitHooks(ctx context.Context) {
|
||||
m := hookManagerCtx(ctx)
|
||||
executeHooks(ctx, m.postCommitHooks)
|
||||
}
|
||||
|
||||
func executePostRollbackHooks(ctx context.Context) {
|
||||
m := hookManagerCtx(ctx)
|
||||
for _, h := range m.postRollbackHooks {
|
||||
// ignore errors
|
||||
_ = h(ctx)
|
||||
}
|
||||
executeHooks(ctx, m.postRollbackHooks)
|
||||
}
|
||||
|
||||
func executePostCompleteHooks(ctx context.Context) {
|
||||
m := hookManagerCtx(ctx)
|
||||
executeHooks(ctx, m.postCompleteHooks)
|
||||
}
|
||||
|
||||
func AddPostCommitHook(ctx context.Context, hook TxnFunc) {
|
||||
@@ -52,3 +59,8 @@ func AddPostRollbackHook(ctx context.Context, hook TxnFunc) {
|
||||
m := hookManagerCtx(ctx)
|
||||
m.postRollbackHooks = append(m.postRollbackHooks, hook)
|
||||
}
|
||||
|
||||
func AddPostCompleteHook(ctx context.Context, hook TxnFunc) {
|
||||
m := hookManagerCtx(ctx)
|
||||
m.postCompleteHooks = append(m.postCompleteHooks, hook)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user