mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-27 00:26:30 +02:00
Fix deprecated uses of ioutil
This commit is contained in:
parent
79d3ed3957
commit
672d22d0dd
@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -134,7 +133,7 @@ var initCmd = &cobra.Command{
|
||||
_, err = os.Stat(indexFilePath)
|
||||
if os.IsNotExist(err) {
|
||||
// Create file
|
||||
err = ioutil.WriteFile(indexFilePath, []byte{}, 0644)
|
||||
err = os.WriteFile(indexFilePath, []byte{}, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating index file: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"golang.org/x/exp/slices"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -108,7 +107,7 @@ func (d *downloadSessionInternal) SaveIndex() error {
|
||||
if err != nil {
|
||||
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 {
|
||||
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) {
|
||||
// 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 {
|
||||
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 {
|
||||
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 !os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("failed to read cache index file: %w", err)
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -183,7 +182,7 @@ var ignoreDefaults = []string{
|
||||
}
|
||||
|
||||
func readGitignore(path string) (*gitignore.GitIgnore, bool) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
// TODO: check for read errors (and present them)
|
||||
return gitignore.CompileIgnoreLines(ignoreDefaults...), false
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/packwiz/packwiz/curseforge/packinterop"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@ -97,7 +96,7 @@ var importCmd = &cobra.Command{
|
||||
// Check if file is a zip
|
||||
if string(header) == "PK" {
|
||||
// Read the whole file (as bufio doesn't work for zips)
|
||||
zipData, err := ioutil.ReadAll(buf)
|
||||
zipData, err := io.ReadAll(buf)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading file: %s\n", err)
|
||||
os.Exit(1)
|
||||
@ -142,7 +141,7 @@ var importCmd = &cobra.Command{
|
||||
_, err = os.Stat(indexFilePath)
|
||||
if os.IsNotExist(err) {
|
||||
// Create file
|
||||
err = ioutil.WriteFile(indexFilePath, []byte{}, 0644)
|
||||
err = os.WriteFile(indexFilePath, []byte{}, 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating index file: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
@ -3,7 +3,6 @@ package packinterop
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
@ -68,7 +67,7 @@ func (s diskPackSource) GetFileList() ([]ImportPackFile, error) {
|
||||
}
|
||||
|
||||
func (s diskPackSource) GetPackFile() ImportPackFile {
|
||||
rc := ioutil.NopCloser(s.MetaSource)
|
||||
rc := io.NopCloser(s.MetaSource)
|
||||
return readerFile{s.MetaName, &rc}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"github.com/packwiz/packwiz/core"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
@ -20,7 +19,7 @@ func ReadMetadata(s ImportPackSource) ImportPackMetadata {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
fmt.Printf("Error reading file: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user