From 77688b38699a74dff12ec0813e680b22e3786fb9 Mon Sep 17 00:00:00 2001 From: bouncepaw Date: Thu, 18 Feb 2021 12:12:57 +0500 Subject: [PATCH] Fix a bug related to hyphae that have amnts but no text --- hyphae/hyphae.go | 12 +++++------- hyphae/upload.go | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/hyphae/hyphae.go b/hyphae/hyphae.go index 6fa5853..8db893d 100644 --- a/hyphae/hyphae.go +++ b/hyphae/hyphae.go @@ -107,9 +107,6 @@ func EmptyHypha(hyphaName string) *Hypha { // ByName returns a hypha by name. If h.Exists, the returned hypha pointer is known to be part of the hypha index (byNames map). func ByName(hyphaName string) (h *Hypha) { - byNamesMutex.Lock() - defer byNamesMutex.Unlock() - h, exists := byNames[hyphaName] if exists { return h @@ -119,22 +116,23 @@ func ByName(hyphaName string) (h *Hypha) { // Insert inserts the hypha into the storage. It overwrites the previous record, if there was any, and returns false. If the was no previous record, return true. func (h *Hypha) Insert() (justCreated bool) { - var hp *Hypha - hp = ByName(h.Name) + hp := ByName(h.Name) byNamesMutex.Lock() defer byNamesMutex.Unlock() if hp.Exists { hp = h } else { - byNames[hp.Name] = h + h.Exists = true + byNames[h.Name] = h + IncrementCount() } return !hp.Exists } func (h *Hypha) InsertIfNew() (justCreated bool) { - if h.Exists { + if !h.Exists { return h.Insert() } return false diff --git a/hyphae/upload.go b/hyphae/upload.go index c66d942..fcf2905 100644 --- a/hyphae/upload.go +++ b/hyphae/upload.go @@ -114,9 +114,9 @@ func (h *Hypha) uploadHelp(hop *history.HistoryOp, ext string, data []byte, u *u } h.InsertIfNew() - *originalFullPath = fullPath - if h.Exists && hop.Type == history.TypeEditText && !history.FileChanged(fullPath) { + if h.Exists && h.TextPath != "" && hop.Type == history.TypeEditText && !history.FileChanged(fullPath) { return hop.Abort(), "No changes" } + *originalFullPath = fullPath return hop.WithFiles(fullPath).WithUser(u).Apply(), "" }