1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-08-06 13:55:36 +00:00

Check for name collisions of subhyphae when renaming recursively

This commit is contained in:
bouncepaw 2020-10-21 23:37:39 +05:00
parent cbb7a02c84
commit 62ff0f0c01
3 changed files with 20 additions and 9 deletions

View File

@ -1,6 +1,11 @@
# 🍄 MycorrhizaWiki 0.9 # 🍄 MycorrhizaWiki 0.10
A wiki engine. A wiki engine.
This is the development branch for version 0.10. Features planned for this version:
* [ ] Mycomarkup
* [ ] CLI options
* [ ] CSS improvements
## Building ## Building
```sh ```sh
git clone --recurse-submodules https://github.com/bouncepaw/mycorrhiza git clone --recurse-submodules https://github.com/bouncepaw/mycorrhiza
@ -34,4 +39,3 @@ Help is always needed. We have a [tg chat](https://t.me/mycorrhizadev) where som
* Tagging system * Tagging system
* Authorization * Authorization
* Better history viewing * Better history viewing
* More markups

View File

@ -61,10 +61,13 @@ func findHyphaeToRename(hyphaName string, recursive bool) []string {
return hyphae return hyphae
} }
func renamingPairs(hyphaNames []string, replaceName func(string) string) map[string]string { func renamingPairs(hyphaNames []string, replaceName func(string) string) (map[string]string, error) {
renameMap := make(map[string]string) renameMap := make(map[string]string)
for _, hn := range hyphaNames { for _, hn := range hyphaNames {
if hd, ok := HyphaStorage[hn]; ok { if hd, ok := HyphaStorage[hn]; ok {
if _, nameUsed := HyphaStorage[replaceName(hn)]; nameUsed {
return nil, errors.New("Hypha " + replaceName(hn) + " already exists")
}
if hd.textPath != "" { if hd.textPath != "" {
renameMap[hd.textPath] = replaceName(hd.textPath) renameMap[hd.textPath] = replaceName(hd.textPath)
} }
@ -73,7 +76,7 @@ func renamingPairs(hyphaNames []string, replaceName func(string) string) map[str
} }
} }
} }
return renameMap return renameMap, nil
} }
// word Data is plural here // word Data is plural here
@ -94,11 +97,15 @@ func (hd *HyphaData) RenameHypha(hyphaName, newName string, recursive bool) *his
replaceName = func(str string) string { replaceName = func(str string) string {
return strings.Replace(str, hyphaName, newName, 1) return strings.Replace(str, hyphaName, newName, 1)
} }
hyphaNames = findHyphaeToRename(hyphaName, recursive) hyphaNames = findHyphaeToRename(hyphaName, recursive)
renameMap = renamingPairs(hyphaNames, replaceName) renameMap, err = renamingPairs(hyphaNames, replaceName)
renameMsg = "Rename %s to %s" renameMsg = "Rename %s to %s"
hop = history.Operation(history.TypeRenameHypha) hop = history.Operation(history.TypeRenameHypha)
) )
if err != nil {
hop.Errs = append(hop.Errs, err)
return hop
}
if recursive { if recursive {
renameMsg += " recursively" renameMsg += " recursively"
} }

View File

@ -40,7 +40,7 @@ func HttpErr(w http.ResponseWriter, status int, name, title, errMsg string) {
w.Header().Set("Content-Type", "text/html;charset=utf-8") w.Header().Set("Content-Type", "text/html;charset=utf-8")
w.WriteHeader(status) w.WriteHeader(status)
fmt.Fprint(w, base(title, fmt.Sprintf( fmt.Fprint(w, base(title, fmt.Sprintf(
`<p>%s. <a href="/page/%s">Go back to the hypha.<a></p>`, `<main><p>%s. <a href="/page/%s">Go back to the hypha.<a></p></main>`,
errMsg, name))) errMsg, name)))
} }