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:
parent
dbafbb85d7
commit
9173b54c91
@ -59,9 +59,9 @@ func (rev Revision) HyphaeLinks() (html string) {
|
|||||||
}
|
}
|
||||||
for _, filename := range strings.Split(out.String(), "\n") {
|
for _, filename := range strings.Split(out.String(), "\n") {
|
||||||
// If filename has an ampersand:
|
// If filename has an ampersand:
|
||||||
if strings.IndexRune(filename, '&') >= 0 {
|
if strings.IndexRune(filename, '.') >= 0 {
|
||||||
// Remove ampersanded suffix from filename:
|
// Remove ampersanded suffix from filename:
|
||||||
ampersandPos := strings.LastIndexByte(filename, '&')
|
ampersandPos := strings.LastIndexByte(filename, '.')
|
||||||
hyphaName := string([]byte(filename)[0:ampersandPos]) // is it safe?
|
hyphaName := string([]byte(filename)[0:ampersandPos]) // is it safe?
|
||||||
if isNewName(hyphaName) {
|
if isNewName(hyphaName) {
|
||||||
// Entries are separated by commas
|
// Entries are separated by commas
|
||||||
|
@ -39,7 +39,7 @@ func Revisions(hyphaName string) ([]Revision, error) {
|
|||||||
"log", "--oneline", "--no-merges",
|
"log", "--oneline", "--no-merges",
|
||||||
// Hash, Commiter email, Commiter time, Commit msg separated by tab
|
// Hash, Commiter email, Commiter time, Commit msg separated by tab
|
||||||
"--pretty=format:\"%h\t%ce\t%ct\t%s\"",
|
"--pretty=format:\"%h\t%ce\t%ct\t%s\"",
|
||||||
"--", hyphaName+"&.*",
|
"--", hyphaName+".*",
|
||||||
)
|
)
|
||||||
revs []Revision
|
revs []Revision
|
||||||
)
|
)
|
||||||
|
@ -129,6 +129,9 @@ func handlerUploadText(w http.ResponseWriter, rq *http.Request) {
|
|||||||
hyphaData, isOld = HyphaStorage[hyphaName]
|
hyphaData, isOld = HyphaStorage[hyphaName]
|
||||||
textData = rq.PostFormValue("text")
|
textData = rq.PostFormValue("text")
|
||||||
)
|
)
|
||||||
|
if !isOld {
|
||||||
|
hyphaData = &HyphaData{}
|
||||||
|
}
|
||||||
if textData == "" {
|
if textData == "" {
|
||||||
HttpErr(w, http.StatusBadRequest, hyphaName, "Error", "No text data passed")
|
HttpErr(w, http.StatusBadRequest, hyphaName, "Error", "No text data passed")
|
||||||
return
|
return
|
||||||
@ -159,8 +162,11 @@ func handlerUploadBinary(w http.ResponseWriter, rq *http.Request) {
|
|||||||
var (
|
var (
|
||||||
hyphaData, isOld = HyphaStorage[hyphaName]
|
hyphaData, isOld = HyphaStorage[hyphaName]
|
||||||
mime = handler.Header.Get("Content-Type")
|
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 {
|
if len(hop.Errs) != 0 {
|
||||||
HttpErr(w, http.StatusInternalServerError, hyphaName, "Error", hop.Errs[0].Error())
|
HttpErr(w, http.StatusInternalServerError, hyphaName, "Error", hop.Errs[0].Error())
|
||||||
|
@ -33,7 +33,7 @@ func handlerRevision(w http.ResponseWriter, rq *http.Request) {
|
|||||||
revHash = shorterUrl[:firstSlashIndex]
|
revHash = shorterUrl[:firstSlashIndex]
|
||||||
hyphaName = CanonicalName(shorterUrl[firstSlashIndex+1:])
|
hyphaName = CanonicalName(shorterUrl[firstSlashIndex+1:])
|
||||||
contents = fmt.Sprintf(`<p>This hypha had no text at this revision.</p>`)
|
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)
|
textContents, err = history.FileAtRevision(textPath, revHash)
|
||||||
)
|
)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
15
hypha.go
15
hypha.go
@ -40,7 +40,7 @@ type HyphaData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// uploadHelp is a helper function for UploadText and UploadBinary
|
// 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 (
|
var (
|
||||||
fullPath = filepath.Join(WikiDir, hyphaName+ext)
|
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 {
|
if err := ioutil.WriteFile(fullPath, data, 0644); err != nil {
|
||||||
return hop.WithError(err)
|
return hop.WithError(err)
|
||||||
}
|
}
|
||||||
|
if isOld && *originalFullPath != fullPath && *originalFullPath != "" {
|
||||||
if isOld && originalFullPath != fullPath {
|
if err := history.Rename(*originalFullPath, fullPath); err != nil {
|
||||||
if err := history.Rename(originalFullPath, fullPath); err != nil {
|
|
||||||
return hop.WithError(err)
|
return hop.WithError(err)
|
||||||
}
|
}
|
||||||
log.Println("Move", originalFullPath, "to", fullPath)
|
log.Println("Move", *originalFullPath, "to", fullPath)
|
||||||
}
|
}
|
||||||
if !isOld {
|
if !isOld {
|
||||||
HyphaStorage[hyphaName] = hd
|
HyphaStorage[hyphaName] = hd
|
||||||
}
|
}
|
||||||
|
*originalFullPath = fullPath
|
||||||
|
log.Printf("%v\n", *hd)
|
||||||
return hop.WithFiles(fullPath).
|
return hop.WithFiles(fullPath).
|
||||||
WithSignature("anon").
|
WithSignature("anon").
|
||||||
Apply()
|
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`.
|
// 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 {
|
func (hd *HyphaData) UploadText(hyphaName, textData string, isOld bool) *history.HistoryOp {
|
||||||
hop := history.Operation(history.TypeEditText).WithMsg(fmt.Sprintf("Edit ‘%s’", hyphaName))
|
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`.
|
// 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 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.
|
// DeleteHypha deletes hypha and makes a history record about that.
|
||||||
|
2
main.go
2
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.
|
// IterateHyphaNamesWith is a closure to be passed to subpackages to let them iterate all hypha names read-only.
|
||||||
func IterateHyphaNamesWith(f func(string)) {
|
func IterateHyphaNamesWith(f func(string)) {
|
||||||
for hyphaName, _ := range HyphaStorage {
|
for hyphaName := range HyphaStorage {
|
||||||
f(hyphaName)
|
f(hyphaName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit faab70f77e18197b1c4cecb5ad54e6d26da843f5
|
Subproject commit abb535c0a90e78b92f31f4bf25764dc1fa0e3122
|
Loading…
Reference in New Issue
Block a user