aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_triggers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/api_triggers.go')
-rw-r--r--internal/admin/api_triggers.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/internal/admin/api_triggers.go b/internal/admin/api_triggers.go
index 5b82465..08e2855 100644
--- a/internal/admin/api_triggers.go
+++ b/internal/admin/api_triggers.go
@@ -147,12 +147,21 @@ func (s *AdminServer) handleTriggerByID(w http.ResponseWriter, r *http.Request)
os.Remove(oldPath)
}
- s.undoStack.Push(ChangeDesc{
+ desc := ChangeDesc{
Description: "Update trigger " + id,
FilePath: newPath,
OldContent: oldContent,
NewContent: triggerData,
- })
+ }
+ if findErr == nil && newSubdir != oldDir {
+ // A kind change moves the file between subdirectories. Record the
+ // old path as the before-image location so undo restores the old
+ // content there (and removes the new file) instead of writing the
+ // old content into the new directory and orphaning the old path.
+ desc.FilePath = oldPath
+ desc.NewFilePath = newPath
+ }
+ s.undoStack.Push(desc)
s.rebuildTriggerIndex()
writeJSON(w, map[string]any{"ok": true, "id": id, "kind": newKind})