Skip to content

Commit

Permalink
maint: update file reader to os.ReadDir.
Browse files Browse the repository at this point in the history
  • Loading branch information
alfg committed Jul 27, 2022
1 parent 519f9e0 commit d58a1e2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cmd/ffmpegd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"encoding/json"
"fmt"
"io/ioutil"
"math"
"net/http"
"os"
Expand Down Expand Up @@ -191,9 +190,7 @@ func handleFiles(w http.ResponseWriter, r *http.Request) {
Files: []file{},
}

base, _ := filepath.Abs(".")
cleaned := filepath.Join(base, cleanPath(prefix))
files, _ := ioutil.ReadDir(cleaned)
files, _ := os.ReadDir(cleanPath(prefix))
for _, f := range files {
if f.IsDir() {
if prefix == "." {
Expand All @@ -208,7 +205,8 @@ func handleFiles(w http.ResponseWriter, r *http.Request) {
} else {
obj.Name = prefix + "/" + f.Name()
}
obj.Size = f.Size()
info, _ := f.Info()
obj.Size = info.Size()
resp.Files = append(resp.Files, obj)
}
}
Expand All @@ -219,7 +217,7 @@ func handleFiles(w http.ResponseWriter, r *http.Request) {
}

func cleanPath(path string) string {
// Clean path to make safe for use with filepath.Join.
// Clean path to make safe for use with filepath.Join.
if path == "" {
return ""
}
Expand Down

0 comments on commit d58a1e2

Please # to comment.