diff --git a/cmd/psc/root.go b/cmd/psc/root.go index 5333f0c..7f86dad 100644 --- a/cmd/psc/root.go +++ b/cmd/psc/root.go @@ -1,7 +1,7 @@ package main import ( - "io/ioutil" + "io" "log" "github.com/spf13/cobra" @@ -26,7 +26,7 @@ func init() { func preRoot(cmd *cobra.Command, args []string) { if !rootFlags.debug { log.SetFlags(0) - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) } else { log.SetFlags(log.LstdFlags | log.Lshortfile) } diff --git a/internal/db/db_test.go b/internal/db/db_test.go index 9d82bda..4d664a1 100644 --- a/internal/db/db_test.go +++ b/internal/db/db_test.go @@ -1,7 +1,6 @@ package db import ( - "io/ioutil" "os" "path/filepath" "reflect" @@ -32,7 +31,7 @@ func addAll(db *Session, infos []FileInfo) error { } func TestVersionOk(t *testing.T) { - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -50,7 +49,7 @@ func TestVersionOk(t *testing.T) { } func TestVersionMismatch(t *testing.T) { - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } diff --git a/internal/periscope/ls_test.go b/internal/periscope/ls_test.go index dff9480..d86d859 100644 --- a/internal/periscope/ls_test.go +++ b/internal/periscope/ls_test.go @@ -3,7 +3,6 @@ package periscope import ( "github.com/anishathalye/periscope/internal/testfs" - "io/ioutil" "os" "path/filepath" "strings" @@ -237,8 +236,8 @@ func TestLsSpecialModes(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) os.Symlink(filepath.Join(dir, "x"), filepath.Join(dir, "z")) ps, out, _ := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) @@ -499,8 +498,8 @@ func TestLsRejectSymlink(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) os.Symlink(dir, filepath.Join(dir, "rec")) ps, out, stderr := newTest(fs) err := ps.Ls([]string{filepath.Join(dir, "rec")}, &LsOptions{}) @@ -630,11 +629,11 @@ func TestLsRelative(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) os.Mkdir(filepath.Join(dir, "d"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) ps, out, _ := newTest(fs) oldWd, err := os.Getwd() if err != nil { @@ -665,11 +664,11 @@ func TestLsRelativeRecursive(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) os.Mkdir(filepath.Join(dir, "d"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) ps, out, _ := newTest(fs) oldWd, err := os.Getwd() if err != nil { @@ -699,11 +698,11 @@ func TestLsRelativeDir(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) os.Mkdir(filepath.Join(dir, "d"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) ps, out, _ := newTest(fs) oldWd, err := os.Getwd() if err != nil { diff --git a/internal/periscope/periscope.go b/internal/periscope/periscope.go index 716e0e3..50a0cbd 100644 --- a/internal/periscope/periscope.go +++ b/internal/periscope/periscope.go @@ -8,7 +8,6 @@ import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "time" @@ -83,7 +82,7 @@ func (ps *Periscope) progressBar(total int, template string) *pb.ProgressBar { if w, ok := ps.errStream.(*os.File); ok && term.IsTerminal(int(w.Fd())) { bar.SetWriter(ps.errStream) } else { - bar.SetWriter(ioutil.Discard) + bar.SetWriter(io.Discard) } return bar } diff --git a/internal/periscope/periscope_test.go b/internal/periscope/periscope_test.go index eb64106..d15e3e2 100644 --- a/internal/periscope/periscope_test.go +++ b/internal/periscope/periscope_test.go @@ -4,8 +4,9 @@ import ( "github.com/anishathalye/periscope/internal/db" "bytes" - "io/ioutil" + "io" "log" + "os" "path/filepath" "testing" @@ -17,7 +18,7 @@ func newTest(fs afero.Fs) (*Periscope, *bytes.Buffer, *bytes.Buffer) { log.SetFlags(log.LstdFlags | log.Lshortfile) } else { log.SetFlags(0) - log.SetOutput(ioutil.Discard) + log.SetOutput(io.Discard) } db, err := db.NewInMemory() if err != nil { @@ -50,7 +51,7 @@ func checkErr(t *testing.T, err error) { } func tempDir() string { - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { panic(err) } diff --git a/internal/periscope/refresh_test.go b/internal/periscope/refresh_test.go index e7ffa92..e4464f1 100644 --- a/internal/periscope/refresh_test.go +++ b/internal/periscope/refresh_test.go @@ -5,7 +5,6 @@ import ( "github.com/anishathalye/periscope/internal/testfs" "bytes" - "io/ioutil" "os" "path/filepath" "testing" @@ -172,10 +171,10 @@ func TestRefreshPermissionError(t *testing.T) { defer os.RemoveAll(dir) os.Mkdir(filepath.Join(dir, "d1"), 0o755) os.Mkdir(filepath.Join(dir, "d2"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d1", "w"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d1", "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d2", "y"), []byte{'b'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d2", "z"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d1", "w"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d1", "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d2", "y"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d2", "z"), []byte{'b'}, 0o644) ps, _, _ := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) os.Chmod(filepath.Join(dir, "d1"), 0o000) @@ -192,10 +191,10 @@ func TestRefreshNonRegularFile(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "w"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'b'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "z"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "w"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "z"), []byte{'b'}, 0o644) ps, _, _ := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) os.Remove(filepath.Join(dir, "w")) @@ -215,8 +214,8 @@ func TestRefreshSymlinkDir(t *testing.T) { defer os.RemoveAll(dir) os.Mkdir(filepath.Join(dir, "d"), 0o755) os.Mkdir(filepath.Join(dir, "d2"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d", "x"), []byte{'b'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d2", "y"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "x"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d2", "y"), []byte{'b'}, 0o644) ps, _, _ := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) os.RemoveAll(filepath.Join(dir, "d2")) diff --git a/internal/periscope/report_test.go b/internal/periscope/report_test.go index 517a1f2..7b737af 100644 --- a/internal/periscope/report_test.go +++ b/internal/periscope/report_test.go @@ -3,7 +3,6 @@ package periscope import ( "github.com/anishathalye/periscope/internal/testfs" - "io/ioutil" "os" "path/filepath" "strings" @@ -91,11 +90,11 @@ func TestReportRelative(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a', 'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a', 'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a', 'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a', 'a'}, 0o644) os.Mkdir(filepath.Join(dir, "d"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) ps, out, _ := newTest(fs) oldWd, err := os.Getwd() if err != nil { @@ -125,11 +124,11 @@ func TestReportRelativeArgument(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a', 'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a', 'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a', 'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a', 'a'}, 0o644) os.Mkdir(filepath.Join(dir, "d"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "a"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "b"), []byte{'b'}, 0o644) ps, out, _ := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) err := ps.Report(filepath.Join(dir, "d"), &ReportOptions{Relative: true}) diff --git a/internal/periscope/rm_test.go b/internal/periscope/rm_test.go index fbba956..1717259 100644 --- a/internal/periscope/rm_test.go +++ b/internal/periscope/rm_test.go @@ -5,7 +5,6 @@ import ( "github.com/anishathalye/periscope/internal/testfs" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -470,8 +469,8 @@ func TestRmNoSymlinks(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) os.Symlink(dir, filepath.Join(dir, "rec")) ps, out, stderr := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) @@ -492,8 +491,8 @@ func TestRmReplacedBySymlink(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) ps, out, stderr := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) os.Remove(filepath.Join(dir, "y")) @@ -556,8 +555,8 @@ func TestRmLostPermission(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) ps, out, stderr := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) os.Chmod(filepath.Join(dir, "y"), 0o000) @@ -592,9 +591,9 @@ func TestRmPartialPermission(t *testing.T) { dir := tempDir() defer os.RemoveAll(dir) os.Mkdir(filepath.Join(dir, "d"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d", "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d", "y"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "z"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d", "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "z"), []byte{'a'}, 0o644) ps, _, _ := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) os.Chmod(filepath.Join(dir, "d", "y"), 0o000) @@ -707,7 +706,7 @@ func TestRmHardLink(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) os.Link(filepath.Join(dir, "x"), filepath.Join(dir, "y")) ps, out, stderr := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) diff --git a/internal/periscope/scan_test.go b/internal/periscope/scan_test.go index 42f5c4a..ae17d9f 100644 --- a/internal/periscope/scan_test.go +++ b/internal/periscope/scan_test.go @@ -5,7 +5,6 @@ import ( "github.com/anishathalye/periscope/internal/testfs" "bytes" - "io/ioutil" "os" "path/filepath" "testing" @@ -164,10 +163,10 @@ func TestScanNoAccess(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "w"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o000) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'b'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "z"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "w"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o000) + os.WriteFile(filepath.Join(dir, "y"), []byte{'b'}, 0o644) + os.WriteFile(filepath.Join(dir, "z"), []byte{'b'}, 0o644) fs.Mkdir(filepath.Join(dir, "d"), 0o644) fs.Mkdir(filepath.Join(dir, "e"), 0o000) ps, _, _ := newTest(fs) @@ -345,8 +344,8 @@ func TestScanNoReadSymlinks(t *testing.T) { fs := afero.NewOsFs() dir := tempDir() defer os.RemoveAll(dir) - ioutil.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "y"), []byte{'a'}, 0o644) os.Symlink(filepath.Join(dir, "x"), filepath.Join(dir, "z")) ps, _, _ := newTest(fs) err := ps.Scan([]string{dir}, &ScanOptions{}) @@ -364,8 +363,8 @@ func TestScanNoDescendSymlinks(t *testing.T) { dir := tempDir() defer os.RemoveAll(dir) os.Mkdir(filepath.Join(dir, "d1"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d1", "w"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d1", "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d1", "w"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d1", "x"), []byte{'a'}, 0o644) os.Symlink(filepath.Join(dir, "d1"), filepath.Join(dir, "d2")) ps, _, _ := newTest(fs) ps.Scan([]string{dir}, &ScanOptions{}) @@ -382,8 +381,8 @@ func TestScanSymlink(t *testing.T) { dir := tempDir() defer os.RemoveAll(dir) os.Mkdir(filepath.Join(dir, "d1"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d1", "w"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d1", "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d1", "w"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d1", "x"), []byte{'a'}, 0o644) os.Symlink(filepath.Join(dir, "d1"), filepath.Join(dir, "d2")) ps, _, _ := newTest(fs) err := ps.Scan([]string{filepath.Join(dir, "d2")}, &ScanOptions{}) @@ -396,8 +395,8 @@ func TestScanInsideSymlink(t *testing.T) { defer os.RemoveAll(dir) os.Mkdir(filepath.Join(dir, "d1"), 0o755) os.Mkdir(filepath.Join(dir, "d1", "d2"), 0o755) - ioutil.WriteFile(filepath.Join(dir, "d1", "d2", "w"), []byte{'a'}, 0o644) - ioutil.WriteFile(filepath.Join(dir, "d1", "d2", "x"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d1", "d2", "w"), []byte{'a'}, 0o644) + os.WriteFile(filepath.Join(dir, "d1", "d2", "x"), []byte{'a'}, 0o644) os.Symlink(filepath.Join(dir, "d1"), filepath.Join(dir, "d3")) ps, _, _ := newTest(fs) err := ps.Scan([]string{filepath.Join(dir, "d2")}, &ScanOptions{})