multi: replace ioutil.WriteFile

This commit is contained in:
erik 2023-06-14 11:33:44 +02:00 committed by ErikEk
parent ab83343c87
commit 789c6bac8c
13 changed files with 20 additions and 31 deletions

View File

@ -9,7 +9,6 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io/ioutil"
"math/big"
"net"
"os"
@ -295,14 +294,14 @@ func GenCertPair(org string, tlsExtraIPs, tlsExtraDomains []string,
func WriteCertPair(certFile, keyFile string, certBytes, keyBytes []byte) error {
// Write cert and key files.
if certFile != "" {
err := ioutil.WriteFile(certFile, certBytes, 0644)
err := os.WriteFile(certFile, certBytes, 0644)
if err != nil {
return err
}
}
if keyFile != "" {
err := ioutil.WriteFile(keyFile, keyBytes, 0600)
err := os.WriteFile(keyFile, keyBytes, 0600)
if err != nil {
os.Remove(certFile)
return err

View File

@ -4,7 +4,6 @@ import (
"bytes"
"encoding/hex"
"fmt"
"io/ioutil"
"net"
"os"
"strconv"
@ -193,7 +192,7 @@ func bakeMacaroon(ctx *cli.Context) error {
// a file or write to the standard output using hex encoding.
switch {
case savePath != "":
err = ioutil.WriteFile(savePath, macBytes, 0644)
err = os.WriteFile(savePath, macBytes, 0644)
if err != nil {
return err
}
@ -472,7 +471,7 @@ func constrainMacaroon(ctx *cli.Context) error {
}
// Now we can output the result.
err = ioutil.WriteFile(destMacFile, destMacBytes, 0644)
err = os.WriteFile(destMacFile, destMacBytes, 0644)
if err != nil {
return fmt.Errorf("error writing destination macaroon file "+
"%s: %v", destMacFile, err)

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
@ -244,7 +243,8 @@ func saveProfileFile(file string, f *profileFile) error {
if err != nil {
return fmt.Errorf("could not marshal profile: %w", err)
}
return ioutil.WriteFile(file, content, 0644)
return os.WriteFile(file, content, 0644)
}
// profileFile is a struct that represents the whole content of a profile file.

View File

@ -10,7 +10,7 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"
@ -256,7 +256,7 @@ func TestMuSig2KeyAggTestVectors(t *testing.T) {
var formattedJson bytes.Buffer
json.Indent(&formattedJson, jsonBytes, "", "\t")
err = ioutil.WriteFile(
err = os.WriteFile(
keyAggTestVectorName, formattedJson.Bytes(), 0644,
)
if err != nil {
@ -656,7 +656,7 @@ func TestMuSig2SigningTestVectors(t *testing.T) {
var formattedJson bytes.Buffer
json.Indent(&formattedJson, jsonBytes, "", "\t")
err = ioutil.WriteFile(
err = os.WriteFile(
signTestVectorName, formattedJson.Bytes(), 0644,
)
if err != nil {
@ -1540,7 +1540,7 @@ func TestMusig2AggregateNoncesTestVectors(t *testing.T) {
var formattedJson bytes.Buffer
json.Indent(&formattedJson, jsonBytes, "", "\t")
err = ioutil.WriteFile(
err = os.WriteFile(
nonceAggTestVectorName, formattedJson.Bytes(), 0644,
)
if err != nil {

View File

@ -9,7 +9,6 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
@ -235,7 +234,7 @@ func updateLastCompactionDate(dbFile string) error {
byteOrder.PutUint64(tsBytes[:], uint64(time.Now().UnixNano()))
tsFile := fmt.Sprintf("%s%s", dbFile, LastCompactionFileNameSuffix)
return ioutil.WriteFile(tsFile, tsBytes[:], 0600)
return os.WriteFile(tsFile, tsBytes[:], 0600)
}
// GetTestBackend opens (or creates if doesn't exist) a bbolt or etcd

View File

@ -7,7 +7,6 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"os"
"path/filepath"
"sync"
@ -153,7 +152,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
if err != nil {
return nil, nil, err
}
err = ioutil.WriteFile(macFilePath, chainNotifierMacBytes, 0644)
err = os.WriteFile(macFilePath, chainNotifierMacBytes, 0644)
if err != nil {
_ = os.Remove(macFilePath)
return nil, nil, err

View File

@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -132,7 +131,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
if err != nil {
return nil, nil, err
}
err = ioutil.WriteFile(macFilePath, invoicesMacBytes, 0644)
err = os.WriteFile(macFilePath, invoicesMacBytes, 0644)
if err != nil {
_ = os.Remove(macFilePath)
return nil, nil, err

View File

@ -6,7 +6,6 @@ import (
crand "crypto/rand"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync/atomic"
@ -216,7 +215,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
if err != nil {
return nil, nil, err
}
err = ioutil.WriteFile(macFilePath, routerMacBytes, 0644)
err = os.WriteFile(macFilePath, routerMacBytes, 0644)
if err != nil {
_ = os.Remove(macFilePath)
return nil, nil, err

View File

@ -8,7 +8,6 @@ import (
"context"
"crypto/sha256"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -167,7 +166,7 @@ func New(cfg *Config) (*Server, lnrpc.MacaroonPerms, error) {
if err != nil {
return nil, nil, err
}
err = ioutil.WriteFile(macFilePath, signerMacBytes, 0644)
err = os.WriteFile(macFilePath, signerMacBytes, 0644)
if err != nil {
_ = os.Remove(macFilePath)
return nil, nil, err

View File

@ -10,7 +10,6 @@ import (
"encoding/binary"
"errors"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
@ -289,7 +288,7 @@ func New(cfg *Config) (*WalletKit, lnrpc.MacaroonPerms, error) {
if err != nil {
return nil, nil, err
}
err = ioutil.WriteFile(macFilePath, walletKitMacBytes, 0644)
err = os.WriteFile(macFilePath, walletKitMacBytes, 0644)
if err != nil {
_ = os.Remove(macFilePath)
return nil, nil, err

View File

@ -7,7 +7,6 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
@ -279,7 +278,7 @@ func (t *TLSManager) ensureEncryption(keyRing keychain.SecretKeyRing) error {
if err != nil {
return err
}
err = ioutil.WriteFile(
err = os.WriteFile(
t.cfg.TLSKeyPath, b.Bytes(), modifyFilePermissions,
)
if err != nil {

View File

@ -9,7 +9,6 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"io/ioutil"
"math/big"
"net"
"os"
@ -351,9 +350,9 @@ func writeTestCertFiles(t *testing.T, expiredCert, encryptTLSKey bool,
require.NoError(t, err, "failed to encrypt private key")
}
err = ioutil.WriteFile(tempDir+"/tls.cert", certBuf.Bytes(), 0644)
err = os.WriteFile(tempDir+"/tls.cert", certBuf.Bytes(), 0644)
require.NoError(t, err, "failed to write cert file")
err = ioutil.WriteFile(tempDir+"/tls.key", keyBuf.Bytes(), 0600)
err = os.WriteFile(tempDir+"/tls.key", keyBuf.Bytes(), 0600)
require.NoError(t, err, "failed to write key file")
return certPath, keyPath, parsedCert

View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
)
@ -105,7 +104,7 @@ func (f *OnionFile) StorePrivateKey(privateKey []byte) error {
privateKeyContent = b.Bytes()
}
err := ioutil.WriteFile(
err := os.WriteFile(
f.privateKeyPath, privateKeyContent, f.privateKeyPerm,
)
if err != nil {