From 8c42479827d76dfcc279e0f56d3791107419db46 Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Sat, 21 Sep 2024 19:16:38 +0200 Subject: [PATCH 1/6] chore(ci): bump FreeBSD and Go version --- .cirrus.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 4e900f8..75a0d79 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,10 +1,10 @@ freebsd_instance: - image_family: freebsd-13-0 + image_family: freebsd-14-0 task: name: Test on FreeBSD - install_script: pkg install -y go119 dbus + install_script: pkg install -y go122 dbus test_script: | /usr/local/etc/rc.d/dbus onestart && \ eval `dbus-launch --sh-syntax` && \ - go119 test -v ./... + go122 test -v ./... From 8f43440ecce3e27e9ef3c7583b8b4370da49c7e8 Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Sat, 21 Sep 2024 19:34:52 +0200 Subject: [PATCH 2/6] chore(ci): bump Ubuntu and Go versions --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0799a47..979e3c6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,22 +12,22 @@ permissions: jobs: lint: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: 1.19 + go-version: 1.23 - uses: golangci/golangci-lint-action@v3 with: version: v1.50 test: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: - go-version: ['1.16', '1.17', '1.18', '1.19', '1.20'] + go-version: ['1.22', '1.23'] steps: @@ -49,7 +49,7 @@ jobs: run: go test -race -v ./... codespell: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v3 - uses: codespell-project/actions-codespell@master From c80783f852f8a4dfc9120be2c3d31a67365bea9b Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Sat, 21 Sep 2024 19:37:38 +0200 Subject: [PATCH 3/6] chore(ci): bump golangci-lint --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 979e3c6..8cf7f2c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,16 +18,16 @@ jobs: - uses: actions/setup-go@v3 with: go-version: 1.23 - - uses: golangci/golangci-lint-action@v3 + - uses: golangci/golangci-lint-action@v6 with: - version: v1.50 + version: v1.60 test: runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: - go-version: ['1.22', '1.23'] + go-version: ['1.20', '1.21', '1.22', '1.23'] steps: From 33c352a0a8e4a8b14533f07945a59bcd08640695 Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Sat, 21 Sep 2024 19:45:06 +0200 Subject: [PATCH 4/6] chore(decoder): use unsafe.String This raises the minimum Go version to 1.20 --- README.md | 2 +- decoder.go | 8 +------- go.mod | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 5c6b196..da848a9 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ D-Bus message bus system. ### Installation -This packages requires Go 1.12 or later. It can be installed by running the command below: +This packages requires Go 1.20 or later. It can be installed by running the command below: ``` go get github.com/godbus/dbus/v5 diff --git a/decoder.go b/decoder.go index 97a827b..d03bdd8 100644 --- a/decoder.go +++ b/decoder.go @@ -370,12 +370,6 @@ func (c *stringConverter) String(b []byte) string { } // toString converts a byte slice to a string without allocating. -// Starting from Go 1.20 you should use unsafe.String. func toString(b []byte) string { - var s string - h := (*reflect.StringHeader)(unsafe.Pointer(&s)) - h.Data = uintptr(unsafe.Pointer(&b[0])) - h.Len = len(b) - - return s + return unsafe.String(&b[0], len(b)) } diff --git a/go.mod b/go.mod index f764bce..3d72570 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/godbus/dbus/v5 -go 1.12 +go 1.20 require golang.org/x/sys v0.0.0-20220817070843-5a390386f1f2 From 2e0e9dd53a1d8a582e4b852db79a61cdf8ed7354 Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Sat, 21 Sep 2024 19:45:40 +0200 Subject: [PATCH 5/6] chore: remove uses of ioutil --- conn_linux_test.go | 3 +-- conn_other.go | 3 +-- conn_test.go | 7 +++---- proto_test.go | 6 +++--- transport_nonce_tcp.go | 4 ++-- transport_nonce_tcp_test.go | 3 +-- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/conn_linux_test.go b/conn_linux_test.go index 2c13545..adcca19 100644 --- a/conn_linux_test.go +++ b/conn_linux_test.go @@ -2,7 +2,6 @@ package dbus import ( "bufio" - "io/ioutil" "os" "os/exec" "syscall" @@ -46,7 +45,7 @@ func startDaemonInDifferentUserNamespace(t *testing.T) (string, *os.Process) { ` - cfg, err := ioutil.TempFile("", "") + cfg, err := os.CreateTemp("", "") if err != nil { t.Fatal(err) } diff --git a/conn_other.go b/conn_other.go index 067e67c..1e99594 100644 --- a/conn_other.go +++ b/conn_other.go @@ -7,7 +7,6 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" "os" "os/exec" "os/user" @@ -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=" diff --git a/conn_test.go b/conn_test.go index 9f64eca..f94dc96 100644 --- a/conn_test.go +++ b/conn_test.go @@ -5,7 +5,6 @@ import ( "encoding/binary" "fmt" "io" - "io/ioutil" "log" "sync" "testing" @@ -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) } @@ -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) } @@ -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) } diff --git a/proto_test.go b/proto_test.go index 5352e0a..534a9ee 100644 --- a/proto_test.go +++ b/proto_test.go @@ -3,7 +3,7 @@ package dbus import ( "bytes" "encoding/binary" - "io/ioutil" + "io" "math" "reflect" "testing" @@ -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) } @@ -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) } diff --git a/transport_nonce_tcp.go b/transport_nonce_tcp.go index a61a820..a08d089 100644 --- a/transport_nonce_tcp.go +++ b/transport_nonce_tcp.go @@ -5,8 +5,8 @@ package dbus import ( "errors" - "io/ioutil" "net" + "os" ) func init() { @@ -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 } diff --git a/transport_nonce_tcp_test.go b/transport_nonce_tcp_test.go index c9075c3..a941584 100644 --- a/transport_nonce_tcp_test.go +++ b/transport_nonce_tcp_test.go @@ -2,7 +2,6 @@ package dbus import ( "bufio" - "io/ioutil" "os" "os/exec" "testing" @@ -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) } From fc0247fbab7c661d2aa8d57aeec3f5c8837174a4 Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Sat, 21 Sep 2024 19:46:01 +0200 Subject: [PATCH 6/6] fix(server_interfaces_test): remove unneeded fmt.Errorf use --- server_interfaces_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server_interfaces_test.go b/server_interfaces_test.go index 96044a5..23d5802 100644 --- a/server_interfaces_test.go +++ b/server_interfaces_test.go @@ -1,7 +1,7 @@ package dbus import ( - "fmt" + "errors" "sync" "sync/atomic" "testing" @@ -83,7 +83,7 @@ func (t *tester) LookupMethod(name string) (Method, bool) { return t, true case "Error": return terrfn(func(in string) error { - return fmt.Errorf(in) + return errors.New(in) }), true case "Introspect": return intro_fn(func() string {