1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-07 02:10:26 +00:00

Fix textual hypha creation

This commit is contained in:
Timur Ismagilov 2022-02-04 22:25:07 +05:00 committed by Timur Ismagilov
parent 6fc5cf994e
commit ee233b9577
5 changed files with 19 additions and 23 deletions

View File

@ -21,7 +21,7 @@ func Index(path string) {
for nh := range ch { for nh := range ch {
switch oh := ByName(nh.CanonicalName()).(type) { switch oh := ByName(nh.CanonicalName()).(type) {
case *EmptyHypha: case *EmptyHypha:
insert(nh) Insert(nh)
default: default:
// In case of conflicts the newer hypha overwrites the previous // In case of conflicts the newer hypha overwrites the previous
switch nh, oh := nh.(*NonEmptyHypha), oh.(*NonEmptyHypha); { switch nh, oh := nh.(*NonEmptyHypha), oh.(*NonEmptyHypha); {

View File

@ -60,8 +60,8 @@ func RenameHyphaTo(h Hypher, newName string) {
h.Unlock() h.Unlock()
} }
// insert inserts the hypha into the storage, possibly overwriting the previous hypha with the same name. Count incrementation is done if needed. // Insert inserts the hypha into the storage, possibly overwriting the previous hypha with the same name. Count incrementation is done if needed.
func insert(h Hypher) (madeNewRecord bool) { func Insert(h Hypher) (madeNewRecord bool) {
_, recorded := byNames[h.CanonicalName()] _, recorded := byNames[h.CanonicalName()]
byNamesMutex.Lock() byNamesMutex.Lock()
@ -79,7 +79,7 @@ func insert(h Hypher) (madeNewRecord bool) {
func InsertIfNew(h Hypher) (madeNewRecord bool) { func InsertIfNew(h Hypher) (madeNewRecord bool) {
switch ByName(h.CanonicalName()).(type) { switch ByName(h.CanonicalName()).(type) {
case *EmptyHypha: case *EmptyHypha:
return insert(h) return Insert(h)
default: default:
return false return false
} }

View File

@ -35,13 +35,7 @@ func historyMessageForTextUpload(h hyphae.Hypher, userMessage string) string {
return fmt.Sprintf("%s %s: %s", verb, h.CanonicalName(), userMessage) return fmt.Sprintf("%s %s: %s", verb, h.CanonicalName(), userMessage)
} }
func writeTextToDiskForEmptyHypha(eh *hyphae.EmptyHypha, data []byte) error { func writeTextToDisk(h *hyphae.NonEmptyHypha, data []byte, hop *history.Op) error {
h := hyphae.FillEmptyHyphaUpToTextualHypha(eh, filepath.Join(files.HyphaeDir(), eh.CanonicalName()+".myco"))
return writeTextToDiskForNonEmptyHypha(h, data)
}
func writeTextToDiskForNonEmptyHypha(h *hyphae.NonEmptyHypha, data []byte) error {
if err := os.MkdirAll(filepath.Dir(h.TextPartPath()), 0777); err != nil { if err := os.MkdirAll(filepath.Dir(h.TextPartPath()), 0777); err != nil {
return err return err
} }
@ -49,6 +43,8 @@ func writeTextToDiskForNonEmptyHypha(h *hyphae.NonEmptyHypha, data []byte) error
if err := os.WriteFile(h.TextPartPath(), data, 0666); err != nil { if err := os.WriteFile(h.TextPartPath(), data, 0666); err != nil {
return err return err
} }
hop.WithFiles(h.TextPartPath())
return nil return nil
} }
@ -56,7 +52,8 @@ func writeTextToDiskForNonEmptyHypha(h *hyphae.NonEmptyHypha, data []byte) error
func UploadText(h hyphae.Hypher, data []byte, userMessage string, u *user.User, lc *l18n.Localizer) (hop *history.Op, errtitle string) { func UploadText(h hyphae.Hypher, data []byte, userMessage string, u *user.User, lc *l18n.Localizer) (hop *history.Op, errtitle string) {
hop = history. hop = history.
Operation(history.TypeEditText). Operation(history.TypeEditText).
WithMsg(historyMessageForTextUpload(h, userMessage)) WithMsg(historyMessageForTextUpload(h, userMessage)).
WithUser(u)
// Privilege check // Privilege check
if !u.CanProceed("upload-text") { if !u.CanProceed("upload-text") {
@ -93,12 +90,14 @@ func UploadText(h hyphae.Hypher, data []byte, userMessage string, u *user.User,
switch h := h.(type) { switch h := h.(type) {
case *hyphae.EmptyHypha: case *hyphae.EmptyHypha:
err := writeTextToDiskForEmptyHypha(h, data) H := hyphae.FillEmptyHyphaUpToTextualHypha(h, filepath.Join(files.HyphaeDir(), h.CanonicalName()+".myco"))
err := writeTextToDisk(H, data, hop)
if err != nil { if err != nil {
return hop.WithErrAbort(err), err.Error() return hop.WithErrAbort(err), err.Error()
} }
hyphae.InsertIfNew(h) hyphae.Insert(H)
case *hyphae.NonEmptyHypha: case *hyphae.NonEmptyHypha:
oldText, err := FetchTextPart(h) oldText, err := FetchTextPart(h)
if err != nil { if err != nil {
@ -111,7 +110,7 @@ func UploadText(h hyphae.Hypher, data []byte, userMessage string, u *user.User,
return hop.Abort(), "" return hop.Abort(), ""
} }
err = writeTextToDiskForNonEmptyHypha(h, data) err = writeTextToDisk(h, data, hop)
if err != nil { if err != nil {
return hop.WithErrAbort(err), err.Error() return hop.WithErrAbort(err), err.Error()
} }
@ -119,10 +118,7 @@ func UploadText(h hyphae.Hypher, data []byte, userMessage string, u *user.User,
backlinks.UpdateBacklinksAfterEdit(h, oldText) backlinks.UpdateBacklinksAfterEdit(h, oldText)
} }
return hop. return hop.Apply(), ""
WithFiles(h.TextPartPath()).
WithUser(u).
Apply(), ""
} }
// UploadBinary edits the hypha's media part and makes a history record about that. // UploadBinary edits the hypha's media part and makes a history record about that.

View File

@ -51,7 +51,7 @@ var (
) )
//line views/readers.qtpl:14 //line views/readers.qtpl:14
func StreamAttachmentMenuHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hyphae.MediaHypha, u *user.User) { func StreamAttachmentMenuHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hyphae.NonEmptyHypha, u *user.User) {
//line views/readers.qtpl:14 //line views/readers.qtpl:14
qw422016.N().S(` qw422016.N().S(`
`) `)
@ -265,7 +265,7 @@ func StreamAttachmentMenuHTML(qw422016 *qt422016.Writer, rq *http.Request, h *hy
} }
//line views/readers.qtpl:78 //line views/readers.qtpl:78
func WriteAttachmentMenuHTML(qq422016 qtio422016.Writer, rq *http.Request, h *hyphae.MediaHypha, u *user.User) { func WriteAttachmentMenuHTML(qq422016 qtio422016.Writer, rq *http.Request, h *hyphae.NonEmptyHypha, u *user.User) {
//line views/readers.qtpl:78 //line views/readers.qtpl:78
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line views/readers.qtpl:78 //line views/readers.qtpl:78
@ -276,7 +276,7 @@ func WriteAttachmentMenuHTML(qq422016 qtio422016.Writer, rq *http.Request, h *hy
} }
//line views/readers.qtpl:78 //line views/readers.qtpl:78
func AttachmentMenuHTML(rq *http.Request, h *hyphae.MediaHypha, u *user.User) string { func AttachmentMenuHTML(rq *http.Request, h *hyphae.NonEmptyHypha, u *user.User) string {
//line views/readers.qtpl:78 //line views/readers.qtpl:78
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line views/readers.qtpl:78 //line views/readers.qtpl:78

View File

@ -1020,7 +1020,7 @@ func StreamHyphaListHTML(qw422016 *qt422016.Writer, lc *l18n.Localizer) {
qw422016.N().S(` qw422016.N().S(`
`) `)
//line views/stuff.qtpl:265 //line views/stuff.qtpl:265
hypha := hyphae.ByName(hyphaName).(*hyphae.MediaHypha) hypha := hyphae.ByName(hyphaName).(*hyphae.NonEmptyHypha)
//line views/stuff.qtpl:265 //line views/stuff.qtpl:265
qw422016.N().S(` qw422016.N().S(`