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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,7 +9,6 @@ import (
"crypto/x509" "crypto/x509"
"crypto/x509/pkix" "crypto/x509/pkix"
"encoding/pem" "encoding/pem"
"io/ioutil"
"math/big" "math/big"
"net" "net"
"os" "os"
@ -351,9 +350,9 @@ func writeTestCertFiles(t *testing.T, expiredCert, encryptTLSKey bool,
require.NoError(t, err, "failed to encrypt private key") 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") 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") require.NoError(t, err, "failed to write key file")
return certPath, keyPath, parsedCert return certPath, keyPath, parsedCert

View File

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