Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove refs to deprecated io/ioutil #427

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions boot/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
log "github.com/sirupsen/logrus"
"github.com/unrolled/secure"
"html/template"
"io/ioutil"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -254,7 +253,7 @@ func Templates(fs embed.FS, config BootConfig) *template.Template {
data := string(dataBuf)
tmpFilePath := filepath.Join(util.ExeFilePath(config.Ui), tmpFile)
if util.FileExist(tmpFilePath) {
s, _ := ioutil.ReadFile(tmpFilePath)
s, _ := os.ReadFile(tmpFilePath)
data = string(s)
}
tmpl.New(tmpFile).Funcs(template.FuncMap{
Expand All @@ -275,7 +274,7 @@ func Templates(fs embed.FS, config BootConfig) *template.Template {
data := string(dataBuf)
tmpNamePath := filepath.Join(util.ExeFilePath(config.Ui), tmpName)
if util.FileExist(tmpNamePath) {
s, _ := ioutil.ReadFile(tmpNamePath)
s, _ := os.ReadFile(tmpNamePath)
data = string(s)
}
tmpl.New(tmpName).Funcs(template.FuncMap{
Expand All @@ -297,7 +296,7 @@ func addTemplatesFromFolder(folder string, tmpl *template.Template, fs embed.FS,
data := string(dataBuf)
tmpNamePath := filepath.Join(util.ExeFilePath(config.Ui), tmpName)
if util.FileExist(tmpNamePath) {
s, _ := ioutil.ReadFile(tmpNamePath)
s, _ := os.ReadFile(tmpNamePath)
data = string(s)
}
tmpl.New(tmpName).Funcs(template.FuncMap{
Expand Down
4 changes: 2 additions & 2 deletions control/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/px-org/PanIndex/service"
"github.com/px-org/PanIndex/util"
log "github.com/sirupsen/logrus"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -275,7 +275,7 @@ func UploadPwdFile(c *gin.Context) {
log.Error(err)
msg = "导入失败"
}
s, err := ioutil.ReadAll(f)
s, err := io.ReadAll(f)
if err != nil {
log.Error(err)
msg = "读取失败"
Expand Down
4 changes: 2 additions & 2 deletions control/webdav/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/px-org/PanIndex/util"
log "github.com/sirupsen/logrus"
"golang.org/x/net/context"
"io/ioutil"
"io"
"net/http"
"path"
"path/filepath"
Expand Down Expand Up @@ -92,7 +92,7 @@ func (fs *FileSystem) Delete(account module.Account, path, fullPath string) erro

func (fs *FileSystem) Upload(account module.Account, req *http.Request, path, fullPath, fileId string, overwrite bool) error {
_, fileName := util.ParsePath(path)
content, err := ioutil.ReadAll(req.Body)
content, err := io.ReadAll(req.Body)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions control/webdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
log "github.com/sirupsen/logrus"
"golang.org/x/net/context"
"io"
"io/ioutil"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -551,7 +550,7 @@ func (h *Handler) handleUnlock(w http.ResponseWriter, r *http.Request) (status i

func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status int, err error) {
if r.ContentLength > 0 {
space, _ := ioutil.ReadAll(r.Body)
space, _ := io.ReadAll(r.Body)
if strings.Contains(string(space), "quota-available-bytes") {
total, used := h.FileSystem.GetSpace(h.Account, h.FullPath)
w.Write([]byte(`<?xml version="1.0" encoding="utf-8"?>
Expand Down
4 changes: 2 additions & 2 deletions pan/ftp/FTP.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/px-org/PanIndex/util"
uuid "github.com/satori/go.uuid"
log "github.com/sirupsen/logrus"
"io/ioutil"
"io"
"path"
"strconv"
"time"
Expand Down Expand Up @@ -188,7 +188,7 @@ func (F FTP) Move(account module.Account, fileId, targetFileId string, overwrite
if err == nil {
r, er := c.Retr(fileId)
fileName := util.GetFileName(fileId)
content, _ := ioutil.ReadAll(r)
content, _ := io.ReadAll(r)
r.Close()
er = c.Stor(path.Join(targetFileId, fileName), bytes.NewReader(content))
if er == nil {
Expand Down
21 changes: 13 additions & 8 deletions pan/native/Native.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/shirou/gopsutil/v3/disk"
log "github.com/sirupsen/logrus"
"io"
"io/ioutil"
"io/fs"
"os"
"path"
"path/filepath"
Expand All @@ -33,24 +33,29 @@ func (n Native) AuthLogin(account *module.Account) (string, error) {
func (n Native) Files(account module.Account, fileId, path, sortColumn, sortOrder string) ([]module.FileNode, error) {
fns := []module.FileNode{}
if util.FileExist(fileId) && IsDirectory(fileId) {
fileInfos, err := ioutil.ReadDir(fileId)
fileInfos, err := os.ReadDir(fileId)
if err != nil {
log.Error(err)
return fns, err
} else {
for _, fileInfo := range fileInfos {
info, err := fileInfo.Info()
if err != nil {
log.Error(err)
return fns, err
}
file := module.FileNode{
Id: uuid.NewV4().String(),
AccountId: account.Id,
FileId: filepath.Join(fileId, fileInfo.Name()),
IsFolder: fileInfo.IsDir(),
FileName: fileInfo.Name(),
FileSize: fileInfo.Size(),
SizeFmt: util.FormatFileSize(fileInfo.Size()),
FileSize: info.Size(),
SizeFmt: util.FormatFileSize(info.Size()),
FileType: util.GetExt(fileInfo.Name()),
Path: PathJoin(path, fileInfo.Name()),
ViewType: util.GetViewType(util.GetExt(fileInfo.Name())),
LastOpTime: time.Unix(fileInfo.ModTime().Unix(), 0).Format("2006-01-02 15:04:05"),
LastOpTime: time.Unix(info.ModTime().Unix(), 0).Format("2006-01-02 15:04:05"),
ParentId: fileId,
ParentPath: path,
IsDelete: 1,
Expand Down Expand Up @@ -94,7 +99,7 @@ func (n Native) UploadFiles(account module.Account, parentFileId string, files [
t1 := time.Now()
log.Debugf("Upload started:%s,Size:%d", file.FileName, file.FileSize)
fileName := filepath.Join(parentFileId, file.FileName)
err := ioutil.WriteFile(fileName, file.Content, 0644)
err := os.WriteFile(fileName, file.Content, 0644)
if err != nil {
log.Error(err)
} else {
Expand Down Expand Up @@ -217,7 +222,7 @@ func FileCopy(src, dst string) error {
// Dir copies a whole directory recursively
func DirCopy(src string, dst string) error {
var err error
var fds []os.FileInfo
var fds []fs.DirEntry
var srcinfo os.FileInfo

if srcinfo, err = os.Stat(src); err != nil {
Expand All @@ -228,7 +233,7 @@ func DirCopy(src string, dst string) error {
return err
}

if fds, err = ioutil.ReadDir(src); err != nil {
if fds, err = os.ReadDir(src); err != nil {
return err
}
for _, fd := range fds {
Expand Down
6 changes: 3 additions & 3 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/skip2/go-qrcode"
"gorm.io/gorm"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -352,7 +352,7 @@ func Upload(accountId, p string, c *gin.Context) string {
fileInfos := []*module.UploadInfo{}
for _, file := range files {
fileContent, _ := file.Open()
byteContent, _ := ioutil.ReadAll(fileContent)
byteContent, _ := io.ReadAll(fileContent)
fileInfos = append(fileInfos, &module.UploadInfo{
FileName: file.Filename,
FileSize: file.Size,
Expand Down Expand Up @@ -436,7 +436,7 @@ func GetFileData(account module.Account, downUrl, r string) ([]byte, string, int
log.Errorln(err)
}
defer resp.Body.Close()
data, _ := ioutil.ReadAll(resp.Body)
data, _ := io.ReadAll(resp.Body)
mtype := mimetype.Detect(data)
return data, mtype.String(), resp.StatusCode
}
Expand Down