cleanup(all): stop using deprecated ioutil functions (#381)
Spotted while working on https://github.com/ooni/probe/issues/1417 See https://golang.org/pkg/io/ioutil/
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -114,7 +113,7 @@ func (managerDarwin) writePlist() error {
|
||||
return err
|
||||
}
|
||||
log.Infof("exec: writePlist(%s)", plistPath)
|
||||
return ioutil.WriteFile(plistPath, out.Bytes(), 0644)
|
||||
return os.WriteFile(plistPath, out.Bytes(), 0644)
|
||||
}
|
||||
|
||||
func (managerDarwin) start() error {
|
||||
|
||||
@@ -2,7 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/utils"
|
||||
@@ -14,7 +14,7 @@ const ConfigVersion = 1
|
||||
|
||||
// ReadConfig reads the configuration from the path
|
||||
func ReadConfig(path string) (*Config, error) {
|
||||
b, err := ioutil.ReadFile(path)
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -67,7 +67,7 @@ func (c *Config) Write() error {
|
||||
if c.path == "" {
|
||||
return errors.New("config file path is empty")
|
||||
}
|
||||
if err := ioutil.WriteFile(c.path, configJSON, 0644); err != nil {
|
||||
if err := os.WriteFile(c.path, configJSON, 0644); err != nil {
|
||||
return errors.Wrap(err, "writing config JSON")
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -43,11 +43,11 @@ func TestUpdateConfig(t *testing.T) {
|
||||
configPath := tmpFile.Name()
|
||||
defer os.Remove(configPath)
|
||||
|
||||
data, err := ioutil.ReadFile("testdata/config-v0.json")
|
||||
data, err := os.ReadFile("testdata/config-v0.json")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
err = ioutil.WriteFile(configPath, data, 0644)
|
||||
err = os.WriteFile(configPath, data, 0644)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -92,7 +91,7 @@ func GetMeasurementJSON(sess sqlbuilder.Database, measurementID int64) (map[stri
|
||||
return nil, errors.New("cannot access measurement file")
|
||||
}
|
||||
measurementFilePath := measurement.Measurement.MeasurementFilePath.String
|
||||
b, err := ioutil.ReadFile(measurementFilePath)
|
||||
b, err := os.ReadFile(measurementFilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package nettests
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
@@ -11,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
func copyfile(source, dest string) error {
|
||||
data, err := ioutil.ReadFile(source)
|
||||
data, err := os.ReadFile(source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(dest, data, 0600)
|
||||
return os.WriteFile(dest, data, 0600)
|
||||
}
|
||||
|
||||
func newOONIProbe(t *testing.T) *ooni.Probe {
|
||||
|
||||
@@ -265,7 +265,7 @@ func InitDefaultConfig(home string) (*config.Config, error) {
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
log.Debugf("writing default config to %s", configPath)
|
||||
if err = ioutil.WriteFile(configPath, defaultConfig, 0644); err != nil {
|
||||
if err = os.WriteFile(configPath, defaultConfig, 0644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// If the user did the informed consent procedure in
|
||||
|
||||
Reference in New Issue
Block a user