From c7024da735022d5cc1adfeb7c5831313b17ce481 Mon Sep 17 00:00:00 2001 From: bouncepaw Date: Thu, 18 Feb 2021 11:21:38 +0500 Subject: [PATCH] Fix the locking bug with CRUD operations --- http_mutators.go | 2 +- hyphae/delete.go | 2 -- hyphae/rename.go | 2 -- hyphae/unattach.go | 2 -- name.go | 3 +-- 5 files changed, 2 insertions(+), 9 deletions(-) diff --git a/http_mutators.go b/http_mutators.go index e4d6bdb..139a0d5 100644 --- a/http_mutators.go +++ b/http_mutators.go @@ -92,7 +92,7 @@ func factoryHandlerConfirmer( return func(w http.ResponseWriter, rq *http.Request) { log.Println(rq.URL) var ( - hyphaName = HyphaNameFromRq(rq, "unattach-confirm") + hyphaName = HyphaNameFromRq(rq, actionPath) h = hyphae.ByName(hyphaName) u = user.FromRequest(rq) ) diff --git a/hyphae/delete.go b/hyphae/delete.go index b5c7939..3ca6aac 100644 --- a/hyphae/delete.go +++ b/hyphae/delete.go @@ -31,8 +31,6 @@ func (h *Hypha) CanDelete(u *user.User) (err error, errtitle string) { // DeleteHypha deletes hypha and makes a history record about that. func (h *Hypha) DeleteHypha(u *user.User) (hop *history.HistoryOp, errtitle string) { - h.Lock() - defer h.Unlock() hop = history.Operation(history.TypeDeleteHypha) if err, errtitle := h.CanDelete(u); errtitle != "" { diff --git a/hyphae/rename.go b/hyphae/rename.go index e0f7f1c..deb9881 100644 --- a/hyphae/rename.go +++ b/hyphae/rename.go @@ -50,8 +50,6 @@ func canRenameThisToThat(oh *Hypha, nh *Hypha, u *user.User) (err error, errtitl // RenameHypha renames hypha from old name `hyphaName` to `newName` and makes a history record about that. If `recursive` is `true`, its subhyphae will be renamed the same way. func (h *Hypha) RenameHypha(newHypha *Hypha, recursive bool, u *user.User) (hop *history.HistoryOp, errtitle string) { - h.Lock() - defer h.Unlock() newHypha.Lock() defer newHypha.Unlock() hop = history.Operation(history.TypeRenameHypha) diff --git a/hyphae/unattach.go b/hyphae/unattach.go index dab8dce..75c7baa 100644 --- a/hyphae/unattach.go +++ b/hyphae/unattach.go @@ -35,8 +35,6 @@ func (h *Hypha) CanUnattach(u *user.User) (err error, errtitle string) { // UnattachHypha unattaches hypha and makes a history record about that. func (h *Hypha) UnattachHypha(u *user.User) (hop *history.HistoryOp, errtitle string) { - h.Lock() - defer h.Unlock() hop = history.Operation(history.TypeUnattachHypha) if err, errtitle := h.CanUnattach(u); errtitle != "" { diff --git a/name.go b/name.go index e81a25b..739c166 100644 --- a/name.go +++ b/name.go @@ -47,8 +47,7 @@ func HyphaNameFromRq(rq *http.Request, actions ...string) string { return util.CanonicalName(strings.TrimPrefix(p, "/"+action+"/")) } } - log.Fatal("HyphaNameFromRq: no matching action passed") - return "" + panic("HyphaNameFromRq: no matching action passed") } // geminiHyphaNameFromRq extracts hypha name from gemini request. You have to also pass the action which is embedded in the url or several actions. For url /hypha/hypha, the action would be "hypha".