Skip to content

Commit

Permalink
multi: replace ioutil.WriteFile
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEk committed Apr 25, 2024
1 parent ab83343 commit 789c6ba
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 31 deletions.
5 changes: 2 additions & 3 deletions cert/selfsigned.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io/ioutil"
"math/big"
"net"
"os"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions cmd/lncli/cmd_macaroon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/hex"
"fmt"
"io/ioutil"
"net"
"os"
"strconv"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions cmd/lncli/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions internal/musig2v040/musig2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
"sync"
"testing"

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions kvdb/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lnrpc/chainrpc/chain_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"os"
"path/filepath"
"sync"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lnrpc/invoicesrpc/invoices_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lnrpc/routerrpc/router_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
crand "crypto/rand"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync/atomic"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lnrpc/signrpc/signer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"crypto/sha256"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lnrpc/walletrpc/walletkit_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"encoding/binary"
"errors"
"fmt"
"io/ioutil"
"math"
"os"
"path/filepath"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tls_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions tls_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"io/ioutil"
"math/big"
"net"
"os"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tor/cmd_onion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 789c6ba

Please sign in to comment.