Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ linters-settings:
packages-with-error-message:
- errors: 'Use github.com/cockroachdb/errors instead'
- github.com/pkg/errors: 'Use github.com/cockroachdb/errors instead'
- ioutil: 'The ioutil package has been deprecated'
- io/ioutil: 'The ioutil package has been deprecated'
gocritic:
disabled-checks:
- appendAssign # Too many false positives
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -68,7 +68,7 @@ Examples:
if isatty.IsTerminal(os.Stdin.Fd()) {
return cmderrors.Usage("expected query to be piped into 'src api' or -query flag to be specified")
}
data, err := ioutil.ReadAll(os.Stdin)
data, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/src/batch_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -374,7 +373,7 @@ func parseBatchSpec(file *string, svc *service.Service) (*batcheslib.BatchSpec,
}
defer f.Close()

data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
return nil, "", errors.Wrap(err, "reading batch spec")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/config_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/sourcegraph/src-cli/internal/api"
"github.com/sourcegraph/src-cli/internal/cmderrors"
Expand Down Expand Up @@ -71,7 +71,7 @@ Examples:
if *valueFlag != "" {
value = *valueFlag
} else if *valueFileFlag != "" {
data, err := ioutil.ReadFile(*valueFileFlag)
data, err := os.ReadFile(*valueFileFlag)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/extensions_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"flag"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -106,7 +106,7 @@ Copy an extension from Sourcegraph.com to your private registry.
return err
}
defer response.Body.Close()
bundle, err := ioutil.ReadAll(response.Body)
bundle, err := io.ReadAll(response.Body)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/src/extensions_publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -67,7 +66,7 @@ Notes:
}
manifestDir := filepath.Dir(manifestPath)

