From 62ff0f0c01aa2006cc57fc8364418758bdc3a129 Mon Sep 17 00:00:00 2001 From: bouncepaw Date: Wed, 21 Oct 2020 23:37:39 +0500 Subject: [PATCH] Check for name collisions of subhyphae when renaming recursively --- README.md | 8 ++++++-- hypha.go | 19 +++++++++++++------ main.go | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1ff54b3..f564532 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ -# šŸ„ MycorrhizaWiki 0.9 +# šŸ„ MycorrhizaWiki 0.10 A wiki engine. +This is the development branch for version 0.10. Features planned for this version: +* [ ] Mycomarkup +* [ ] CLI options +* [ ] CSS improvements + ## Building ```sh 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 * Authorization * Better history viewing -* More markups diff --git a/hypha.go b/hypha.go index 74a8685..f184ff3 100644 --- a/hypha.go +++ b/hypha.go @@ -61,10 +61,13 @@ func findHyphaeToRename(hyphaName string, recursive bool) []string { 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) for _, hn := range hyphaNames { if hd, ok := HyphaStorage[hn]; ok { + if _, nameUsed := HyphaStorage[replaceName(hn)]; nameUsed { + return nil, errors.New("Hypha " + replaceName(hn) + " already exists") + } if 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 @@ -94,11 +97,15 @@ func (hd *HyphaData) RenameHypha(hyphaName, newName string, recursive bool) *his replaceName = func(str string) string { return strings.Replace(str, hyphaName, newName, 1) } - hyphaNames = findHyphaeToRename(hyphaName, recursive) - renameMap = renamingPairs(hyphaNames, replaceName) - renameMsg = "Rename ā€˜%sā€™ to ā€˜%sā€™" - hop = history.Operation(history.TypeRenameHypha) + hyphaNames = findHyphaeToRename(hyphaName, recursive) + renameMap, err = renamingPairs(hyphaNames, replaceName) + renameMsg = "Rename ā€˜%sā€™ to ā€˜%sā€™" + hop = history.Operation(history.TypeRenameHypha) ) + if err != nil { + hop.Errs = append(hop.Errs, err) + return hop + } if recursive { renameMsg += " recursively" } diff --git a/main.go b/main.go index 7956270..e8ac7fd 100644 --- a/main.go +++ b/main.go @@ -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.WriteHeader(status) fmt.Fprint(w, base(title, fmt.Sprintf( - `

%s. Go back to the hypha.

`, + `

%s. Go back to the hypha.

`, errMsg, name))) }