1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use io.SeekStart instead of os.SEEK_SET

Fixes linter warnings like this one:

> distribution/pull_v2.go:229:39: SA1019: os.SEEK_SET is deprecated: Use io.SeekStart, io.SeekCurrent, and io.SeekEnd.  (staticcheck)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2019-08-05 20:12:23 -07:00 committed by Sebastiaan van Stijn
parent 04129678a6
commit a7942baf76
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
3 changed files with 8 additions and 8 deletions

View file

@ -200,7 +200,7 @@ func (ld *v2LayerDescriptor) Download(ctx context.Context, progressOutput progre
} }
if offset != 0 { if offset != 0 {
_, err := layerDownload.Seek(offset, os.SEEK_SET) _, err := layerDownload.Seek(offset, io.SeekStart)
if err != nil { if err != nil {
if err := ld.truncateDownloadFile(); err != nil { if err := ld.truncateDownloadFile(); err != nil {
return nil, 0, xfer.DoNotRetry{Err: err} return nil, 0, xfer.DoNotRetry{Err: err}
@ -226,7 +226,7 @@ func (ld *v2LayerDescriptor) Download(ctx context.Context, progressOutput progre
// Restore the seek offset either at the beginning of the // Restore the seek offset either at the beginning of the
// stream, or just after the last byte we have from previous // stream, or just after the last byte we have from previous
// attempts. // attempts.
_, err = layerDownload.Seek(offset, os.SEEK_SET) _, err = layerDownload.Seek(offset, io.SeekStart)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
@ -272,7 +272,7 @@ func (ld *v2LayerDescriptor) Download(ctx context.Context, progressOutput progre
logrus.Debugf("Downloaded %s to tempfile %s", ld.ID(), tmpFile.Name()) logrus.Debugf("Downloaded %s to tempfile %s", ld.ID(), tmpFile.Name())
_, err = tmpFile.Seek(0, os.SEEK_SET) _, err = tmpFile.Seek(0, io.SeekStart)
if err != nil { if err != nil {
tmpFile.Close() tmpFile.Close()
if err := os.Remove(tmpFile.Name()); err != nil { if err := os.Remove(tmpFile.Name()); err != nil {
@ -310,7 +310,7 @@ func (ld *v2LayerDescriptor) truncateDownloadFile() error {
// Need a new hash context since we will be redoing the download // Need a new hash context since we will be redoing the download
ld.verifier = nil ld.verifier = nil
if _, err := ld.tmpFile.Seek(0, os.SEEK_SET); err != nil { if _, err := ld.tmpFile.Seek(0, io.SeekStart); err != nil {
logrus.Errorf("error seeking to beginning of download file: %v", err) logrus.Errorf("error seeking to beginning of download file: %v", err)
return err return err
} }

View file

@ -4,8 +4,8 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io"
"net/http" "net/http"
"os"
"runtime" "runtime"
"sort" "sort"
"strconv" "strconv"
@ -41,7 +41,7 @@ func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekClo
// We're done if the registry has this blob. // We're done if the registry has this blob.
if err == nil { if err == nil {
// Seek does an HTTP GET. If it succeeds, the blob really is accessible. // Seek does an HTTP GET. If it succeeds, the blob really is accessible.
if _, err = rsc.Seek(0, os.SEEK_SET); err == nil { if _, err = rsc.Seek(0, io.SeekStart); err == nil {
return rsc, nil return rsc, nil
} }
rsc.Close() rsc.Close()
@ -53,7 +53,7 @@ func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekClo
rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil) rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil)
// Seek does an HTTP GET. If it succeeds, the blob really is accessible. // Seek does an HTTP GET. If it succeeds, the blob really is accessible.
_, err = rsc.Seek(0, os.SEEK_SET) _, err = rsc.Seek(0, io.SeekStart)
if err == nil { if err == nil {
break break
} }

View file

@ -2217,7 +2217,7 @@ func (s *DockerDaemonSuite) TestDaemonDiscoveryBackendConfigReload(c *testing.T)
err = configFile.Truncate(0) err = configFile.Truncate(0)
assert.NilError(c, err) assert.NilError(c, err)
_, err = configFile.Seek(0, os.SEEK_SET) _, err = configFile.Seek(0, io.SeekStart)
assert.NilError(c, err) assert.NilError(c, err)
_, err = configFile.Write([]byte(daemonConfig)) _, err = configFile.Write([]byte(daemonConfig))