From 39ecb7aabbc2330a2428a9a9d16d2a9ba9854e13 Mon Sep 17 00:00:00 2001 From: barthr Date: Fri, 14 Jul 2023 12:41:41 +0200 Subject: [PATCH 1/2] Fix deprecations of ioutil --- src/history.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/history.go b/src/history.go index 45728d40d9f..1e66c721468 100644 --- a/src/history.go +++ b/src/history.go @@ -2,7 +2,6 @@ package fzf import ( "errors" - "io/ioutil" "os" "strings" ) @@ -26,12 +25,12 @@ func NewHistory(path string, maxSize int) (*History, error) { } // Read history file - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { // If it doesn't exist, check if we can create a file with the name if os.IsNotExist(err) { data = []byte{} - if err := ioutil.WriteFile(path, data, 0600); err != nil { + if err := os.WriteFile(path, data, 0600); err != nil { return nil, fmtError(err) } } else { @@ -62,11 +61,11 @@ func (h *History) append(line string) error { lines = lines[len(lines)-h.maxSize:] } h.lines = append(lines, "") - return ioutil.WriteFile(h.path, []byte(strings.Join(h.lines, "\n")), 0600) + return os.WriteFile(h.path, []byte(strings.Join(h.lines, "\n")), 0600) } func (h *History) override(str string) { - // You can update the history but they're not written to the file + // You can update the history, but they're not written to the file if h.cursor == len(h.lines)-1 { h.lines[h.cursor] = str } else if h.cursor < len(h.lines)-1 { From a2ad2a12c4ff0c0be9544fbfd8abc1a0aa43fa30 Mon Sep 17 00:00:00 2001 From: barthr Date: Fri, 14 Jul 2023 12:45:25 +0200 Subject: [PATCH 2/2] Fix remaining deprecations for ioutil --- src/history_test.go | 3 +-- src/options_test.go | 4 ++-- src/terminal.go | 3 +-- src/tui/ttyname_unix.go | 9 ++++++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/history_test.go b/src/history_test.go index 6294bde8219..b18f31d2e64 100644 --- a/src/history_test.go +++ b/src/history_test.go @@ -1,7 +1,6 @@ package fzf import ( - "io/ioutil" "os" "runtime" "testing" @@ -25,7 +24,7 @@ func TestHistory(t *testing.T) { } } - f, _ := ioutil.TempFile("", "fzf-history") + f, _ := os.CreateTemp("", "fzf-history") f.Close() { // Append lines diff --git a/src/options_test.go b/src/options_test.go index 4e300db7827..998733370f8 100644 --- a/src/options_test.go +++ b/src/options_test.go @@ -2,7 +2,7 @@ package fzf import ( "fmt" - "io/ioutil" + "os" "testing" "github.com/junegunn/fzf/src/tui" @@ -357,7 +357,7 @@ func TestDefaultCtrlNP(t *testing.T) { check([]string{"--bind=ctrl-n:accept"}, tui.CtrlN, actAccept) check([]string{"--bind=ctrl-p:accept"}, tui.CtrlP, actAccept) - f, _ := ioutil.TempFile("", "fzf-history") + f, _ := os.CreateTemp("", "fzf-history") f.Close() hist := "--history=" + f.Name() check([]string{hist}, tui.CtrlN, actNextHistory) diff --git a/src/terminal.go b/src/terminal.go index 5baccf4eae7..3fdb770ecb9 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -4,7 +4,6 @@ import ( "bufio" "fmt" "io" - "io/ioutil" "math" "os" "os/exec" @@ -2208,7 +2207,7 @@ func hasPreviewFlags(template string) (slot bool, plus bool, query bool) { } func writeTemporaryFile(data []string, printSep string) string { - f, err := ioutil.TempFile("", "fzf-preview-*") + f, err := os.CreateTemp("", "fzf-preview-*") if err != nil { errorExit("Unable to create temporary file") } diff --git a/src/tui/ttyname_unix.go b/src/tui/ttyname_unix.go index b5f47416aa6..bc6fe968f7d 100644 --- a/src/tui/ttyname_unix.go +++ b/src/tui/ttyname_unix.go @@ -3,7 +3,6 @@ package tui import ( - "io/ioutil" "os" "syscall" ) @@ -17,13 +16,17 @@ func ttyname() string { } for _, prefix := range devPrefixes { - files, err := ioutil.ReadDir(prefix) + files, err := os.ReadDir(prefix) if err != nil { continue } for _, file := range files { - if stat, ok := file.Sys().(*syscall.Stat_t); ok && stat.Rdev == stderr.Rdev { + info, err := file.Info() + if err != nil { + continue + } + if stat, ok := info.Sys().(*syscall.Stat_t); ok && stat.Rdev == stderr.Rdev { return prefix + file.Name() } }