mirror of
https://github.com/Jguer/yay.git
synced 2025-08-10 16:47:08 +02:00
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated in Go 1.16. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
1869bbe291
commit
e43c712c84
5
clean.go
5
clean.go
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -102,7 +101,7 @@ func cleanAUR(ctx context.Context, keepInstalled, keepCurrent, removeAll bool, d
|
|||||||
|
|
||||||
remotePackages, _ := query.GetRemotePackages(dbExecutor)
|
remotePackages, _ := query.GetRemotePackages(dbExecutor)
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(config.BuildDir)
|
files, err := os.ReadDir(config.BuildDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -167,7 +166,7 @@ func cleanAUR(ctx context.Context, keepInstalled, keepCurrent, removeAll bool, d
|
|||||||
func cleanUntracked(ctx context.Context) error {
|
func cleanUntracked(ctx context.Context) error {
|
||||||
fmt.Println(gotext.Get("removing untracked AUR files from cache..."))
|
fmt.Println(gotext.Get("removing untracked AUR files from cache..."))
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(config.BuildDir)
|
files, err := os.ReadDir(config.BuildDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
@ -75,7 +75,7 @@ func ABSPKGBUILD(httpClient httpRequestDoer, dbName, pkgName string) ([]byte, er
|
|||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
pkgBuild, err := ioutil.ReadAll(resp.Body)
|
pkgBuild, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package download
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -220,7 +219,7 @@ func TestABSPKGBUILDRepo(t *testing.T) {
|
|||||||
// THEN a pull command should be formed
|
// THEN a pull command should be formed
|
||||||
func TestABSPKGBUILDRepoExistsPerms(t *testing.T) {
|
func TestABSPKGBUILDRepoExistsPerms(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir, _ := ioutil.TempDir("/tmp/", "yay-test")
|
dir, _ := os.MkdirTemp("/tmp/", "yay-test")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(dir, "linux", ".git"), 0o777)
|
os.MkdirAll(filepath.Join(dir, "linux", ".git"), 0o777)
|
||||||
|
@ -3,7 +3,7 @@ package download
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
@ -31,7 +31,7 @@ func AURPKGBUILD(httpClient httpRequestDoer, pkgName, aurURL string) ([]byte, er
|
|||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
pkgBuild, err := ioutil.ReadAll(resp.Body)
|
pkgBuild, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package download
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
@ -99,7 +98,7 @@ func TestAURPKGBUILDRepo(t *testing.T) {
|
|||||||
// THEN a pull command should be formed
|
// THEN a pull command should be formed
|
||||||
func TestAURPKGBUILDRepoExistsPerms(t *testing.T) {
|
func TestAURPKGBUILDRepoExistsPerms(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir, _ := ioutil.TempDir("/tmp/", "yay-test")
|
dir, _ := os.MkdirTemp("/tmp/", "yay-test")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(dir, "yay-bin", ".git"), 0o777)
|
os.MkdirAll(filepath.Join(dir, "yay-bin", ".git"), 0o777)
|
||||||
@ -122,7 +121,7 @@ func TestAURPKGBUILDRepoExistsPerms(t *testing.T) {
|
|||||||
|
|
||||||
func TestAURPKGBUILDRepos(t *testing.T) {
|
func TestAURPKGBUILDRepos(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir, _ := ioutil.TempDir("/tmp/", "yay-test")
|
dir, _ := os.MkdirTemp("/tmp/", "yay-test")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(dir, "yay-bin", ".git"), 0o777)
|
os.MkdirAll(filepath.Join(dir, "yay-bin", ".git"), 0o777)
|
||||||
|
@ -2,7 +2,6 @@ package download
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -21,7 +20,7 @@ import (
|
|||||||
// THEN all should be found and cloned, except the repo one
|
// THEN all should be found and cloned, except the repo one
|
||||||
func TestPKGBUILDReposDefinedDBPull(t *testing.T) {
|
func TestPKGBUILDReposDefinedDBPull(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir, _ := ioutil.TempDir("/tmp/", "yay-test")
|
dir, _ := os.MkdirTemp("/tmp/", "yay-test")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
os.MkdirAll(filepath.Join(dir, "yay", ".git"), 0o777)
|
os.MkdirAll(filepath.Join(dir, "yay", ".git"), 0o777)
|
||||||
@ -53,7 +52,7 @@ func TestPKGBUILDReposDefinedDBPull(t *testing.T) {
|
|||||||
// THEN all should be found and cloned
|
// THEN all should be found and cloned
|
||||||
func TestPKGBUILDReposDefinedDBClone(t *testing.T) {
|
func TestPKGBUILDReposDefinedDBClone(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir, _ := ioutil.TempDir("/tmp/", "yay-test")
|
dir, _ := os.MkdirTemp("/tmp/", "yay-test")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
targets := []string{"core/yay", "yay-bin", "yay-git"}
|
targets := []string{"core/yay", "yay-bin", "yay-git"}
|
||||||
@ -83,7 +82,7 @@ func TestPKGBUILDReposDefinedDBClone(t *testing.T) {
|
|||||||
// THEN all should be found and cloned
|
// THEN all should be found and cloned
|
||||||
func TestPKGBUILDReposClone(t *testing.T) {
|
func TestPKGBUILDReposClone(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir, _ := ioutil.TempDir("/tmp/", "yay-test")
|
dir, _ := os.MkdirTemp("/tmp/", "yay-test")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
targets := []string{"yay", "yay-bin", "yay-git"}
|
targets := []string{"yay", "yay-bin", "yay-git"}
|
||||||
@ -113,7 +112,7 @@ func TestPKGBUILDReposClone(t *testing.T) {
|
|||||||
// THEN all aur be found and cloned
|
// THEN all aur be found and cloned
|
||||||
func TestPKGBUILDReposNotFound(t *testing.T) {
|
func TestPKGBUILDReposNotFound(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir, _ := ioutil.TempDir("/tmp/", "yay-test")
|
dir, _ := os.MkdirTemp("/tmp/", "yay-test")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
targets := []string{"extra/yay", "yay-bin", "yay-git"}
|
targets := []string{"extra/yay", "yay-bin", "yay-git"}
|
||||||
@ -143,7 +142,7 @@ func TestPKGBUILDReposNotFound(t *testing.T) {
|
|||||||
// THEN only repo should be cloned
|
// THEN only repo should be cloned
|
||||||
func TestPKGBUILDReposRepoMode(t *testing.T) {
|
func TestPKGBUILDReposRepoMode(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
dir, _ := ioutil.TempDir("/tmp/", "yay-test")
|
dir, _ := os.MkdirTemp("/tmp/", "yay-test")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
targets := []string{"yay", "yay-bin", "yay-git"}
|
targets := []string{"yay", "yay-bin", "yay-git"}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -74,7 +74,7 @@ func PrintNewsFeed(ctx context.Context, client *http.Client, cutOffDate time.Tim
|
|||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package news
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@ -119,7 +119,7 @@ func TestPrintNewsFeed(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
w.Close()
|
w.Close()
|
||||||
out, _ := ioutil.ReadAll(r)
|
out, _ := io.ReadAll(r)
|
||||||
cupaloy.SnapshotT(t, out)
|
cupaloy.SnapshotT(t, out)
|
||||||
os.Stdout = rescueStdout
|
os.Stdout = rescueStdout
|
||||||
})
|
})
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -48,7 +48,7 @@ func newPkg(basename string) *aur.Pkg {
|
|||||||
func getPgpKey(key string) string {
|
func getPgpKey(key string) string {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
|
||||||
if contents, err := ioutil.ReadFile(path.Join("testdata", key)); err == nil {
|
if contents, err := os.ReadFile(path.Join("testdata", key)); err == nil {
|
||||||
buffer.WriteString("-----BEGIN PGP PUBLIC KEY BLOCK-----\n")
|
buffer.WriteString("-----BEGIN PGP PUBLIC KEY BLOCK-----\n")
|
||||||
buffer.WriteString("Version: SKS 1.1.6\n")
|
buffer.WriteString("Version: SKS 1.1.6\n")
|
||||||
buffer.WriteString("Comment: Hostname: yay\n\n")
|
buffer.WriteString("Comment: Hostname: yay\n\n")
|
||||||
@ -71,7 +71,7 @@ func startPgpKeyServer() *http.Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestImportKeys(t *testing.T) {
|
func TestImportKeys(t *testing.T) {
|
||||||
keyringDir, err := ioutil.TempDir("/tmp", "yay-test-keyring")
|
keyringDir, err := os.MkdirTemp("/tmp", "yay-test-keyring")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to init test keyring %q: %v\n", keyringDir, err)
|
t.Fatalf("Unable to init test keyring %q: %v\n", keyringDir, err)
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ func makeSrcinfo(pkgbase string, pgpkeys ...string) *gosrc.Srcinfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckPgpKeys(t *testing.T) {
|
func TestCheckPgpKeys(t *testing.T) {
|
||||||
keyringDir, err := ioutil.TempDir("/tmp", "yay-test-keyring")
|
keyringDir, err := os.MkdirTemp("/tmp", "yay-test-keyring")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to init test keyring: %v\n", err)
|
t.Fatalf("Unable to init test keyring: %v\n", err)
|
||||||
}
|
}
|
||||||
@ -255,7 +255,7 @@ func TestCheckPgpKeys(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w.Close()
|
w.Close()
|
||||||
out, _ := ioutil.ReadAll(r)
|
out, _ := io.ReadAll(r)
|
||||||
os.Stdout = rescueStdout
|
os.Stdout = rescueStdout
|
||||||
|
|
||||||
splitLines := strings.Split(string(out), "\n")
|
splitLines := strings.Split(string(out), "\n")
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
"sync"
|
||||||
@ -262,7 +261,7 @@ func TestInfoStore_Update(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := ioutil.TempFile("/tmp", "yay-vcs-test")
|
file, err := os.CreateTemp("/tmp", "yay-vcs-test")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer os.Remove(file.Name())
|
defer os.Remove(file.Name())
|
||||||
|
|
||||||
@ -326,7 +325,7 @@ func TestInfoStore_Remove(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := ioutil.TempFile("/tmp", "yay-vcs-test")
|
file, err := os.CreateTemp("/tmp", "yay-vcs-test")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
defer os.Remove(file.Name())
|
defer os.Remove(file.Name())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user