all: fix go-critic linter suggestions

This commit is contained in:
Oleg Kovalov 2018-08-04 12:16:43 +02:00 committed by Nick Craig-Wood
parent 44abf6473e
commit 06c9f76cd2
24 changed files with 66 additions and 66 deletions

View file

@ -831,7 +831,7 @@ func (o *Object) decodeMetaDataFromPropertiesResponse(info *azblob.BlobGetProper
} }
func (o *Object) decodeMetaDataFromBlob(info *azblob.BlobItem) (err error) { func (o *Object) decodeMetaDataFromBlob(info *azblob.BlobItem) (err error) {
o.md5 = string(info.Properties.ContentMD5[:]) o.md5 = string(info.Properties.ContentMD5)
o.mimeType = *info.Properties.ContentType o.mimeType = *info.Properties.ContentType
o.size = *info.Properties.ContentLength o.size = *info.Properties.ContentLength
o.modTime = info.Properties.LastModified o.modTime = info.Properties.LastModified

View file

@ -69,7 +69,7 @@ const versionFormat = "-v2006-01-02-150405.000"
func (t Timestamp) AddVersion(remote string) string { func (t Timestamp) AddVersion(remote string) string {
ext := path.Ext(remote) ext := path.Ext(remote)
base := remote[:len(remote)-len(ext)] base := remote[:len(remote)-len(ext)]
s := (time.Time)(t).Format(versionFormat) s := time.Time(t).Format(versionFormat)
// Replace the '.' with a '-' // Replace the '.' with a '-'
s = strings.Replace(s, ".", "-", -1) s = strings.Replace(s, ".", "-", -1)
return base + s + ext return base + s + ext
@ -102,20 +102,20 @@ func RemoveVersion(remote string) (t Timestamp, newRemote string) {
// IsZero returns true if the timestamp is unitialised // IsZero returns true if the timestamp is unitialised
func (t Timestamp) IsZero() bool { func (t Timestamp) IsZero() bool {
return (time.Time)(t).IsZero() return time.Time(t).IsZero()
} }
// Equal compares two timestamps // Equal compares two timestamps
// //
// If either are !IsZero then it returns false // If either are !IsZero then it returns false
func (t Timestamp) Equal(s Timestamp) bool { func (t Timestamp) Equal(s Timestamp) bool {
if (time.Time)(t).IsZero() { if time.Time(t).IsZero() {
return false return false
} }
if (time.Time)(s).IsZero() { if time.Time(s).IsZero() {
return false return false
} }
return (time.Time)(t).Equal((time.Time)(s)) return time.Time(t).Equal(time.Time(s))
} }
// File is info about a file // File is info about a file

View file

@ -668,7 +668,7 @@ func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error) {
Parameters: fieldsValue(), Parameters: fieldsValue(),
} }
replacedLeaf := replaceReservedChars(leaf) replacedLeaf := replaceReservedChars(leaf)
copy := api.CopyFile{ copyFile := api.CopyFile{
Name: replacedLeaf, Name: replacedLeaf,
Parent: api.Parent{ Parent: api.Parent{
ID: directoryID, ID: directoryID,
@ -677,7 +677,7 @@ func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error) {
var resp *http.Response var resp *http.Response
var info *api.Item var info *api.Item
err = f.pacer.Call(func() (bool, error) { err = f.pacer.Call(func() (bool, error) {
resp, err = f.srv.CallJSON(&opts, &copy, &info) resp, err = f.srv.CallJSON(&opts, &copyFile, &info)
return shouldRetry(resp, err) return shouldRetry(resp, err)
}) })
if err != nil { if err != nil {

View file

@ -24,7 +24,7 @@ func TestNewNameEncryptionMode(t *testing.T) {
{"off", NameEncryptionOff, ""}, {"off", NameEncryptionOff, ""},
{"standard", NameEncryptionStandard, ""}, {"standard", NameEncryptionStandard, ""},
{"obfuscate", NameEncryptionObfuscated, ""}, {"obfuscate", NameEncryptionObfuscated, ""},
{"potato", NameEncryptionMode(0), "Unknown file name encryption mode \"potato\""}, {"potato", NameEncryptionOff, "Unknown file name encryption mode \"potato\""},
} { } {
actual, actualErr := NewNameEncryptionMode(test.in) actual, actualErr := NewNameEncryptionMode(test.in)
assert.Equal(t, actual, test.expected) assert.Equal(t, actual, test.expected)

View file

@ -704,15 +704,15 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOptio
// newDir returns a dir with the Name decrypted // newDir returns a dir with the Name decrypted
func (f *Fs) newDir(dir fs.Directory) fs.Directory { func (f *Fs) newDir(dir fs.Directory) fs.Directory {
new := fs.NewDirCopy(dir) newDir := fs.NewDirCopy(dir)
remote := dir.Remote() remote := dir.Remote()
decryptedRemote, err := f.cipher.DecryptDirName(remote) decryptedRemote, err := f.cipher.DecryptDirName(remote)
if err != nil { if err != nil {
fs.Debugf(remote, "Undecryptable dir name: %v", err) fs.Debugf(remote, "Undecryptable dir name: %v", err)
} else { } else {
new.SetRemote(decryptedRemote) newDir.SetRemote(decryptedRemote)
} }
return new return newDir
} }
// ObjectInfo describes a wrapped fs.ObjectInfo for being the source // ObjectInfo describes a wrapped fs.ObjectInfo for being the source

View file

@ -838,7 +838,7 @@ func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error) {
id, _, _ := parseDirID(directoryID) id, _, _ := parseDirID(directoryID)
replacedLeaf := replaceReservedChars(leaf) replacedLeaf := replaceReservedChars(leaf)
copy := api.CopyItemRequest{ copyReq := api.CopyItemRequest{
Name: &replacedLeaf, Name: &replacedLeaf,
ParentReference: api.ItemReference{ ParentReference: api.ItemReference{
ID: id, ID: id,
@ -846,7 +846,7 @@ func (f *Fs) Copy(src fs.Object, remote string) (fs.Object, error) {
} }
var resp *http.Response var resp *http.Response
err = f.pacer.Call(func() (bool, error) { err = f.pacer.Call(func() (bool, error) {
resp, err = f.srv.CallJSON(&opts, &copy, nil) resp, err = f.srv.CallJSON(&opts, &copyReq, nil)
return shouldRetry(resp, err) return shouldRetry(resp, err)
}) })
if err != nil { if err != nil {

View file

@ -140,7 +140,7 @@ func TestQuickXorHashByBlock(t *testing.T) {
got := h.Sum(nil) got := h.Sum(nil)
want, err := base64.StdEncoding.DecodeString(test.out) want, err := base64.StdEncoding.DecodeString(test.out)
require.NoError(t, err, what) require.NoError(t, err, what)
assert.Equal(t, want, got[:], test.size, what) assert.Equal(t, want, got, test.size, what)
} }
} }
} }

View file

@ -29,7 +29,7 @@ func (c *Client) PerformDelete(url string) error {
if err != nil { if err != nil {
return err return err
} }
return errors.Errorf("delete error [%d]: %s", resp.StatusCode, string(body[:])) return errors.Errorf("delete error [%d]: %s", resp.StatusCode, string(body))
} }
return nil return nil
} }

View file

@ -34,7 +34,7 @@ func (c *Client) PerformDownload(url string, headers map[string]string) (out io.
if err != nil { if err != nil {
return nil, err return nil, err
} }
return nil, errors.Errorf("download error [%d]: %s", resp.StatusCode, string(body[:])) return nil, errors.Errorf("download error [%d]: %s", resp.StatusCode, string(body))
} }
return resp.Body, err return resp.Body, err
} }

View file

@ -28,7 +28,7 @@ func (c *Client) PerformMkdir(url string) (int, string, error) {
return 0, "", err return 0, "", err
} }
//third parameter is the json error response body //third parameter is the json error response body
return resp.StatusCode, string(body[:]), errors.Errorf("create folder error [%d]: %s", resp.StatusCode, string(body[:])) return resp.StatusCode, string(body), errors.Errorf("create folder error [%d]: %s", resp.StatusCode, string(body))
} }
return resp.StatusCode, "", nil return resp.StatusCode, "", nil
} }

