1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-14 06:10:26 +00:00
mycorrhiza/hyphae/existing_hypha.go
2022-02-19 11:31:54 +03:00

40 lines
976 B
Go

package hyphae
import (
"github.com/bouncepaw/mycorrhiza/util"
)
// ExistingHypha is not EmptyHypha.
type ExistingHypha interface {
Hypha
// DoesExist does nothing except marks that the type is an ExistingHypha.
DoesExist()
HasTextFile() bool
TextFilePath() string
}
// RenameHyphaTo renames a hypha and renames stored filepaths as needed. The actual files are not moved, move them yourself.
func RenameHyphaTo(h ExistingHypha, newName string, replaceName func(string) string) {
// TODO: that replaceName is suspicious.
newName = util.CanonicalName(newName)
byNamesMutex.Lock()
h.Lock()
delete(byNames, h.CanonicalName())
switch h := h.(type) {
case *TextualHypha:
h.canonicalName = newName
h.mycoFilePath = replaceName(h.mycoFilePath)
case *MediaHypha:
h.canonicalName = newName
h.mycoFilePath = replaceName(h.mediaFilePath)
h.mediaFilePath = replaceName(h.mediaFilePath)
}
byNames[h.CanonicalName()] = h
byNamesMutex.Unlock()
h.Unlock()
}