diff --git a/history/history.go b/history/history.go index c57ef96..4a4bf9e 100644 --- a/history/history.go +++ b/history/history.go @@ -59,9 +59,9 @@ func (rev Revision) HyphaeLinks() (html string) { } for _, filename := range strings.Split(out.String(), "\n") { // If filename has an ampersand: - if strings.IndexRune(filename, '&') >= 0 { + if strings.IndexRune(filename, '.') >= 0 { // Remove ampersanded suffix from filename: - ampersandPos := strings.LastIndexByte(filename, '&') + ampersandPos := strings.LastIndexByte(filename, '.') hyphaName := string([]byte(filename)[0:ampersandPos]) // is it safe? if isNewName(hyphaName) { // Entries are separated by commas diff --git a/history/information.go b/history/information.go index 469d9ab..164e3a9 100644 --- a/history/information.go +++ b/history/information.go @@ -39,7 +39,7 @@ func Revisions(hyphaName string) ([]Revision, error) { "log", "--oneline", "--no-merges", // Hash, Commiter email, Commiter time, Commit msg separated by tab "--pretty=format:\"%h\t%ce\t%ct\t%s\"", - "--", hyphaName+"&.*", + "--", hyphaName+".*", ) revs []Revision ) diff --git a/http_mutators.go b/http_mutators.go index 4801fe6..5f5d6b4 100644 --- a/http_mutators.go +++ b/http_mutators.go @@ -129,6 +129,9 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) { hyphaData, isOld = HyphaStorage[hyphaName] textData = rq.PostFormValue("text") ) + if !isOld { + hyphaData = &HyphaData{} + } if textData == "" { HttpErr(w, http.StatusBadRequest, hyphaName, "Error", "No text data passed") return @@ -159,8 +162,11 @@ func handlerUploadBinary(w http.ResponseWriter, rq *http.Request) { var ( hyphaData, isOld = HyphaStorage[hyphaName] mime = handler.Header.Get("Content-Type") - hop = hyphaData.UploadBinary(hyphaName, mime, file, isOld) ) + if !isOld { + hyphaData = &HyphaData{} + } + hop := hyphaData.UploadBinary(hyphaName, mime, file, isOld) if len(hop.Errs) != 0 { HttpErr(w, http.StatusInternalServerError, hyphaName, "Error", hop.Errs[0].Error()) diff --git a/http_readers.go b/http_readers.go index 8166353..d6cb9da 100644 --- a/http_readers.go +++ b/http_readers.go @@ -33,7 +33,7 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) { revHash = shorterUrl[:firstSlashIndex] hyphaName = CanonicalName(shorterUrl[firstSlashIndex+1:]) contents = fmt.Sprintf(`

This hypha had no text at this revision.

`) - textPath = hyphaName + "&.gmi" + textPath = hyphaName + ".myco" textContents, err = history.FileAtRevision(textPath, revHash) ) if err == nil { diff --git a/hypha.go b/hypha.go index 322a3d8..b95f5d1 100644 --- a/hypha.go +++ b/hypha.go @@ -40,7 +40,7 @@ type HyphaData struct { } // uploadHelp is a helper function for UploadText and UploadBinary -func (hd *HyphaData) uploadHelp(hop *history.HistoryOp, hyphaName, ext, originalFullPath string, isOld bool, data []byte) *history.HistoryOp { +func (hd *HyphaData) uploadHelp(hop *history.HistoryOp, hyphaName, ext string, originalFullPath *string, isOld bool, data []byte) *history.HistoryOp { var ( fullPath = filepath.Join(WikiDir, hyphaName+ext) ) @@ -51,16 +51,17 @@ func (hd *HyphaData) uploadHelp(hop *history.HistoryOp, hyphaName, ext, original if err := ioutil.WriteFile(fullPath, data, 0644); err != nil { return hop.WithError(err) } - - if isOld && originalFullPath != fullPath { - if err := history.Rename(originalFullPath, fullPath); err != nil { + if isOld && *originalFullPath != fullPath && *originalFullPath != "" { + if err := history.Rename(*originalFullPath, fullPath); err != nil { return hop.WithError(err) } - log.Println("Move", originalFullPath, "to", fullPath) + log.Println("Move", *originalFullPath, "to", fullPath) } if !isOld { HyphaStorage[hyphaName] = hd } + *originalFullPath = fullPath + log.Printf("%v\n", *hd) return hop.WithFiles(fullPath). WithSignature("anon"). Apply() @@ -69,7 +70,7 @@ func (hd *HyphaData) uploadHelp(hop *history.HistoryOp, hyphaName, ext, original // UploadText loads a new text part from `textData` for hypha `hyphaName` with `hd`. It must be marked if the hypha `isOld`. func (hd *HyphaData) UploadText(hyphaName, textData string, isOld bool) *history.HistoryOp { hop := history.Operation(history.TypeEditText).WithMsg(fmt.Sprintf("Edit ā€˜%sā€™", hyphaName)) - return hd.uploadHelp(hop, hyphaName, ".myco", hd.textPath, isOld, []byte(textData)) + return hd.uploadHelp(hop, hyphaName, ".myco", &hd.textPath, isOld, []byte(textData)) } // UploadBinary loads a new binary part from `file` for hypha `hyphaName` with `hd`. The contents have the specified `mime` type. It must be marked if the hypha `isOld`. @@ -82,7 +83,7 @@ func (hd *HyphaData) UploadBinary(hyphaName, mime string, file multipart.File, i return hop.WithError(err) } - return hd.uploadHelp(hop, hyphaName, MimeToExtension(mime), hd.binaryPath, isOld, data) + return hd.uploadHelp(hop, hyphaName, MimeToExtension(mime), &hd.binaryPath, isOld, data) } // DeleteHypha deletes hypha and makes a history record about that. diff --git a/main.go b/main.go index b8a6c78..abb11f8 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ var HyphaStorage = make(map[string]*HyphaData) // IterateHyphaNamesWith is a closure to be passed to subpackages to let them iterate all hypha names read-only. func IterateHyphaNamesWith(f func(string)) { - for hyphaName, _ := range HyphaStorage { + for hyphaName := range HyphaStorage { f(hyphaName) } } diff --git a/metarrhiza b/metarrhiza index faab70f..abb535c 160000 --- a/metarrhiza +++ b/metarrhiza @@ -1 +1 @@ -Subproject commit faab70f77e18197b1c4cecb5ad54e6d26da843f5 +Subproject commit abb535c0a90e78b92f31f4bf25764dc1fa0e3122