View file

@ -32,7 +32,7 @@ func (c *Client) PerformUpload(url string, data io.Reader, contentType string) (
return err return err
} }
return errors.Errorf("upload error [%d]: %s", resp.StatusCode, string(body[:])) return errors.Errorf("upload error [%d]: %s", resp.StatusCode, string(body))
} }
return nil return nil
} }

View file

@ -189,7 +189,7 @@ var _ fusefs.NodeLinker = (*Dir)(nil)
// Link creates a new directory entry in the receiver based on an // Link creates a new directory entry in the receiver based on an
// existing Node. Receiver must be a directory. // existing Node. Receiver must be a directory.
func (d *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fusefs.Node) (new fusefs.Node, err error) { func (d *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fusefs.Node) (newNode fusefs.Node, err error) {
defer log.Trace(d, "req=%v, old=%v", req, old)("new=%v, err=%v", &new, &err) defer log.Trace(d, "req=%v, old=%v", req, old)("new=%v, err=%v", &newNode, &err)
return nil, fuse.ENOSYS return nil, fuse.ENOSYS
} }

View file

@ -143,7 +143,7 @@ func TestDirModTime(t *testing.T) {
run.skipIfNoFUSE(t) run.skipIfNoFUSE(t)
run.mkdir(t, "dir") run.mkdir(t, "dir")
mtime := time.Date(2012, 11, 18, 17, 32, 31, 0, time.UTC) mtime := time.Date(2012, time.November, 18, 17, 32, 31, 0, time.UTC)
err := os.Chtimes(run.path("dir"), mtime, mtime) err := os.Chtimes(run.path("dir"), mtime, mtime)
require.NoError(t, err) require.NoError(t, err)

View file

@ -16,7 +16,7 @@ func TestFileModTime(t *testing.T) {
run.createFile(t, "file", "123") run.createFile(t, "file", "123")
mtime := time.Date(2012, 11, 18, 17, 32, 31, 0, time.UTC) mtime := time.Date(2012, time.November, 18, 17, 32, 31, 0, time.UTC)
err := os.Chtimes(run.path("file"), mtime, mtime) err := os.Chtimes(run.path("file"), mtime, mtime)
require.NoError(t, err) require.NoError(t, err)
@ -41,7 +41,7 @@ func TestFileModTimeWithOpenWriters(t *testing.T) {
t.Skip("Skipping test on Windows") t.Skip("Skipping test on Windows")
} }
mtime := time.Date(2012, 11, 18, 17, 32, 31, 0, time.UTC) mtime := time.Date(2012, time.November, 18, 17, 32, 31, 0, time.UTC)
filepath := run.path("cp-archive-test") filepath := run.path("cp-archive-test")
f, err := osCreate(filepath) f, err := osCreate(filepath)

View file

@ -932,7 +932,7 @@ func NewRemoteName() (name string) {
// editOptions edits the options. If new is true then it just allows // editOptions edits the options. If new is true then it just allows
// entry and doesn't show any old values. // entry and doesn't show any old values.
func editOptions(ri *fs.RegInfo, name string, new bool) { func editOptions(ri *fs.RegInfo, name string, isNew bool) {
hasAdvanced := false hasAdvanced := false
for _, advanced := range []bool{false, true} { for _, advanced := range []bool{false, true} {
if advanced { if advanced {
@ -951,7 +951,7 @@ func editOptions(ri *fs.RegInfo, name string, new bool) {
} }
subProvider := getConfigData().MustValue(name, fs.ConfigProvider, "") subProvider := getConfigData().MustValue(name, fs.ConfigProvider, "")
if matchProvider(option.Provider, subProvider) { if matchProvider(option.Provider, subProvider) {
if !new { if !isNew {
fmt.Printf("Value %q = %q\n", option.Name, FileGet(name, option.Name)) fmt.Printf("Value %q = %q\n", option.Name, FileGet(name, option.Name))
fmt.Printf("Edit? (y/n)>\n") fmt.Printf("Edit? (y/n)>\n")
if !Confirm() { if !Confirm() {

View file

@ -7,9 +7,9 @@ import (
) )
var ( var (
_ Mapper = (Simple)(nil) _ Mapper = Simple(nil)
_ Getter = (Simple)(nil) _ Getter = Simple(nil)
_ Setter = (Simple)(nil) _ Setter = Simple(nil)
) )
func TestConfigMapGet(t *testing.T) { func TestConfigMapGet(t *testing.T) {

View file

@ -628,16 +628,16 @@ func (ft *Features) Mask(f Fs) *Features {
// Wrap makes a Copy of the features passed in, overriding the UnWrap/Wrap // Wrap makes a Copy of the features passed in, overriding the UnWrap/Wrap
// method only if available in f. // method only if available in f.
func (ft *Features) Wrap(f Fs) *Features { func (ft *Features) Wrap(f Fs) *Features {
copy := new(Features) ftCopy := new(Features)
*copy = *ft *ftCopy = *ft
if do, ok := f.(UnWrapper); ok { if do, ok := f.(UnWrapper); ok {
copy.UnWrap = do.UnWrap ftCopy.UnWrap = do.UnWrap
} }
if do, ok := f.(Wrapper); ok { if do, ok := f.(Wrapper); ok {
copy.WrapFs = do.WrapFs ftCopy.WrapFs = do.WrapFs
copy.SetWrapper = do.SetWrapper ftCopy.SetWrapper = do.SetWrapper
} }
return copy return ftCopy
} }
// WrapsFs adds extra information between `f` which wraps `w` // WrapsFs adds extra information between `f` which wraps `w`

View file

@ -53,7 +53,7 @@ func (err wrappedRetryError) Retry() bool {
} }
// Check interface // Check interface
var _ Retrier = wrappedRetryError{(error)(nil)} var _ Retrier = wrappedRetryError{error(nil)}
// RetryError makes an error which indicates it would like to be retried // RetryError makes an error which indicates it would like to be retried
func RetryError(err error) error { func RetryError(err error) error {
@ -97,7 +97,7 @@ func (err wrappedFatalError) Fatal() bool {
} }
// Check interface // Check interface
var _ Fataler = wrappedFatalError{(error)(nil)} var _ Fataler = wrappedFatalError{error(nil)}
// FatalError makes an error which indicates it is a fatal error and // FatalError makes an error which indicates it is a fatal error and
// the sync should stop. // the sync should stop.
@ -145,7 +145,7 @@ func (err wrappedNoRetryError) NoRetry() bool {
} }
// Check interface // Check interface
var _ NoRetrier = wrappedNoRetryError{(error)(nil)} var _ NoRetrier = wrappedNoRetryError{error(nil)}
// NoRetryError makes an error which indicates the sync shouldn't be // NoRetryError makes an error which indicates the sync shouldn't be
// retried. // retried.

View file

@ -15,26 +15,26 @@ func ptr(p interface{}) string {
func TestSetDefaults(t *testing.T) { func TestSetDefaults(t *testing.T) {
old := http.DefaultTransport.(*http.Transport) old := http.DefaultTransport.(*http.Transport)
new := new(http.Transport) newT := new(http.Transport)
setDefaults(new, old) setDefaults(newT, old)
// Can't use assert.Equal or reflect.DeepEqual for this as it has functions in // Can't use assert.Equal or reflect.DeepEqual for this as it has functions in
// Check functions by comparing the "%p" representations of them // Check functions by comparing the "%p" representations of them
assert.Equal(t, ptr(old.Proxy), ptr(new.Proxy), "when checking .Proxy") assert.Equal(t, ptr(old.Proxy), ptr(newT.Proxy), "when checking .Proxy")
assert.Equal(t, ptr(old.DialContext), ptr(new.DialContext), "when checking .DialContext") assert.Equal(t, ptr(old.DialContext), ptr(newT.DialContext), "when checking .DialContext")
// Check the other public fields // Check the other public fields
assert.Equal(t, ptr(old.Dial), ptr(new.Dial), "when checking .Dial") assert.Equal(t, ptr(old.Dial), ptr(newT.Dial), "when checking .Dial")
assert.Equal(t, ptr(old.DialTLS), ptr(new.DialTLS), "when checking .DialTLS") assert.Equal(t, ptr(old.DialTLS), ptr(newT.DialTLS), "when checking .DialTLS")
assert.Equal(t, old.TLSClientConfig, new.TLSClientConfig, "when checking .TLSClientConfig") assert.Equal(t, old.TLSClientConfig, newT.TLSClientConfig, "when checking .TLSClientConfig")
assert.Equal(t, old.TLSHandshakeTimeout, new.TLSHandshakeTimeout, "when checking .TLSHandshakeTimeout") assert.Equal(t, old.TLSHandshakeTimeout, newT.TLSHandshakeTimeout, "when checking .TLSHandshakeTimeout")
assert.Equal(t, old.DisableKeepAlives, new.DisableKeepAlives, "when checking .DisableKeepAlives") assert.Equal(t, old.DisableKeepAlives, newT.DisableKeepAlives, "when checking .DisableKeepAlives")
assert.Equal(t, old.DisableCompression, new.DisableCompression, "when checking .DisableCompression") assert.Equal(t, old.DisableCompression, newT.DisableCompression, "when checking .DisableCompression")
assert.Equal(t, old.MaxIdleConns, new.MaxIdleConns, "when checking .MaxIdleConns") assert.Equal(t, old.MaxIdleConns, newT.MaxIdleConns, "when checking .MaxIdleConns")
assert.Equal(t, old.MaxIdleConnsPerHost, new.MaxIdleConnsPerHost, "when checking .MaxIdleConnsPerHost") assert.Equal(t, old.MaxIdleConnsPerHost, newT.MaxIdleConnsPerHost, "when checking .MaxIdleConnsPerHost")
assert.Equal(t, old.IdleConnTimeout, new.IdleConnTimeout, "when checking .IdleConnTimeout") assert.Equal(t, old.IdleConnTimeout, newT.IdleConnTimeout, "when checking .IdleConnTimeout")
assert.Equal(t, old.ResponseHeaderTimeout, new.ResponseHeaderTimeout, "when checking .ResponseHeaderTimeout") assert.Equal(t, old.ResponseHeaderTimeout, newT.ResponseHeaderTimeout, "when checking .ResponseHeaderTimeout")
assert.Equal(t, old.ExpectContinueTimeout, new.ExpectContinueTimeout, "when checking .ExpectContinueTimeout") assert.Equal(t, old.ExpectContinueTimeout, newT.ExpectContinueTimeout, "when checking .ExpectContinueTimeout")
assert.Equal(t, old.TLSNextProto, new.TLSNextProto, "when checking .TLSNextProto") assert.Equal(t, old.TLSNextProto, newT.TLSNextProto, "when checking .TLSNextProto")
assert.Equal(t, old.MaxResponseHeaderBytes, new.MaxResponseHeaderBytes, "when checking .MaxResponseHeaderBytes") assert.Equal(t, old.MaxResponseHeaderBytes, newT.MaxResponseHeaderBytes, "when checking .MaxResponseHeaderBytes")
} }
func TestCleanAuth(t *testing.T) { func TestCleanAuth(t *testing.T) {

View file

@ -982,15 +982,15 @@ func Purge(f fs.Fs, dir string) error {
// Delete removes all the contents of a container. Unlike Purge, it // Delete removes all the contents of a container. Unlike Purge, it
// obeys includes and excludes. // obeys includes and excludes.
func Delete(f fs.Fs) error { func Delete(f fs.Fs) error {
delete := make(fs.ObjectsChan, fs.Config.Transfers) delChan := make(fs.ObjectsChan, fs.Config.Transfers)
delErr := make(chan error, 1) delErr := make(chan error, 1)
go func() { go func() {
delErr <- DeleteFiles(delete) delErr <- DeleteFiles(delChan)
}() }()
err := ListFn(f, func(o fs.Object) { err := ListFn(f, func(o fs.Object) {
delete <- o delChan <- o
}) })
close(delete) close(delChan)
delError := <-delErr delError := <-delErr
if err == nil { if err == nil {
err = delError err = delError

View file

@ -172,7 +172,7 @@ func newTest(pkg, remote string, subdir bool, fastlist bool) *test {
pkg: pkg, pkg: pkg,
remote: remote, remote: remote,
subdir: subdir, subdir: subdir,
cmdLine: []string{binary, "-test.timeout", (*timeout).String(), "-remote", remote}, cmdLine: []string{binary, "-test.timeout", timeout.String(), "-remote", remote},
try: 1, try: 1,
} }
if *fstest.Verbose { if *fstest.Verbose {
@ -226,7 +226,7 @@ func (t *test) findFailures() {
// nextCmdLine returns the next command line // nextCmdLine returns the next command line
func (t *test) nextCmdLine() []string { func (t *test) nextCmdLine() []string {
cmdLine := t.cmdLine[:] cmdLine := t.cmdLine
if t.runFlag != "" { if t.runFlag != "" {
cmdLine = append(cmdLine, "-test.run", t.runFlag) cmdLine = append(cmdLine, "-test.run", t.runFlag)
} }

View file

@ -261,9 +261,9 @@ func (fh *RWFileHandle) close() (err error) {
return nil return nil
} }
copy := false isCopied := false
if writer { if writer {
copy = fh.file.delWriter(fh, fh.modified()) isCopied = fh.file.delWriter(fh, fh.modified())
defer fh.file.finishWriterClose() defer fh.file.finishWriterClose()
} }
@ -293,7 +293,7 @@ func (fh *RWFileHandle) close() (err error) {
} }
} }
if copy { if isCopied {
// Transfer the temp file to the remote // Transfer the temp file to the remote
cacheObj, err := fh.d.vfs.cache.f.NewObject(fh.remote) cacheObj, err := fh.d.vfs.cache.f.NewObject(fh.remote)
if err != nil { if err != nil {

View file

@ -576,7 +576,7 @@ func TestRWFileModTimeWithOpenWriters(t *testing.T) {
defer r.Finalise() defer r.Finalise()
vfs, fh := rwHandleCreateWriteOnly(t, r) vfs, fh := rwHandleCreateWriteOnly(t, r)
mtime := time.Date(2012, 11, 18, 17, 32, 31, 0, time.UTC) mtime := time.Date(2012, time.November, 18, 17, 32, 31, 0, time.UTC)
_, err := fh.Write([]byte{104, 105}) _, err := fh.Write([]byte{104, 105})
require.NoError(t, err) require.NoError(t, err)

View file

@ -226,7 +226,7 @@ func TestWriteFileModTimeWithOpenWriters(t *testing.T) {
defer r.Finalise() defer r.Finalise()
vfs, fh := writeHandleCreate(t, r) vfs, fh := writeHandleCreate(t, r)
mtime := time.Date(2012, 11, 18, 17, 32, 31, 0, time.UTC) mtime := time.Date(2012, time.November, 18, 17, 32, 31, 0, time.UTC)
_, err := fh.Write([]byte{104, 105}) _, err := fh.Write([]byte{104, 105})
require.NoError(t, err) require.NoError(t, err)