Skip to content

Commit

Permalink
Merge pull request #25 from mah0x211/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
mah0x211 authored Sep 25, 2023
2 parents 33ad65f + 93154fe commit 97404a3
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 24 deletions.
4 changes: 2 additions & 2 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -82,7 +82,7 @@ func CmdFetch() {
}
defer rsp.Body.Close()

b, err := ioutil.ReadAll(rsp.Body)
b, err := io.ReadAll(rsp.Body)
if err != nil {
eprintf("failed to read body: %v", err)
}
Expand Down
13 changes: 6 additions & 7 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -123,7 +122,7 @@ func postInstallLuaJit(instdir string) error {

switch dir {
case "bin":
infos, err := ioutil.ReadDir(".")
infos, err := os.ReadDir(".")
if err != nil {
return err
}
Expand Down Expand Up @@ -158,12 +157,12 @@ func postInstallLuaJit(instdir string) error {
}

case "lib":
infos, err := ioutil.ReadDir(".")
infos, err := os.ReadDir(".")
if err != nil {
return err
}
for _, info := range infos {
if info.Mode().IsRegular() {
if info.Type().IsRegular() {
oldname := info.Name()
if ext := filepath.Ext(oldname); ext != "" {
newname := "liblua" + ext
Expand Down Expand Up @@ -283,7 +282,7 @@ func openCachedFile(url string) (io.Reader, error) {
return nil, err
} else if f != nil {
defer f.Close()
b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -324,7 +323,7 @@ func download(url string) (io.Reader, error) {
}
defer f.Close()

b, err := ioutil.ReadAll(rsp.Body)
b, err := io.ReadAll(rsp.Body)
if err != nil {
os.Remove(file)
return nil, err
Expand All @@ -351,7 +350,7 @@ func doInstall(cfg *TargetConfig, item *VerItem, opts []string) {
printf("install %q", item.Ver)

url := cfg.DownloadURL + filepath.Clean(item.Name)
tmpdir, err := ioutil.TempDir(os.TempDir(), "lenv_tmp_")
tmpdir, err := os.MkdirTemp(os.TempDir(), "lenv_tmp_")
if err != nil {
fatalf("failed to create tempdir: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -120,7 +119,7 @@ func mkdir(dirname string) error {

func createSymlink(oldname, newname string) error {
var tmpName string
if f, err := ioutil.TempFile("./", "tmp_symlink_*"); err != nil {
if f, err := os.CreateTemp("./", "tmp_symlink_*"); err != nil {
fatalf("failed to tempfile(): %v", err)
} else {
f.Close()
Expand Down
5 changes: 2 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"testing"
)
Expand Down Expand Up @@ -32,9 +31,9 @@ func (f *FakeStdout) CloseAll() {
}

func NewFakeStdout(t *testing.T) *FakeStdout {
file, err := ioutil.TempFile(".", "fakeio.*.txt")
file, err := os.CreateTemp(".", "fakeio.*.txt")
if err != nil {
t.Fatalf("failed to ioutil.TempFile(): %v", err)
t.Fatalf("failed to os.CreateTemp(): %v", err)
}

stdout := os.Stdout
Expand Down
3 changes: 1 addition & 2 deletions uninstall.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
)
Expand All @@ -23,7 +22,7 @@ func CmdUninstall(cfg *TargetConfig, opts []string) {
fatalf("%s version %q does not defined in %q", cfg.Name, ver, cfg.VersionFile)
}

infos, err := ioutil.ReadDir(cfg.RootDir)
infos, err := os.ReadDir(cfg.RootDir)
if err != nil {
fatalf("failed to readdir: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions use.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -28,7 +27,7 @@ func UseInstalledVersion(cfg *TargetConfig, ver string) {
rootdir = filepath.Clean("./" + rootdir)
}

infos, err := ioutil.ReadDir(rootdir)
infos, err := os.ReadDir(rootdir)
if err != nil {
fatalf("failed to readdir: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions vers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"regexp"
"sort"
Expand Down Expand Up @@ -169,7 +169,7 @@ func (vers *Versions) ReadFile(filename string) error {
}
defer f.Close()

b, err := ioutil.ReadAll(f)
b, err := io.ReadAll(f)
if err != nil {
return err
}
Expand Down
4 changes: 0 additions & 4 deletions vers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/rand"
"os"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -60,8 +59,6 @@ var LuaRocksVers = []string{
}

func Test_SortVersions(t *testing.T) {

rand.Seed(time.Now().UnixNano())
for _, list := range [][]string{
LuaVers, LuaJitVers, LuaRocksVers,
} {
Expand All @@ -76,7 +73,6 @@ func Test_SortVersions(t *testing.T) {
}

func Test_VerItems_Sort(t *testing.T) {
rand.Seed(time.Now().UnixNano())
for _, list := range [][]string{
LuaVers, LuaJitVers, LuaRocksVers,
} {
Expand Down

0 comments on commit 97404a3

Please sign in to comment.