Fix deprecated uses of ioutil

This commit is contained in:
comp500 2023-01-20 18:43:46 +00:00
parent 79d3ed3957
commit 672d22d0dd
6 changed files with 9 additions and 15 deletions

View File

@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@ -134,7 +133,7 @@ var initCmd = &cobra.Command{
_, err = os.Stat(indexFilePath) _, err = os.Stat(indexFilePath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
// Create file // Create file
err = ioutil.WriteFile(indexFilePath, []byte{}, 0644) err = os.WriteFile(indexFilePath, []byte{}, 0644)
if err != nil { if err != nil {
fmt.Printf("Error creating index file: %s\n", err) fmt.Printf("Error creating index file: %s\n", err)
os.Exit(1) os.Exit(1)

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
@ -108,7 +107,7 @@ func (d *downloadSessionInternal) SaveIndex() error {
if err != nil { if err != nil {
return fmt.Errorf("failed to serialise index: %w", err) return fmt.Errorf("failed to serialise index: %w", err)
} }
err = ioutil.WriteFile(filepath.Join(d.cacheFolder, "index.json"), data, 0644) err = os.WriteFile(filepath.Join(d.cacheFolder, "index.json"), data, 0644)
if err != nil { if err != nil {
return fmt.Errorf("failed to write index: %w", err) return fmt.Errorf("failed to write index: %w", err)
} }
@ -146,7 +145,7 @@ func reuseExistingFile(cacheHandle *CacheIndexHandle, hashesToObtain []string, m
func downloadNewFile(task *downloadTask, cacheFolder string, hashesToObtain []string, index *CacheIndex) (CompletedDownload, error) { func downloadNewFile(task *downloadTask, cacheFolder string, hashesToObtain []string, index *CacheIndex) (CompletedDownload, error) {
// Create temp file to download to // Create temp file to download to
tempFile, err := ioutil.TempFile(filepath.Join(cacheFolder, "temp"), "download-tmp") tempFile, err := os.CreateTemp(filepath.Join(cacheFolder, "temp"), "download-tmp")
if err != nil { if err != nil {
return CompletedDownload{}, fmt.Errorf("failed to create temporary file for download: %w", err) return CompletedDownload{}, fmt.Errorf("failed to create temporary file for download: %w", err)
} }
@ -551,7 +550,7 @@ func CreateDownloadSession(mods []*Mod, hashesToObtain []string) (DownloadSessio
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create cache temp directory: %w", err) return nil, fmt.Errorf("failed to create cache temp directory: %w", err)
} }
cacheIndexData, err := ioutil.ReadFile(filepath.Join(cachePath, "index.json")) cacheIndexData, err := os.ReadFile(filepath.Join(cachePath, "index.json"))
if err != nil { if err != nil {
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to read cache index file: %w", err) return nil, fmt.Errorf("failed to read cache index file: %w", err)

View File

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@ -183,7 +182,7 @@ var ignoreDefaults = []string{
} }
func readGitignore(path string) (*gitignore.GitIgnore, bool) { func readGitignore(path string) (*gitignore.GitIgnore, bool) {
data, err := ioutil.ReadFile(path) data, err := os.ReadFile(path)
if err != nil { if err != nil {
// TODO: check for read errors (and present them) // TODO: check for read errors (and present them)
return gitignore.CompileIgnoreLines(ignoreDefaults...), false return gitignore.CompileIgnoreLines(ignoreDefaults...), false

View File

@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"github.com/packwiz/packwiz/curseforge/packinterop" "github.com/packwiz/packwiz/curseforge/packinterop"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
@ -97,7 +96,7 @@ var importCmd = &cobra.Command{
// Check if file is a zip // Check if file is a zip
if string(header) == "PK" { if string(header) == "PK" {
// Read the whole file (as bufio doesn't work for zips) // Read the whole file (as bufio doesn't work for zips)
zipData, err := ioutil.ReadAll(buf) zipData, err := io.ReadAll(buf)
if err != nil { if err != nil {
fmt.Printf("Error reading file: %s\n", err) fmt.Printf("Error reading file: %s\n", err)
os.Exit(1) os.Exit(1)
@ -142,7 +141,7 @@ var importCmd = &cobra.Command{
_, err = os.Stat(indexFilePath) _, err = os.Stat(indexFilePath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
// Create file // Create file
err = ioutil.WriteFile(indexFilePath, []byte{}, 0644) err = os.WriteFile(indexFilePath, []byte{}, 0644)
if err != nil { if err != nil {
fmt.Printf("Error creating index file: %s\n", err) fmt.Printf("Error creating index file: %s\n", err)
os.Exit(1) os.Exit(1)

View File

@ -3,7 +3,6 @@ package packinterop
import ( import (
"bufio" "bufio"
"io" "io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
) )
@ -68,7 +67,7 @@ func (s diskPackSource) GetFileList() ([]ImportPackFile, error) {
} }
func (s diskPackSource) GetPackFile() ImportPackFile { func (s diskPackSource) GetPackFile() ImportPackFile {
rc := ioutil.NopCloser(s.MetaSource) rc := io.NopCloser(s.MetaSource)
return readerFile{s.MetaName, &rc} return readerFile{s.MetaName, &rc}
} }

View File

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"github.com/packwiz/packwiz/core" "github.com/packwiz/packwiz/core"
"io" "io"
"io/ioutil"
"os" "os"
) )
@ -20,7 +19,7 @@ func ReadMetadata(s ImportPackSource) ImportPackMetadata {
} }
// Read the whole file (as we are going to parse it multiple times) // Read the whole file (as we are going to parse it multiple times)
fileData, err := ioutil.ReadAll(rdr) fileData, err := io.ReadAll(rdr)
if err != nil { if err != nil {
fmt.Printf("Error reading file: %s\n", err) fmt.Printf("Error reading file: %s\n", err)
os.Exit(1) os.Exit(1)