manifest, err := ioutil.ReadFile(manifestPath)
manifest, err := os.ReadFile(manifestPath)
if err != nil {
return fmt.Errorf("%s\n\nRun this command in a directory with a %s file for an extension.\n\nSee 'src extensions %s -h' for help", err, *manifestFlag, flagSet.Name())
}
Expand Down Expand Up @@ -256,7 +255,7 @@ func addReadmeToManifest(manifest []byte, dir string) ([]byte, error) {
var readme string
filenames := []string{"README.md", "README.txt", "README", "readme.md", "readme.txt", "readme", "Readme.md", "Readme.txt", "Readme"}
for _, f := range filenames {
data, err := ioutil.ReadFile(filepath.Join(dir, f))
data, err := os.ReadFile(filepath.Join(dir, f))
if err != nil {
continue
}
Expand Down Expand Up @@ -292,7 +291,7 @@ func readExtensionArtifacts(manifest []byte, dir string) (bundle, sourceMap *str

mainPath := filepath.Join(dir, o.Main)

data, err := ioutil.ReadFile(mainPath)
data, err := os.ReadFile(mainPath)
if err != nil {
return nil, nil, fmt.Errorf(`extension manifest "main" bundle file: %s`, err)
}
Expand All @@ -303,7 +302,7 @@ func readExtensionArtifacts(manifest []byte, dir string) (bundle, sourceMap *str

// Guess that source map is the main file with a ".map" extension.
sourceMapPath := strings.TrimSuffix(mainPath, filepath.Ext(mainPath)) + ".map"
data, err = ioutil.ReadFile(sourceMapPath)
data, err = os.ReadFile(sourceMapPath)
if err == nil {
tmp := string(data)
sourceMap = &tmp
Expand Down
6 changes: 3 additions & 3 deletions cmd/src/extsvc_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"os"
"strings"

Expand Down Expand Up @@ -73,14 +73,14 @@ Examples:
// Determine if we are updating the JSON configuration or not.
var updateJSON []byte
if len(flagSet.Args()) == 1 {
updateJSON, err = ioutil.ReadFile(flagSet.Arg(0))
updateJSON, err = os.ReadFile(flagSet.Arg(0))
if err != nil {
return err
}
}
if !isatty.IsTerminal(os.Stdin.Fd()) {
// stdin is a pipe not a terminal
updateJSON, err = ioutil.ReadAll(os.Stdin)
updateJSON, err = io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/src/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -53,7 +52,7 @@ Examples:
return cmderrors.Usage("expected exactly one argument: the Sourcegraph URL, or SRC_ENDPOINT to be set")
}

client := cfg.apiClient(apiFlags, ioutil.Discard)
client := cfg.apiClient(apiFlags, io.Discard)

return loginCmd(context.Background(), cfg, client, endpoint, os.Stdout)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
Expand All @@ -18,7 +18,7 @@ func TestLogin(t *testing.T) {
t.Helper()

var out bytes.Buffer
err = loginCmd(context.Background(), cfg, cfg.apiClient(nil, ioutil.Discard), endpointArg, &out)
err = loginCmd(context.Background(), cfg, cfg.apiClient(nil, io.Discard), endpointArg, &out)
return strings.TrimSpace(out.String()), err
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"flag"
"io"
"io/ioutil"
"log"
"os"
"os/user"
Expand Down Expand Up @@ -114,7 +113,7 @@ func readConfig() (*config, error) {
} else if strings.HasPrefix(cfgPath, "~/") {
cfgPath = filepath.Join(homeDir, cfgPath[2:])
}
data, err := ioutil.ReadFile(os.ExpandEnv(cfgPath))
data, err := os.ReadFile(os.ExpandEnv(cfgPath))
if err != nil && (!os.IsNotExist(err) || userSpecified) {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/src/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -154,7 +153,7 @@ func TestReadConfig(t *testing.T) {
setEnv("SRC_ACCESS_TOKEN", test.envToken)
setEnv("SRC_ENDPOINT", test.envEndpoint)

tmpDir, err := ioutil.TempDir("", "")
tmpDir, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand All @@ -176,7 +175,7 @@ func TestReadConfig(t *testing.T) {
t.Fatal(err)
}
filePath := filepath.Join(tmpDir, "config.json")
err = ioutil.WriteFile(filePath, data, 0600)
err = os.WriteFile(filePath, data, 0600)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/src/search_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"flag"
"io/ioutil"
"io"
"net"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -147,11 +147,11 @@ func TestSearchStream(t *testing.T) {
if err != nil {
t.Fatal(err)
}
got, err := ioutil.ReadAll(r)
got, err := io.ReadAll(r)
if err != nil {
t.Fatal(err)
}
want, err := ioutil.ReadFile(c.want)
want, err := os.ReadFile(c.want)
if err != nil {
t.Fatal(err)
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/src/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -29,7 +28,7 @@ func TestSearchOutput(t *testing.T) {
tests := map[string]*testT{}

dataDir := "testdata/search_formatting"
infos, err := ioutil.ReadDir(dataDir)
infos, err := os.ReadDir(dataDir)
if err != nil {
t.Fatal(err)
}
Expand All @@ -50,7 +49,7 @@ func TestSearchOutput(t *testing.T) {
tests[testName] = &testT{}
}

data, err := ioutil.ReadFile(path)
data, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
Expand All @@ -74,7 +73,7 @@ func TestSearchOutput(t *testing.T) {
if tst.want == nil {
// Create the initial (empty) .want.txt file.
wantFile := filepath.Join(dataDir, testName+".want.txt")
if err := ioutil.WriteFile(wantFile, nil, 0600); err != nil {
if err := os.WriteFile(wantFile, nil, 0600); err != nil {
t.Fatal(err)
}
tmp := ""
Expand All @@ -100,7 +99,7 @@ func TestSearchOutput(t *testing.T) {
gotFile := filepath.Join(dataDir, testName+".got.txt")
wantFile := filepath.Join(dataDir, testName+".want.txt")

err := ioutil.WriteFile(gotFile, []byte(got), 0600)
err := os.WriteFile(gotFile, []byte(got), 0600)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/servegit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"io"
"log"
"os"

Expand Down Expand Up @@ -53,7 +53,7 @@ Documentation at https://docs.sourcegraph.com/admin/external_service/src_serve_g
return cmderrors.Usage("requires zero or one arguments")
}

dbug := log.New(ioutil.Discard, "", log.LstdFlags)
dbug := log.New(io.Discard, "", log.LstdFlags)
if *verbose {
dbug = log.New(os.Stderr, "DBUG serve-git: ", log.LstdFlags)
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/src/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -92,7 +92,7 @@ Please visit https://docs.sourcegraph.com/admin/validation for documentation of
var err error
if len(flagSet.Args()) == 1 {
filename := flagSet.Arg(0)
script, err = ioutil.ReadFile(filename)
script, err = os.ReadFile(filename)
if err != nil {
return err
}
Expand All @@ -102,7 +102,7 @@ Please visit https://docs.sourcegraph.com/admin/validation for documentation of
}
if !isatty.IsTerminal(os.Stdin.Fd()) {
// stdin is a pipe not a terminal
script, err = ioutil.ReadAll(os.Stdin)
script, err = io.ReadAll(os.Stdin)
if err != nil {
return err
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func (vd *validator) parseKVPairs(val string, pairSep string) map[string]string
}

func (vd *validator) readSecrets(path string) (map[string]string, error) {
bs, err := ioutil.ReadFile(path)
bs, err := os.ReadFile(path)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -497,7 +497,7 @@ func (vd *validator) newClient(baseURL string) (*vdClient, error) {
}
defer func() { _ = resp.Body.Close() }()

p, err := ioutil.ReadAll(resp.Body)
p, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -548,7 +548,7 @@ func (c *vdClient) authenticate(path string, body interface{}) error {
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
p, err := ioutil.ReadAll(resp.Body)
p, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down Expand Up @@ -654,7 +654,7 @@ func (c *vdClient) graphQL(token, query string, variables map[string]interface{}
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
p, err := ioutil.ReadAll(resp.Body)
p, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/src/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"io"
"net/http"

"github.com/sourcegraph/src-cli/internal/api"
Expand Down Expand Up @@ -66,7 +66,7 @@ func getRecommendedVersion(ctx context.Context, client api.Client) (string, erro
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand Down
Loading