mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-10-27 13:47:41 +00:00
Play with stuff
This commit is contained in:
committed by
Timur Ismagilov
parent
1c317e39aa
commit
d0dbbe4714
@@ -23,7 +23,7 @@ func Index(path string) {
|
|||||||
if oh := ByName(h.name); oh.Exists {
|
if oh := ByName(h.name); oh.Exists {
|
||||||
oh.mergeIn(h)
|
oh.mergeIn(h)
|
||||||
} else {
|
} else {
|
||||||
h.insert()
|
insert(h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Println("Indexed", Count(), "hyphae")
|
log.Println("Indexed", Count(), "hyphae")
|
||||||
@@ -40,10 +40,8 @@ func indexHelper(path string, nestLevel uint, ch chan *Hypha) {
|
|||||||
|
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
// If this hypha looks like it can be a hypha path, go deeper. Do not
|
// If this hypha looks like it can be a hypha path, go deeper. Do not
|
||||||
// touch the .git and static folders for they have an administrative
|
// touch the .git folders for it has an administrative importance!
|
||||||
// importance!
|
if node.IsDir() && IsValidName(node.Name()) && node.Name() != ".git" {
|
||||||
if node.IsDir() && IsValidName(node.Name()) && node.Name() != ".git" &&
|
|
||||||
!(nestLevel == 0 && node.Name() == "static") {
|
|
||||||
indexHelper(filepath.Join(path, node.Name()), nestLevel+1, ch)
|
indexHelper(filepath.Join(path, node.Name()), nestLevel+1, ch)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ func storeHypha(h *Hypha) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert inserts the hypha into the storage. A previous record is used if possible. Count incrementation is done if needed.
|
// insert inserts the hypha into the storage. A previous record is used if possible. Count incrementation is done if needed.
|
||||||
func (h *Hypha) insert() (madeNewRecord bool) {
|
func insert(h *Hypha) (madeNewRecord bool) {
|
||||||
hp, recorded := byNames[h.name]
|
hp, recorded := byNames[h.name]
|
||||||
if recorded {
|
if recorded {
|
||||||
hp.mergeIn(h)
|
hp.mergeIn(h)
|
||||||
@@ -123,11 +123,11 @@ func (h *Hypha) insert() (madeNewRecord bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InsertIfNew checks whether hypha exists and returns `true` if it didn't and has been created.
|
// InsertIfNew checks whether hypha exists and returns `true` if it didn't and has been created.
|
||||||
func (h *Hypha) InsertIfNew() (madeNewRecord bool) {
|
func InsertIfNew(h *Hypha) (madeNewRecord bool) {
|
||||||
if h.DoesExist() {
|
if h.DoesExist() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return h.insert()
|
return insert(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenameTo renames a hypha and performs respective changes in the storage.
|
// RenameTo renames a hypha and performs respective changes in the storage.
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ func uploadHelp(h *hyphae.Hypha, hop *history.Op, ext string, data []byte, u *us
|
|||||||
log.Println("Move", sourceFullPath, "to", fullPath)
|
log.Println("Move", sourceFullPath, "to", fullPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
h.InsertIfNew()
|
hyphae.InsertIfNew(h)
|
||||||
if h.Exists && h.TextPath != "" && hop.Type == history.TypeEditText && !history.FileChanged(fullPath) {
|
if h.Exists && h.TextPath != "" && hop.Type == history.TypeEditText && !history.FileChanged(fullPath) {
|
||||||
return hop.Abort(), "No changes"
|
return hop.Abort(), "No changes"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
// FetchTextPart tries to read text file of the given hypha. If there is no file, empty string is returned.
|
// FetchTextPart tries to read text file of the given hypha. If there is no file, empty string is returned.
|
||||||
func FetchTextPart(h *hyphae.Hypha) (string, error) {
|
func FetchTextPart(h *hyphae.Hypha) (string, error) {
|
||||||
if h.TextPath == "" {
|
if !h.HasTextPart() {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
text, err := os.ReadFile(h.TextPath)
|
text, err := os.ReadFile(h.TextPath)
|
||||||
|
|||||||
Reference in New Issue
Block a user