[go] all: use io.Seek* instead of deprecated os.SEEK_*

145 views
Skip to first unread message

Tobias Klauser (Gerrit)

unread,
Aug 5, 2022, 5:41:27 AM8/5/22
to Russ Cox, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: Ian Lance Taylor, Russ Cox.

Tobias Klauser would like Ian Lance Taylor and Russ Cox to review this change.

View Change

all: use io.Seek* instead of deprecated os.SEEK_*

These are available since Go 1.7. The version used for bootstrap is Go
1.17 for Go 1.20.

For #44505

Change-Id: I497c9f617baefdeb273cd115b08b6e31bd10aad2
---
M src/cmd/compile/internal/typecheck/iimport.go
M src/cmd/internal/archive/archive.go
M src/cmd/link/internal/loader/loader.go
M src/internal/pkgbits/decoder.go
M src/internal/xcoff/ar.go
M src/internal/xcoff/file.go
M src/net/sendfile_test.go
M src/testing/run_example_js.go
8 files changed, 41 insertions(+), 27 deletions(-)

diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go
index 84c748f..8c4fe54 100644
--- a/src/cmd/compile/internal/typecheck/iimport.go
+++ b/src/cmd/compile/internal/typecheck/iimport.go
@@ -13,7 +13,6 @@
"go/constant"
"io"
"math/big"
- "os"
"strings"

"cmd/compile/internal/base"
@@ -152,7 +151,7 @@
whence, _ := ird.Seek(0, io.SeekCurrent)
stringData := data[whence : whence+sLen]
declData := data[whence+sLen : whence+sLen+dLen]
- ird.Seek(sLen+dLen, os.SEEK_CUR)
+ ird.Seek(sLen+dLen, io.SeekCurrent)

p := &iimporter{
exportVersion: version,
diff --git a/src/cmd/internal/archive/archive.go b/src/cmd/internal/archive/archive.go
index da1f293..d2c4f69 100644
--- a/src/cmd/internal/archive/archive.go
+++ b/src/cmd/internal/archive/archive.go
@@ -124,9 +124,9 @@

func (r *objReader) init(f *os.File) {
r.a = &Archive{f, nil}
- r.offset, _ = f.Seek(0, os.SEEK_CUR)
- r.limit, _ = f.Seek(0, os.SEEK_END)
- f.Seek(r.offset, os.SEEK_SET)
+ r.offset, _ = f.Seek(0, io.SeekCurrent)
+ r.limit, _ = f.Seek(0, io.SeekEnd)
+ f.Seek(r.offset, io.SeekStart)
r.b = bio.NewReader(f)
}

@@ -227,7 +227,7 @@
r.readFull(r.tmp[:n])
} else {
// Seek, giving up buffered data.
- r.b.MustSeek(r.offset+n, os.SEEK_SET)
+ r.b.MustSeek(r.offset+n, io.SeekStart)
r.offset += n
}
}
@@ -435,7 +435,7 @@

// AddEntry adds an entry to the end of a, with the content from r.
func (a *Archive) AddEntry(typ EntryType, name string, mtime int64, uid, gid int, mode os.FileMode, size int64, r io.Reader) {
- off, err := a.f.Seek(0, os.SEEK_END)
+ off, err := a.f.Seek(0, io.SeekEnd)
if err != nil {
log.Fatal(err)
}
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go
index 0cf9551..664f345 100644
--- a/src/cmd/link/internal/loader/loader.go
+++ b/src/cmd/link/internal/loader/loader.go
@@ -14,6 +14,7 @@
"cmd/link/internal/sym"
"debug/elf"
"fmt"
+ "io"
"log"
"math/bits"
"os"
@@ -2081,7 +2082,7 @@
l.addObj(lib.Pkg, or)

// The caller expects us consuming all the data
- f.MustSeek(length, os.SEEK_CUR)
+ f.MustSeek(length, io.SeekCurrent)

return r.Fingerprint()
}
diff --git a/src/internal/pkgbits/decoder.go b/src/internal/pkgbits/decoder.go
index b015033..357e328 100644
--- a/src/internal/pkgbits/decoder.go
+++ b/src/internal/pkgbits/decoder.go
@@ -95,7 +95,7 @@
pr.elemEnds = make([]uint32, pr.elemEndsEnds[len(pr.elemEndsEnds)-1])
assert(binary.Read(r, binary.LittleEndian, pr.elemEnds[:]) == nil)

