1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-29 19:26:16 +00:00

Hopefully fix some bugs on Windows

This commit is contained in:
Timur Ismagilov 2024-06-11 02:52:47 +03:00
parent 9ef08fb42d
commit a0ec4f5fbf
2 changed files with 16 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package hyphae
import (
"log"
"log/slog"
"os"
"path/filepath"
@ -27,11 +28,10 @@ func Index(path string) {
switch foundHypha := foundHypha.(type) {
case *TextualHypha: // conflict! overwrite
storedHypha.mycoFilePath = foundHypha.mycoFilePath
log.Printf(
"File collision for hypha %s, using %s rather than %s\n",
foundHypha.CanonicalName(),
foundHypha.TextFilePath(),
storedHypha.TextFilePath(),
slog.Info("File collision",
"hypha", foundHypha.CanonicalName(),
"usingFile", foundHypha.TextFilePath(),
"insteadOf", storedHypha.TextFilePath(),
)
case *MediaHypha: // no conflict
Insert(ExtendTextualToMedia(storedHypha, foundHypha.mediaFilePath))
@ -43,11 +43,11 @@ func Index(path string) {
storedHypha.mycoFilePath = foundHypha.mycoFilePath
case *MediaHypha: // conflict! overwrite
storedHypha.mediaFilePath = foundHypha.mediaFilePath
log.Printf(
"File collision for hypha %s, using %s rather than %s\n",
foundHypha.CanonicalName(),
foundHypha.MediaFilePath(),
storedHypha.MediaFilePath(),
slog.Info("File collision",
"hypha", foundHypha.CanonicalName(),
"usingFile", foundHypha.MediaFilePath(),
"insteadOf", storedHypha.MediaFilePath(),
)
}
}

View File

@ -15,6 +15,7 @@ import (
"mime/multipart"
"os"
"path/filepath"
"strings"
)
func historyMessageForTextUpload(h hyphae.Hypha, userMessage string) string {
@ -78,7 +79,9 @@ func UploadText(h hyphae.Hypha, data []byte, userMessage string, u *user.User) e
switch h := h.(type) {
case *hyphae.EmptyHypha:
H := hyphae.ExtendEmptyToTextual(h, filepath.Join(files.HyphaeDir(), h.CanonicalName()+".myco"))
parts := []string{files.HyphaeDir()}
parts = append(parts, strings.Split(h.CanonicalName()+".myco", "\\")...)
H := hyphae.ExtendEmptyToTextual(h, filepath.Join(parts...))
err := writeTextToDisk(H, data, hop)
if err != nil {
@ -139,7 +142,8 @@ func writeMediaToDisk(h hyphae.Hypha, mime string, data []byte) (string, error)
var (
ext = mimetype.ToExtension(mime)
// That's where the file will go
uploadedFilePath = filepath.Join(files.HyphaeDir(), h.CanonicalName()+ext)
uploadedFilePath = filepath.Join(append([]string{files.HyphaeDir()}, strings.Split(h.CanonicalName()+ext, "\\")...)...)
)
if err := os.MkdirAll(filepath.Dir(uploadedFilePath), 0777); err != nil {