1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-02-09 07:30:11 +00:00

Start the ontology refactoring

This commit is contained in:
Timur Ismagilov 2022-02-04 02:26:08 +05:00 committed by Timur Ismagilov
parent 9fca911718
commit ff10d577d2
4 changed files with 52 additions and 12 deletions

View File

@ -37,6 +37,24 @@ type Hypha struct {
BinaryPath string // == "" => no attachment
}
func (h *Hypha) CanonicalName() string {
return h.Name
}
func (h *Hypha) Kind() HyphaKind {
if !h.Exists {
return HyphaEmpty
}
if h.HasAttachment() {
return HyphaMedia
}
return HyphaText
}
func (h *Hypha) HasTextPart() bool {
return h.TextPath != ""
}
// TextPartPath returns rooted path to the file where the text part should be.
func (h *Hypha) TextPartPath() string {
if h.TextPath == "" {
@ -103,16 +121,6 @@ func (h *Hypha) InsertIfNew() (justRecorded bool) {
return false
}
// Delete removes a hypha from the storage.
func (h *Hypha) Delete() {
byNamesMutex.Lock()
h.Lock()
delete(byNames, h.Name)
decrementCount()
byNamesMutex.Unlock()
h.Unlock()
}
// RenameTo renames a hypha and performs respective changes in the storage.
func (h *Hypha) RenameTo(newName string) {
byNamesMutex.Lock()

32
hyphae/interface.go Normal file
View File

@ -0,0 +1,32 @@
package hyphae
import "sync"
type HyphaKind int
const (
HyphaEmpty HyphaKind = iota
HyphaText
HyphaMedia
)
// Hypher is a temporary name for this interface. The name will become Hypha, once the struct with the said name is deprecated for good.
type Hypher interface {
sync.Locker
CanonicalName() string
Kind() HyphaKind
HasTextPart() bool
TextPartPath() string
}
// DeleteHypha deletes the hypha from the storage.
func DeleteHypha(h Hypher) {
byNamesMutex.Lock()
h.Lock()
delete(byNames, h.CanonicalName())
decrementCount()
byNamesMutex.Unlock()
h.Unlock()
}

View File

@ -27,7 +27,7 @@ func DeleteHypha(u *user.User, h *hyphae.Hypha, lc *l18n.Localizer) (hop *histor
Apply()
if !hop.HasErrors() {
backlinks.UpdateBacklinksAfterDelete(h, originalText)
h.Delete()
hyphae.DeleteHypha(h)
}
return hop, ""
}

View File

@ -35,7 +35,7 @@ func UnattachHypha(u *user.User, h *hyphae.Hypha, lc *l18n.Localizer) (hop *hist
}
// If nothing is left of the hypha
if h.TextPath == "" {
h.Delete()
hyphae.DeleteHypha(h)
}
return hop, ""
}