- pos, err := r.Seek(0, os.SEEK_CUR)
+ pos, err := r.Seek(0, io.SeekCurrent)
assert(err == nil)

pr.elemData = input[pos:]
diff --git a/src/internal/xcoff/ar.go b/src/internal/xcoff/ar.go
index 0fb410f..2b432d5 100644
--- a/src/internal/xcoff/ar.go
+++ b/src/internal/xcoff/ar.go
@@ -123,7 +123,7 @@
}

var fhdr bigarFileHeader
- if _, err := sr.Seek(0, os.SEEK_SET); err != nil {
+ if _, err := sr.Seek(0, io.SeekStart); err != nil {
return nil, err
}
if err := binary.Read(sr, binary.BigEndian, &fhdr); err != nil {
@@ -151,7 +151,7 @@
// The member header is normally 2 bytes larger. But it's easier
// to read the name if the header is read without _ar_nam.
// However, AIAFMAG must be read afterward.
- if _, err := sr.Seek(off, os.SEEK_SET); err != nil {
+ if _, err := sr.Seek(off, io.SeekStart); err != nil {
return nil, err
}

@@ -183,7 +183,7 @@
fileoff := off + AR_HSZ_BIG + namlen
if fileoff&1 != 0 {
fileoff++
- if _, err := sr.Seek(1, os.SEEK_CUR); err != nil {
+ if _, err := sr.Seek(1, io.SeekCurrent); err != nil {
return nil, err
}
}
diff --git a/src/internal/xcoff/file.go b/src/internal/xcoff/file.go
index 05e4fd5..553103b 100644
--- a/src/internal/xcoff/file.go
+++ b/src/internal/xcoff/file.go
@@ -167,7 +167,7 @@
f.TargetMachine = magic

// Read XCOFF file header
- if _, err := sr.Seek(0, os.SEEK_SET); err != nil {
+ if _, err := sr.Seek(0, io.SeekStart); err != nil {
return nil, err
}
var nscns uint16
@@ -204,7 +204,7 @@

// Read string table (located right after symbol table).
offset := symptr + uint64(nsyms)*SYMESZ
- if _, err := sr.Seek(int64(offset), os.SEEK_SET); err != nil {
+ if _, err := sr.Seek(int64(offset), io.SeekStart); err != nil {
return nil, err
}
// The first 4 bytes contain the length (in bytes).
@@ -213,7 +213,7 @@
return nil, err
}
if l > 4 {
- if _, err := sr.Seek(int64(offset), os.SEEK_SET); err != nil {
+ if _, err := sr.Seek(int64(offset), io.SeekStart); err != nil {
return nil, err
}
f.StringTable = make([]byte, l)
@@ -223,7 +223,7 @@
}

// Read section headers
- if _, err := sr.Seek(int64(hdrsz)+int64(opthdr), os.SEEK_SET); err != nil {
+ if _, err := sr.Seek(int64(hdrsz)+int64(opthdr), io.SeekStart); err != nil {
return nil, err
}
f.Sections = make([]*Section, nscns)
@@ -269,7 +269,7 @@
var idxToSym = make(map[int]*Symbol)

// Read symbol table
- if _, err := sr.Seek(int64(symptr), os.SEEK_SET); err != nil {
+ if _, err := sr.Seek(int64(symptr), io.SeekStart); err != nil {
return nil, err
}
f.Symbols = make([]*Symbol, 0)
@@ -355,7 +355,7 @@

// Read csect auxiliary entry (by convention, it is the last).
if !needAuxFcn {
- if _, err := sr.Seek(int64(numaux-1)*SYMESZ, os.SEEK_CUR); err != nil {
+ if _, err := sr.Seek(int64(numaux-1)*SYMESZ, io.SeekCurrent); err != nil {
return nil, err
}
}
@@ -382,7 +382,7 @@
f.Symbols = append(f.Symbols, sym)
skip:
i += numaux // Skip auxiliary entries
- if _, err := sr.Seek(int64(numaux)*SYMESZ, os.SEEK_CUR); err != nil {
+ if _, err := sr.Seek(int64(numaux)*SYMESZ, io.SeekCurrent); err != nil {
return nil, err
}
}
@@ -397,7 +397,7 @@
if sect.Relptr == 0 {
continue
}
- if _, err := sr.Seek(int64(sect.Relptr), os.SEEK_SET); err != nil {
+ if _, err := sr.Seek(int64(sect.Relptr), io.SeekStart); err != nil {
return nil, err
}
for i := uint32(0); i < sect.Nreloc; i++ {
@@ -508,7 +508,7 @@
// Library name pattern is either path/base/member or base/member
func (f *File) readImportIDs(s *Section) ([]string, error) {
// Read loader header
- if _, err := s.sr.Seek(0, os.SEEK_SET); err != nil {
+ if _, err := s.sr.Seek(0, io.SeekStart); err != nil {
return nil, err
}
var istlen uint32
@@ -534,7 +534,7 @@
}

// Read loader import file ID table
- if _, err := s.sr.Seek(int64(impoff), os.SEEK_SET); err != nil {
+ if _, err := s.sr.Seek(int64(impoff), io.SeekStart); err != nil {
return nil, err
}
table := make([]byte, istlen)
@@ -577,7 +577,7 @@
return nil, nil
}
// Read loader header
- if _, err := s.sr.Seek(0, os.SEEK_SET); err != nil {
+ if _, err := s.sr.Seek(0, io.SeekStart); err != nil {
return nil, err
}
var stlen uint32
@@ -606,7 +606,7 @@
}

// Read loader section string table
- if _, err := s.sr.Seek(int64(stoff), os.SEEK_SET); err != nil {
+ if _, err := s.sr.Seek(int64(stoff), io.SeekStart); err != nil {
return nil, err
}
st := make([]byte, stlen)
@@ -621,7 +621,7 @@
}

// Read loader symbol table
- if _, err := s.sr.Seek(int64(symoff), os.SEEK_SET); err != nil {
+ if _, err := s.sr.Seek(int64(symoff), io.SeekStart); err != nil {
return nil, err
}
all := make([]ImportedSymbol, 0)
diff --git a/src/net/sendfile_test.go b/src/net/sendfile_test.go
index 6edfb67..969c022 100644
--- a/src/net/sendfile_test.go
+++ b/src/net/sendfile_test.go
@@ -175,7 +175,7 @@
return
}
defer f.Close()
- if _, err := f.Seek(seekTo, os.SEEK_SET); err != nil {
+ if _, err := f.Seek(seekTo, io.SeekStart); err != nil {
errc <- err
return
}
diff --git a/src/testing/run_example_js.go b/src/testing/run_example_js.go
index adef951..f3a1120 100644
--- a/src/testing/run_example_js.go
+++ b/src/testing/run_example_js.go
@@ -36,7 +36,7 @@
// Restore stdout, get output and remove temporary file.
os.Stdout = stdout
var buf strings.Builder
- _, seekErr := f.Seek(0, os.SEEK_SET)
+ _, seekErr := f.Seek(0, io.SeekStart)
_, readErr := io.Copy(&buf, f)
out := buf.String()
f.Close()

To view, visit change 421634. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I497c9f617baefdeb273cd115b08b6e31bd10aad2
Gerrit-Change-Number: 421634
Gerrit-PatchSet: 1
Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
Gerrit-Reviewer: Ian Lance Taylor <ia...@google.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
Gerrit-Attention: Ian Lance Taylor <ia...@google.com>
Gerrit-Attention: Russ Cox <r...@golang.org>
Gerrit-MessageType: newchange

Brad Fitzpatrick (Gerrit)

unread,
Aug 5, 2022, 12:03:34 PM8/5/22
to Tobias Klauser, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, Gopher Robot, Russ Cox, golang-co...@googlegroups.com

Attention is currently required from: Ian Lance Taylor, Russ Cox, Tobias Klauser.

Patch set 1:Code-Review +2

View Change

    To view, visit change 421634. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I497c9f617baefdeb273cd115b08b6e31bd10aad2
    Gerrit-Change-Number: 421634
    Gerrit-PatchSet: 1
    Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Ian Lance Taylor <ia...@google.com>
    Gerrit-Reviewer: Russ Cox <r...@golang.org>
    Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Ian Lance Taylor <ia...@google.com>
    Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
    Gerrit-Attention: Russ Cox <r...@golang.org>
    Gerrit-Comment-Date: Fri, 05 Aug 2022 16:03:29 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Than McIntosh (Gerrit)

    unread,
    Aug 8, 2022, 11:33:34 AM8/8/22
    to Tobias Klauser, goph...@pubsubhelper.golang.org, Brad Fitzpatrick, Gopher Robot, Russ Cox, golang-co...@googlegroups.com

    Attention is currently required from: Ian Lance Taylor, Russ Cox, Tobias Klauser.

    Patch set 1:Code-Review +1

    View Change

      To view, visit change 421634. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I497c9f617baefdeb273cd115b08b6e31bd10aad2
      Gerrit-Change-Number: 421634
      Gerrit-PatchSet: 1
      Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
      Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Ian Lance Taylor <ia...@google.com>
      Gerrit-Reviewer: Russ Cox <r...@golang.org>
      Gerrit-Reviewer: Than McIntosh <th...@google.com>
      Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
      Gerrit-Attention: Ian Lance Taylor <ia...@google.com>
      Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
      Gerrit-Attention: Russ Cox <r...@golang.org>
      Gerrit-Comment-Date: Mon, 08 Aug 2022 15:33:28 +0000

      Dmitri Shuralyov (Gerrit)

      unread,
      Aug 8, 2022, 12:30:58 PM8/8/22
      to Tobias Klauser, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, Than McIntosh, Brad Fitzpatrick, Gopher Robot, Russ Cox, golang-co...@googlegroups.com

      Attention is currently required from: Ian Lance Taylor, Russ Cox, Tobias Klauser.

      Patch set 1:Code-Review +1

      View Change

        To view, visit change 421634. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I497c9f617baefdeb273cd115b08b6e31bd10aad2
        Gerrit-Change-Number: 421634
        Gerrit-PatchSet: 1
        Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@google.com>
        Gerrit-Reviewer: Russ Cox <r...@golang.org>
        Gerrit-Reviewer: Than McIntosh <th...@google.com>
        Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
        Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
        Gerrit-Attention: Ian Lance Taylor <ia...@google.com>
        Gerrit-Attention: Tobias Klauser <tobias....@gmail.com>
        Gerrit-Attention: Russ Cox <r...@golang.org>
        Gerrit-Comment-Date: Mon, 08 Aug 2022 16:30:53 +0000

        Tobias Klauser (Gerrit)

        unread,
        Aug 8, 2022, 1:02:02 PM8/8/22
        to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Dmitri Shuralyov, Dmitri Shuralyov, Than McIntosh, Brad Fitzpatrick, Gopher Robot, Russ Cox, golang-co...@googlegroups.com

        Tobias Klauser submitted this change.

        View Change


        Approvals: Than McIntosh: Looks good to me, but someone else must approve Dmitri Shuralyov: Looks good to me, but someone else must approve Tobias Klauser: Run TryBots Brad Fitzpatrick: Looks good to me, approved Gopher Robot: TryBots succeeded
        all: use io.Seek* instead of deprecated os.SEEK_*

        These are available since Go 1.7. The version used for bootstrap is Go
        1.17 for Go 1.20.

        For #44505

        Change-Id: I497c9f617baefdeb273cd115b08b6e31bd10aad2
        Reviewed-on: https://go-review.googlesource.com/c/go/+/421634
        Reviewed-by: Than McIntosh <th...@google.com>
        Run-TryBot: Tobias Klauser <tobias....@gmail.com>
        Reviewed-by: Brad Fitzpatrick <brad...@golang.org>
        TryBot-Result: Gopher Robot <go...@golang.org>
        Reviewed-by: Dmitri Shuralyov <dmit...@google.com>

        ---
        M src/cmd/compile/internal/typecheck/iimport.go
        M src/cmd/internal/archive/archive.go
        M src/cmd/link/internal/loader/loader.go
        M src/internal/pkgbits/decoder.go
        M src/internal/xcoff/ar.go
        M src/internal/xcoff/file.go
        M src/net/sendfile_test.go
        M src/testing/run_example_js.go
        8 files changed, 47 insertions(+), 27 deletions(-)

        diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go
        index 51978de..690daee 100644

        To view, visit change 421634. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I497c9f617baefdeb273cd115b08b6e31bd10aad2
        Gerrit-Change-Number: 421634
        Gerrit-PatchSet: 2
        Gerrit-Owner: Tobias Klauser <tobias....@gmail.com>
        Gerrit-Reviewer: Brad Fitzpatrick <brad...@golang.org>
        Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Ian Lance Taylor <ia...@google.com>
        Gerrit-Reviewer: Russ Cox <r...@golang.org>
        Gerrit-Reviewer: Than McIntosh <th...@google.com>
        Gerrit-Reviewer: Tobias Klauser <tobias....@gmail.com>
        Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
        Gerrit-MessageType: merged
        Reply all
        Reply to author
        Forward
        0 new messages