mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-12-12 05:20:26 +00:00
Fix the renaming bug
This commit is contained in:
parent
43fbe3c6e2
commit
355fd4b1b0
7
hypha.go
7
hypha.go
@ -8,7 +8,7 @@ import (
|
|||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"regexp"
|
||||||
|
|
||||||
"github.com/bouncepaw/mycorrhiza/history"
|
"github.com/bouncepaw/mycorrhiza/history"
|
||||||
"github.com/bouncepaw/mycorrhiza/hyphae"
|
"github.com/bouncepaw/mycorrhiza/hyphae"
|
||||||
@ -88,7 +88,7 @@ func uploadHelp(hop *history.HistoryOp, hyphaName, ext string, data []byte, u *u
|
|||||||
hyphae.IncrementCount()
|
hyphae.IncrementCount()
|
||||||
}
|
}
|
||||||
*originalFullPath = fullPath
|
*originalFullPath = fullPath
|
||||||
if hop.Type == history.TypeEditText && !history.FileChanged(fullPath) {
|
if isOld && hop.Type == history.TypeEditText && !history.FileChanged(fullPath) {
|
||||||
return hop.Abort()
|
return hop.Abort()
|
||||||
}
|
}
|
||||||
return hop.WithFiles(fullPath).
|
return hop.WithFiles(fullPath).
|
||||||
@ -195,8 +195,9 @@ func relocateHyphaData(hyphaNames []string, replaceName func(string) string) {
|
|||||||
// RenameHypha renames hypha from old name `hyphaName` to `newName` and makes a history record about that. If `recursive` is `true`, its subhyphae will be renamed the same way.
|
// RenameHypha renames hypha from old name `hyphaName` to `newName` and makes a history record about that. If `recursive` is `true`, its subhyphae will be renamed the same way.
|
||||||
func RenameHypha(hyphaName, newName string, recursive bool, u *user.User) *history.HistoryOp {
|
func RenameHypha(hyphaName, newName string, recursive bool, u *user.User) *history.HistoryOp {
|
||||||
var (
|
var (
|
||||||
|
re = regexp.MustCompile(`(?i)` + hyphaName)
|
||||||
replaceName = func(str string) string {
|
replaceName = func(str string) string {
|
||||||
return strings.Replace(str, hyphaName, newName, 1)
|
return re.ReplaceAllString(CanonicalName(str), newName)
|
||||||
}
|
}
|
||||||
hyphaNames = findHyphaeToRename(hyphaName, recursive)
|
hyphaNames = findHyphaeToRename(hyphaName, recursive)
|
||||||
renameMap, err = renamingPairs(hyphaNames, replaceName)
|
renameMap, err = renamingPairs(hyphaNames, replaceName)
|
||||||
|
Loading…
Reference in New Issue
Block a user