all: Remove usage of deprecated io/ioutil (#7971)

As of Go 1.16 io/ioutil is deprecated. This replaces usage with the
corresponding functions in package os and package io.
This commit is contained in:
Jakob Borg
2021-11-22 08:59:47 +01:00
committed by GitHub
parent bf89bffb0b
commit 4b750b6dc3
71 changed files with 190 additions and 235 deletions
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net"
"net/url"
"os"
@@ -163,7 +162,7 @@ func ReadXML(r io.Reader, myID protocol.DeviceID) (Configuration, int, error) {
}
func ReadJSON(r io.Reader, myID protocol.DeviceID) (Configuration, error) {
bs, err := ioutil.ReadAll(r)
bs, err := io.ReadAll(r)
if err != nil {
return Configuration{}, err
}
+4 -5
View File
@@ -13,7 +13,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"reflect"
@@ -502,7 +501,7 @@ func TestFolderPath(t *testing.T) {
}
func TestFolderCheckPath(t *testing.T) {
n, err := ioutil.TempDir("", "")
n, err := os.MkdirTemp("", "")
if err != nil {
t.Fatal(err)
}
@@ -643,8 +642,8 @@ func TestCopy(t *testing.T) {
t.Error("Config should have changed")
}
if !bytes.Equal(bsOrig, bsCopy) {
// ioutil.WriteFile("a", bsOrig, 0644)
// ioutil.WriteFile("b", bsCopy, 0644)
// os.WriteFile("a", bsOrig, 0644)
// os.WriteFile("b", bsCopy, 0644)
t.Error("Copy should be unchanged")
}
}
@@ -1266,7 +1265,7 @@ func copyToTmp(path string) (string, error) {
return "", err
}
defer orig.Close()
temp, err := ioutil.TempFile("", "syncthing-configTest-")
temp, err := os.CreateTemp("", "syncthing-configTest-")
if err != nil {
return "", err
}