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 {
_, err := layerDownload.Seek(offset, os.SEEK_SET)
_, err := layerDownload.Seek(offset, io.SeekStart)
if err != nil {
if err := ld.truncateDownloadFile(); err != nil {
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
// stream, or just after the last byte we have from previous
// attempts.
_, err = layerDownload.Seek(offset, os.SEEK_SET)
_, err = layerDownload.Seek(offset, io.SeekStart)
if err != nil {
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())
_, err = tmpFile.Seek(0, os.SEEK_SET)
_, err = tmpFile.Seek(0, io.SeekStart)
if err != nil {
tmpFile.Close()
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
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)
return err
}

View File

@ -4,8 +4,8 @@ import (
"context"
"errors"
"fmt"
"io"
"net/http"
"os"
"runtime"
"sort"
"strconv"
@ -41,7 +41,7 @@ func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekClo
// We're done if the registry has this blob.
if err == nil {
// 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
}
rsc.Close()
@ -53,7 +53,7 @@ func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekClo
rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil)
// 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 {
break
}

View File

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