mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-02-09 23:50:10 +00:00
Start the ontology refactoring
This commit is contained in:
parent
9fca911718
commit
ff10d577d2
@ -37,6 +37,24 @@ type Hypha struct {
|
|||||||
BinaryPath string // == "" => no attachment
|
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.
|
// TextPartPath returns rooted path to the file where the text part should be.
|
||||||
func (h *Hypha) TextPartPath() string {
|
func (h *Hypha) TextPartPath() string {
|
||||||
if h.TextPath == "" {
|
if h.TextPath == "" {
|
||||||
@ -103,16 +121,6 @@ func (h *Hypha) InsertIfNew() (justRecorded bool) {
|
|||||||
return false
|
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.
|
// RenameTo renames a hypha and performs respective changes in the storage.
|
||||||
func (h *Hypha) RenameTo(newName string) {
|
func (h *Hypha) RenameTo(newName string) {
|
||||||
byNamesMutex.Lock()
|
byNamesMutex.Lock()
|
||||||
|
32
hyphae/interface.go
Normal file
32
hyphae/interface.go
Normal 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()
|
||||||
|
}
|
@ -27,7 +27,7 @@ func DeleteHypha(u *user.User, h *hyphae.Hypha, lc *l18n.Localizer) (hop *histor
|
|||||||
Apply()
|
Apply()
|
||||||
if !hop.HasErrors() {
|
if !hop.HasErrors() {
|
||||||
backlinks.UpdateBacklinksAfterDelete(h, originalText)
|
backlinks.UpdateBacklinksAfterDelete(h, originalText)
|
||||||
h.Delete()
|
hyphae.DeleteHypha(h)
|
||||||
}
|
}
|
||||||
return hop, ""
|
return hop, ""
|
||||||
}
|
}
|
||||||
|
@ -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 nothing is left of the hypha
|
||||||
if h.TextPath == "" {
|
if h.TextPath == "" {
|
||||||
h.Delete()
|
hyphae.DeleteHypha(h)
|
||||||
}
|
}
|
||||||
return hop, ""
|
return hop, ""
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user