Skip to content

Commit 559c430

Browse files
committedSep 12, 2023
tools: replace references to obsolete package ioutils
ioutil defines 7 functions. 6 of these are replaced by functions in io or os with the same signature. ReadDir is deprecated, but the suggested replacement has a different signature. These changes were generated by a program, with some manual adjutments. The program replaces ReadDir with a call to a function named ioutilReadDir that has the same signature. The code for this function is added to files if necessary. The program replaces all the others with their new versions. The program removes the 'io/ioutil' import and adds, as necessary, 'os', 'io', and 'io/fs', the latter being needed for the signature of ioutilReadDir. The automatic process fails in a few ways: 1. ReadFile occurs only in a comment but the program adds an unneeded import. 2. ioutilReadDir is added to more than one file in the same package Both of these could be viewed as bugs and fixed by looking harder. After manual adjustment, two tests failed: 1. gopls/internal/lsp/regtesg/mis:TestGenerateProgress. The reason was a use of ioutil in a txtar constant. The calls were changed, but the code is not smart enough to change the import inside the string constant. (Or it's not smart enough not to change the contents of a string.) 2. gopls/internal/lsp/analysis/deprecated, which wants to see a use of ioutil These tests were adjused by hand, and all tests (-short) pass. Change-Id: If9efe40bbb0edda36173d9a88afaf71245db8e79 Reviewed-on: https://go-review.googlesource.com/c/tools/+/527675 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Peter Weinberger <pjw@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
1 parent 0b3914d commit 559c430

File tree

117 files changed

+389
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+389
-346
lines changed
 

‎cmd/auth/netrcauth/netrcauth.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package main
1616

1717
import (
1818
"fmt"
19-
"io/ioutil"
2019
"log"
2120
"net/http"
2221
"net/url"
@@ -41,7 +40,7 @@ func main() {
4140

4241
path := os.Args[1]
4342

44-
data, err := ioutil.ReadFile(path)
43+
data, err := os.ReadFile(path)
4544
if err != nil {
4645
if os.IsNotExist(err) {
4746
return

‎cmd/bundle/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ import (
7979
"go/printer"
8080
"go/token"
8181
"go/types"
82-
"io/ioutil"
8382
"log"
8483
"os"
8584
"strconv"
@@ -149,7 +148,7 @@ func main() {
149148
log.Fatal(err)
150149
}
151150
if *outputFile != "" {
152-
err := ioutil.WriteFile(*outputFile, code, 0666)
151+
err := os.WriteFile(*outputFile, code, 0666)
153152
if err != nil {
154153
log.Fatal(err)
155154
}

0 commit comments

Comments
 (0)
Please sign in to comment.