Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove refs to deprecated io/ioutil #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions pkg/config/cfgReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package cfgreader
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"os"
"unicode"

Expand All @@ -40,7 +40,7 @@ func LoadConfig(cfg interface{}, path string) (err error) {
defer file.Close()

// read our opened json file as a byte array.
data, readErr := ioutil.ReadAll(file)
data, readErr := io.ReadAll(file)
if readErr != nil {
return readErr
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/file/fileUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"encoding/base64"
"fmt"
"io"
"io/ioutil"
"log"
"mime/multipart"
"os"
Expand Down Expand Up @@ -429,7 +428,7 @@ func GetCompressedFiles(files []scan.File, rootPath string) (newfiles []scan.Fil
//check if file list contains compressed files, if so, scan their contents
for _, file := range files {
//Unpack and append to file list
tmppath, err := ioutil.TempDir("", "ebzip")
tmppath, err := os.MkdirTemp("", "ebzip")
if err != nil {
return newfiles, compresspaths, err
}
Expand Down Expand Up @@ -488,11 +487,11 @@ func Uncompress(src string, dest string) (filenames []string, err error) {
if err = os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil {
return filenames, err
}
body, err := ioutil.ReadAll(rc)
body, err := io.ReadAll(rc)
if err != nil {
return filenames, err
}
err = ioutil.WriteFile(fpath, body, 0644)
err = os.WriteFile(fpath, body, 0644)
if err != nil {
return filenames, err
}
Expand All @@ -518,7 +517,7 @@ func GetConvertedFiles(files []scan.File) (convertedFiles []scan.File, converted
}

for _, file := range toBeConverted {
tmppath, err := ioutil.TempDir("", "ebconv")
tmppath, err := os.MkdirTemp("", "ebconv")
fpath := filepath.Join(tmppath, file.Name)

// Get content from the file as a string
Expand All @@ -529,7 +528,7 @@ func GetConvertedFiles(files []scan.File) (convertedFiles []scan.File, converted
}

// Write content to new temp file
err = ioutil.WriteFile(fpath, []byte(content.Body), 0644)
err = os.WriteFile(fpath, []byte(content.Body), 0644)
if err != nil {
log.Printf("Error writing converted file %s, file not scanned\n", file.Path)
continue
Expand Down
3 changes: 1 addition & 2 deletions pkg/git/cloner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"gopkg.in/src-d/go-git.v4/plumbing"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -79,7 +78,7 @@ func ReposPerProject(projectURL, username, password string) (scanRepos []string)

//CloneGitRepos Clones a Git repo into a random temporary folder
func CloneGitRepos(repoURLs []string, username, password string, branch string, json bool) (tmpDir string, err error) {
tmpDir, err = ioutil.TempDir("", "ebgit")
tmpDir, err = os.MkdirTemp("", "ebgit")
if err != nil {
return "", err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package configupdate

import (
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
"os"
"path"

cfgreader "github.com/americanexpress/earlybird/v4/pkg/config"
Expand Down Expand Up @@ -70,16 +71,16 @@ func downloadFile(path string, url string) error {
defer resp.Body.Close()

if resp.StatusCode != 200 {
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
return fmt.Errorf("received non 200 status code: status=%d, response=%v", resp.StatusCode, string(b))
}

b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)

if err != nil {
return fmt.Errorf("reading response body: %v", err)
}
err = ioutil.WriteFile(path, b, 0666)
err = os.WriteFile(path, b, 0666)
if err != nil {
return fmt.Errorf("writing file at %s: %v", path, err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package utils

import (
"io/ioutil"
"os"
"testing"
)
Expand Down Expand Up @@ -128,7 +127,7 @@ func TestDeleteGit(t *testing.T) {
}

testRepo := "test-repo"
tmpDir, err := ioutil.TempDir("", "ebgit")
tmpDir, err := os.MkdirTemp("", "ebgit")
if err != nil {
t.Errorf("Failed to create temporoary directory: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/writers/jsonout.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
cfgReader "github.com/americanexpress/earlybird/v4/pkg/config"
"github.com/americanexpress/earlybird/v4/pkg/file"
"github.com/americanexpress/earlybird/v4/pkg/scan"
"io/ioutil"
"os"
"time"
)
Expand Down Expand Up @@ -62,7 +61,7 @@ func reportToJSONWriter(v interface{}, fileName string) (s string, err error) {
if fileName == "" {
_, err = os.Stdout.Write(b)
} else {
err = ioutil.WriteFile(fileName, b, 0666)
err = os.WriteFile(fileName, b, 0666)
}
return string(b), err

Expand Down