1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-05-19 13:54:05 +00:00

Migrate away from ioutil

This commit is contained in:
handlerug 2021-07-02 15:29:55 +07:00
parent b87583ef28
commit 3dccbd602c
No known key found for this signature in database
GPG Key ID: 38009F0605051491
4 changed files with 8 additions and 10 deletions

View File

@ -1,8 +1,8 @@
package hyphae package hyphae
import ( import (
"io/ioutil"
"log" "log"
"os"
"path/filepath" "path/filepath"
"github.com/bouncepaw/mycorrhiza/mimetype" "github.com/bouncepaw/mycorrhiza/mimetype"
@ -33,7 +33,7 @@ func Index(path string) {
// indexHelper finds all hypha files in the full `path` and sends them to the channel. Handling of duplicate entries and attachment and counting them is up to the caller. // indexHelper finds all hypha files in the full `path` and sends them to the channel. Handling of duplicate entries and attachment and counting them is up to the caller.
func indexHelper(path string, nestLevel uint, ch chan *Hypha) { func indexHelper(path string, nestLevel uint, ch chan *Hypha) {
nodes, err := ioutil.ReadDir(path) nodes, err := os.ReadDir(path)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -3,7 +3,7 @@ package shroom
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"log" "log"
"mime/multipart" "mime/multipart"
"os" "os"
@ -45,7 +45,7 @@ func UploadText(h *hyphae.Hypha, data []byte, message string, u *user.User) (hop
func UploadBinary(h *hyphae.Hypha, mime string, file multipart.File, u *user.User) (*history.HistoryOp, string) { func UploadBinary(h *hyphae.Hypha, mime string, file multipart.File, u *user.User) (*history.HistoryOp, string) {
var ( var (
hop = history.Operation(history.TypeEditBinary).WithMsg(fmt.Sprintf("Upload binary part for %s with type %s", h.Name, mime)) hop = history.Operation(history.TypeEditBinary).WithMsg(fmt.Sprintf("Upload binary part for %s with type %s", h.Name, mime))
data, err = ioutil.ReadAll(file) data, err = io.ReadAll(file)
) )
if err != nil { if err != nil {
@ -80,7 +80,7 @@ func uploadHelp(h *hyphae.Hypha, hop *history.HistoryOp, ext string, data []byte
return hop.WithErrAbort(err), err.Error() return hop.WithErrAbort(err), err.Error()
} }
if err := ioutil.WriteFile(fullPath, data, 0666); err != nil { if err := os.WriteFile(fullPath, data, 0666); err != nil {
return hop.WithErrAbort(err), err.Error() return hop.WithErrAbort(err), err.Error()
} }

View File

@ -1,7 +1,6 @@
package shroom package shroom
import ( import (
"io/ioutil"
"os" "os"
"github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/cfg"
@ -13,7 +12,7 @@ func FetchTextPart(h *hyphae.Hypha) (string, error) {
if h.TextPath == "" { if h.TextPath == "" {
return "", nil return "", nil
} }
text, err := ioutil.ReadFile(h.TextPath) text, err := os.ReadFile(h.TextPath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return "", nil return "", nil
} else if err != nil { } else if err != nil {
@ -26,7 +25,7 @@ func SetHeaderLinks() {
if userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha); !userLinksHypha.Exists { if userLinksHypha := hyphae.ByName(cfg.HeaderLinksHypha); !userLinksHypha.Exists {
cfg.SetDefaultHeaderLinks() cfg.SetDefaultHeaderLinks()
} else { } else {
contents, err := ioutil.ReadFile(userLinksHypha.TextPath) contents, err := os.ReadFile(userLinksHypha.TextPath)
if err != nil || len(contents) == 0 { if err != nil || len(contents) == 0 {
cfg.SetDefaultHeaderLinks() cfg.SetDefaultHeaderLinks()
} else { } else {

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"github.com/bouncepaw/mycomarkup/mycocontext" "github.com/bouncepaw/mycomarkup/mycocontext"
"github.com/bouncepaw/mycorrhiza/cfg" "github.com/bouncepaw/mycorrhiza/cfg"
"io/ioutil"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -123,7 +122,7 @@ func handlerHypha(w http.ResponseWriter, rq *http.Request) {
u = user.FromRequest(rq) u = user.FromRequest(rq)
) )
if h.Exists { if h.Exists {
fileContentsT, errT := ioutil.ReadFile(h.TextPath) fileContentsT, errT := os.ReadFile(h.TextPath)
_, errB := os.Stat(h.BinaryPath) _, errB := os.Stat(h.BinaryPath)
if errT == nil { if errT == nil {
ctx, _ := mycocontext.ContextFromStringInput(hyphaName, string(fileContentsT)) ctx, _ := mycocontext.ContextFromStringInput(hyphaName, string(fileContentsT))