1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00

Fix a bug related to hyphae that have amnts but no text

This commit is contained in:
bouncepaw 2021-02-18 12:12:57 +05:00
parent c7024da735
commit 77688b3869
2 changed files with 7 additions and 9 deletions

View File

@ -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). // 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) { func ByName(hyphaName string) (h *Hypha) {
byNamesMutex.Lock()
defer byNamesMutex.Unlock()
h, exists := byNames[hyphaName] h, exists := byNames[hyphaName]
if exists { if exists {
return h 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. // 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) { func (h *Hypha) Insert() (justCreated bool) {
var hp *Hypha hp := ByName(h.Name)
hp = ByName(h.Name)
byNamesMutex.Lock() byNamesMutex.Lock()
defer byNamesMutex.Unlock() defer byNamesMutex.Unlock()
if hp.Exists { if hp.Exists {
hp = h hp = h
} else { } else {
byNames[hp.Name] = h h.Exists = true
byNames[h.Name] = h
IncrementCount()
} }
return !hp.Exists return !hp.Exists
} }
func (h *Hypha) InsertIfNew() (justCreated bool) { func (h *Hypha) InsertIfNew() (justCreated bool) {
if h.Exists { if !h.Exists {
return h.Insert() return h.Insert()
} }
return false return false

View File

@ -114,9 +114,9 @@ func (h *Hypha) uploadHelp(hop *history.HistoryOp, ext string, data []byte, u *u
} }
h.InsertIfNew() h.InsertIfNew()
*originalFullPath = fullPath if h.Exists && h.TextPath != "" && hop.Type == history.TypeEditText && !history.FileChanged(fullPath) {
if h.Exists && hop.Type == history.TypeEditText && !history.FileChanged(fullPath) {
return hop.Abort(), "No changes" return hop.Abort(), "No changes"
} }
*originalFullPath = fullPath
return hop.WithFiles(fullPath).WithUser(u).Apply(), "" return hop.WithFiles(fullPath).WithUser(u).Apply(), ""
} }