diff --git a/hyphae/files.go b/hyphae/files.go index f1bc400..43b8c67 100644 --- a/hyphae/files.go +++ b/hyphae/files.go @@ -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(), ) } } diff --git a/shroom/upload.go b/shroom/upload.go index 5599b01..8750ca9 100644 --- a/shroom/upload.go +++ b/shroom/upload.go @@ -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 {