Skip to content

Commit

Permalink
chore: remove uses of ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
guelfey committed Sep 21, 2024
1 parent 33c352a commit 2e0e9dd
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
3 changes: 1 addition & 2 deletions conn_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dbus

import (
"bufio"
"io/ioutil"
"os"
"os/exec"
"syscall"
Expand Down Expand Up @@ -46,7 +45,7 @@ func startDaemonInDifferentUserNamespace(t *testing.T) (string, *os.Process) {
</policy>
</busconfig>
`
cfg, err := ioutil.TempFile("", "")
cfg, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions conn_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"os/user"
Expand Down Expand Up @@ -61,7 +60,7 @@ func tryDiscoverDbusSessionBusAddress() string {
// text file // containing the address of the socket, e.g.:
// DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-E1c73yNqrG

if f, err := ioutil.ReadFile(runUserSessionDbusFile); err == nil {
if f, err := os.ReadFile(runUserSessionDbusFile); err == nil {
fileContent := string(f)

prefix := "DBUS_SESSION_BUS_ADDRESS="
Expand Down
7 changes: 3 additions & 4 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"log"
"sync"
"testing"
Expand Down Expand Up @@ -171,7 +170,7 @@ func TestCloseBeforeSignal(t *testing.T) {
defer pipewriter.Close()
defer reader.Close()

bus, err := NewConn(rwc{Reader: reader, Writer: ioutil.Discard})
bus, err := NewConn(rwc{Reader: reader, Writer: io.Discard})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -743,7 +742,7 @@ func TestDisconnectCancelsConnectionContext(t *testing.T) {
defer pipewriter.Close()
defer reader.Close()

bus, err := NewConn(rwc{Reader: reader, Writer: ioutil.Discard})
bus, err := NewConn(rwc{Reader: reader, Writer: io.Discard})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -778,7 +777,7 @@ func TestCancellingContextClosesConnection(t *testing.T) {
defer pipewriter.Close()
defer reader.Close()

bus, err := NewConn(rwc{Reader: reader, Writer: ioutil.Discard}, WithContext(ctx))
bus, err := NewConn(rwc{Reader: reader, Writer: io.Discard}, WithContext(ctx))
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dbus
import (
"bytes"
"encoding/binary"
"io/ioutil"
"io"
"math"
"reflect"
"testing"
Expand Down Expand Up @@ -371,7 +371,7 @@ func BenchmarkDecodeMessageBig(b *testing.B) {
func BenchmarkEncodeMessageSmall(b *testing.B) {
var err error
for i := 0; i < b.N; i++ {
err = smallMessage.EncodeTo(ioutil.Discard, binary.LittleEndian)
err = smallMessage.EncodeTo(io.Discard, binary.LittleEndian)
if err != nil {
b.Fatal(err)
}
Expand All @@ -381,7 +381,7 @@ func BenchmarkEncodeMessageSmall(b *testing.B) {
func BenchmarkEncodeMessageBig(b *testing.B) {
var err error
for i := 0; i < b.N; i++ {
err = bigMessage.EncodeTo(ioutil.Discard, binary.LittleEndian)
err = bigMessage.EncodeTo(io.Discard, binary.LittleEndian)
if err != nil {
b.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions transport_nonce_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package dbus

import (
"errors"
"io/ioutil"
"net"
"os"
)

func init() {
Expand All @@ -28,7 +28,7 @@ func newNonceTcpTransport(keys string) (transport, error) {
if err != nil {
return nil, err
}
b, err := ioutil.ReadFile(noncefile)
b, err := os.ReadFile(noncefile)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions transport_nonce_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dbus

import (
"bufio"
"io/ioutil"
"os"
"os/exec"
"testing"
Expand Down Expand Up @@ -38,7 +37,7 @@ func TestTcpNonceConnection(t *testing.T) {
// startDaemon starts a dbus-daemon instance with the given config
// and returns its address string and underlying process.
func startDaemon(t *testing.T, config string) (string, *os.Process) {
cfg, err := ioutil.TempFile("", "")
cfg, err := os.CreateTemp("", "")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 2e0e9dd

Please sign in to comment.