Skip to content

Commit

Permalink
gopls: update uses of deprecated ioutil APIs
Browse files Browse the repository at this point in the history
Change-Id: I35acdc8a1e8e558f905fd6879b3ac8332e7c2325
Reviewed-on: https://go-review.googlesource.com/c/tools/+/524836
Reviewed-by: Alan Donovan <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: qiulaidongfeng <[email protected]>
Run-TryBot: Robert Findley <[email protected]>
  • Loading branch information
findleyr committed Sep 1, 2023
1 parent 914b218 commit 1bfa8e3
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 19 deletions.
3 changes: 1 addition & 2 deletions gopls/internal/lsp/cache/mod_tidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"go/ast"
"go/token"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -118,7 +117,7 @@ func modTidyImpl(ctx context.Context, snapshot *snapshot, filename string, pm *s

// Go directly to disk to get the temporary mod file,
// since it is always on disk.
tempContents, err := ioutil.ReadFile(tmpURI.Filename())
tempContents, err := os.ReadFile(tmpURI.Filename())
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions gopls/internal/lsp/cache/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"go/token"
"go/types"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -456,11 +455,11 @@ func (s *snapshot) RunGoCommands(ctx context.Context, allowNetwork bool, wd stri
return false, nil, nil, nil
}
var modBytes, sumBytes []byte
modBytes, err = ioutil.ReadFile(tmpURI.Filename())
modBytes, err = os.ReadFile(tmpURI.Filename())
if err != nil && !os.IsNotExist(err) {
return false, nil, nil, err
}
sumBytes, err = ioutil.ReadFile(strings.TrimSuffix(tmpURI.Filename(), ".mod") + ".sum")
sumBytes, err = os.ReadFile(strings.TrimSuffix(tmpURI.Filename(), ".mod") + ".sum")
if err != nil && !os.IsNotExist(err) {
return false, nil, nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions gopls/internal/lsp/cache/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -351,7 +350,7 @@ func (v *View) ID() string { return v.id }
// longer needed.
func tempModFile(modFh source.FileHandle, gosum []byte) (tmpURI span.URI, cleanup func(), err error) {
filenameHash := source.Hashf("%s", modFh.URI().Filename())
tmpMod, err := ioutil.TempFile("", fmt.Sprintf("go.%s.*.mod", filenameHash))
tmpMod, err := os.CreateTemp("", fmt.Sprintf("go.%s.*.mod", filenameHash))
if err != nil {
return "", nil, err
}
Expand Down Expand Up @@ -386,7 +385,7 @@ func tempModFile(modFh source.FileHandle, gosum []byte) (tmpURI span.URI, cleanu

// Create an analogous go.sum, if one exists.
if gosum != nil {
if err := ioutil.WriteFile(tmpSumName, gosum, 0655); err != nil {
if err := os.WriteFile(tmpSumName, gosum, 0655); err != nil {
return "", nil, err
}
}
Expand Down
8 changes: 2 additions & 6 deletions gopls/internal/lsp/cache/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cache
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -20,17 +19,14 @@ import (
)

func TestCaseInsensitiveFilesystem(t *testing.T) {
base, err := ioutil.TempDir("", t.Name())
if err != nil {
t.Fatal(err)
}
base := t.TempDir()

inner := filepath.Join(base, "a/B/c/DEFgh")
if err := os.MkdirAll(inner, 0777); err != nil {
t.Fatal(err)
}
file := filepath.Join(inner, "f.go")
if err := ioutil.WriteFile(file, []byte("hi"), 0777); err != nil {
if err := os.WriteFile(file, []byte("hi"), 0777); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(filepath.Join(inner, "F.go")); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions gopls/internal/lsp/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -629,7 +628,7 @@ func collectFileEdits(ctx context.Context, snapshot source.Snapshot, uri span.UR
// file and leave it unsaved. We would rather apply the changes directly,
// especially to go.sum, which should be mostly invisible to the user.
if !snapshot.IsOpen(uri) {
err := ioutil.WriteFile(uri.Filename(), newContent, 0666)
err := os.WriteFile(uri.Filename(), newContent, 0666)
return nil, err
}

Expand Down
5 changes: 2 additions & 3 deletions gopls/internal/lsp/source/gc_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -45,7 +44,7 @@ func GCOptimizationDetails(ctx context.Context, snapshot Snapshot, m *Metadata)
if err := os.MkdirAll(outDir, 0700); err != nil {
return nil, err
}
tmpFile, err := ioutil.TempFile(os.TempDir(), "gopls-x")
tmpFile, err := os.CreateTemp(os.TempDir(), "gopls-x")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -99,7 +98,7 @@ func GCOptimizationDetails(ctx context.Context, snapshot Snapshot, m *Metadata)
}

func parseDetailsFile(filename string, options *Options) (span.URI, []*Diagnostic, error) {
buf, err := ioutil.ReadFile(filename)
buf, err := os.ReadFile(filename)
if err != nil {
return "", nil, err
}
Expand Down

0 comments on commit 1bfa8e3

Please sign in to comment.