1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-18 22:52:50 +00:00

Fix some bugs related to the new file structure

This commit is contained in:
bouncepaw 2020-10-25 18:50:14 +05:00
parent dbafbb85d7
commit 9173b54c91
7 changed files with 21 additions and 14 deletions

View File

@ -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

View File

@ -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
)

View File

@ -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())

View File

@ -33,7 +33,7 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) {
revHash = shorterUrl[:firstSlashIndex]
hyphaName = CanonicalName(shorterUrl[firstSlashIndex+1:])
contents = fmt.Sprintf(`<p>This hypha had no text at this revision.</p>`)
textPath = hyphaName + "&.gmi"
textPath = hyphaName + ".myco"
textContents, err = history.FileAtRevision(textPath, revHash)
)
if err == nil {

View File

@ -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.

View File

@ -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)
}
}

@ -1 +1 @@
Subproject commit faab70f77e18197b1c4cecb5ad54e6d26da843f5
Subproject commit abb535c0a90e78b92f31f4bf25764dc1fa0e3122