aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_modules.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/api_modules.go')
-rw-r--r--internal/admin/api_modules.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/internal/admin/api_modules.go b/internal/admin/api_modules.go
index 8356b2d..ea547c5 100644
--- a/internal/admin/api_modules.go
+++ b/internal/admin/api_modules.go
@@ -96,9 +96,10 @@ func (s *AdminServer) handleModuleByID(w http.ResponseWriter, r *http.Request) {
delete(body, "_raw")
path := filepath.Join(s.dataDir, "modules", id+".yaml")
- var oldContent []byte
- if existing, err := snapshotFile(path); err == nil {
- oldContent = existing
+ oldContent, existed, err := snapshotBefore(path)
+ if err != nil {
+ failJSON(w, "read existing file: "+err.Error())
+ return
}
newContent, err := writeMapAsYAML(path, body)
@@ -107,7 +108,7 @@ func (s *AdminServer) handleModuleByID(w http.ResponseWriter, r *http.Request) {
return
}
- isCreate := oldContent == nil
+ isCreate := !existed
desc := "Updated module " + id
if isCreate {
desc = "Created module " + id