Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

Fix problems found with ineffassign

Nick Craig-Wood740b3f6ae2f8
diff --git a/cmd/mountlib/mounttest/read.go b/cmd/mountlib/mounttest/read.go
index 6489841aa..544357927 100644
--- a/cmd/mountlib/mounttest/read.go
+++ b/cmd/mountlib/mounttest/read.go
@@ -67,6 +67,7 @@ func TestReadChecksum(t *testing.T) {
_, err = fd.Seek(int64(len(b)-len(buf)), 0)
assert.NoError(t, err)
_, err = io.ReadFull(fd, buf)
+ assert.NoError(t, err)
// ensure we don't compare hashes
err = fd.Close()
assert.NoError(t, err)
diff --git a/cmd/mountlib/mounttest/write_unix.go b/cmd/mountlib/mounttest/write_unix.go
index 9fd279c8a..abb42b74a 100644
--- a/cmd/mountlib/mounttest/write_unix.go
+++ b/cmd/mountlib/mounttest/write_unix.go
@@ -39,7 +39,7 @@ func TestWriteFileDoubleClose(t *testing.T) {
assert.NoError(t, err)
// write to the other dup - should produce an error
- n, err = syscall.Write(fd2, buf)
+ _, err = syscall.Write(fd2, buf)
assert.Error(t, err, "input/output error")
// close the dup - should produce an error
diff --git a/cmd/mountlib/read.go b/cmd/mountlib/read.go
index 7be50c88d..6019b1b18 100644
--- a/cmd/mountlib/read.go
+++ b/cmd/mountlib/read.go
@@ -139,7 +139,6 @@ func (fh *ReadFileHandle) Read(reqSize, reqOffset int64) (respData []byte, err e
// file in an unchanged state.
if reqOffset >= fh.o.Size() {
fs.Debugf(fh.o, "ReadFileHandle.Read attempt to read beyond end of file: %d > %d", reqOffset, fh.o.Size())
- respData = nil
return nil, nil
}
// Otherwise do the seek
diff --git a/crypt/cipher_test.go b/crypt/cipher_test.go
index 34f41f67c..2bb322ad4 100644
--- a/crypt/cipher_test.go
+++ b/crypt/cipher_test.go
@@ -689,7 +689,7 @@ func TestRandomSource(t *testing.T) {
buf := make([]byte, 16)
_, _ = source.Read(buf)
sink = newRandomSource(1E8)
- n, err = io.Copy(sink, source)
+ _, err = io.Copy(sink, source)
assert.Error(t, err, "Error in stream")
}
@@ -966,6 +966,7 @@ func TestNewDecrypterSeek(t *testing.T) {
// Now try decoding it with a single open and lots of seeks
rc, err := c.DecryptDataSeek(open, 0)
+ assert.NoError(t, err)
for _, offset := range trials {
_, err := rc.Seek(int64(offset), 0)
assert.NoError(t, err)
@@ -1050,6 +1051,7 @@ func TestDecrypterClose(t *testing.T) {
// close before reading
assert.Equal(t, nil, fh.err)
err = fh.Close()
+ assert.NoError(t, err)
assert.Equal(t, ErrorFileClosed, fh.err)
assert.Equal(t, 1, cd.closed)
@@ -1070,6 +1072,7 @@ func TestDecrypterClose(t *testing.T) {
assert.Equal(t, []byte{1}, out)
assert.Equal(t, io.EOF, fh.err)
err = fh.Close()
+ assert.NoError(t, err)
assert.Equal(t, ErrorFileClosed, fh.err)
assert.Equal(t, 1, cd.closed)
}
diff --git a/fs/accounting.go b/fs/accounting.go
index 4312b2ac7..26a437319 100644
--- a/fs/accounting.go
+++ b/fs/accounting.go
@@ -474,11 +474,9 @@ func (acc *Account) Progress() (bytes, size int64) {
return 0, 0
}
acc.statmu.Lock()
- if bytes > size {
- size = 0
- }
- defer acc.statmu.Unlock()
- return acc.bytes, acc.size
+ bytes, size = acc.bytes, acc.size
+ acc.statmu.Unlock()
+ return bytes, size
}
// Speed returns the speed of the current file transfer
@@ -528,7 +526,7 @@ func (acc *Account) ETA() (eta time.Duration, ok bool) {
// String produces stats for this file
func (acc *Account) String() string {
a, b := acc.Progress()
- avg, cur := acc.Speed()
+ _, cur := acc.Speed()
eta, etaok := acc.ETA()
etas := "-"
if etaok {
@@ -545,7 +543,7 @@ func (acc *Account) String() string {
}
if Config.DataRateUnit == "bits" {
- cur, avg = cur*8, avg*8
+ cur = cur * 8
}
done := ""
diff --git a/fs/config.go b/fs/config.go
index 3c2edbac3..940d766b6 100644
--- a/fs/config.go
+++ b/fs/config.go
@@ -472,7 +472,6 @@ func loadConfigFile() (*goconfig.ConfigFile, error) {
err := setConfigPassword(envpw)
if err != nil {
fmt.Println("Using RCLONE_CONFIG_PASS returned:", err)
- envpw = ""
} else {
Debugf(nil, "Using RCLONE_CONFIG_PASS password.")
}
diff --git a/fs/test_all.go b/fs/test_all.go
index eca634d4a..02d1260df 100644
--- a/fs/test_all.go
+++ b/fs/test_all.go
@@ -139,6 +139,9 @@ func (t *test) cleanFs() error {
return err
}
dirs, err := fs.NewLister().SetLevel(1).Start(f, "").GetDirs()
+ if err != nil {
+ return err
+ }
for _, dir := range dirs {
if fstest.MatchTestRemote.MatchString(dir.Name) {
log.Printf("Purging %s%s", t.remote, dir.Name)
diff --git a/fstest/fstests/fstests.go b/fstest/fstests/fstests.go
index 6448531e8..fef3c55f6 100644
--- a/fstest/fstests/fstests.go
+++ b/fstest/fstests/fstests.go
@@ -216,14 +216,14 @@ func findObject(t *testing.T, Name string) fs.Object {
}
func testPut(t *testing.T, file *fstest.Item) string {
+ tries := 1
+ const maxTries = 10
again:
contents := fstest.RandomString(100)
buf := bytes.NewBufferString(contents)
hash := fs.NewMultiHasher()
in := io.TeeReader(buf, hash)
- tries := 1
- const maxTries = 10
file.Size = int64(buf.Len())
obji := fs.NewStaticObjectInfo(file.Path, file.ModTime, file.Size, true, nil, nil)
obj, err := remote.Put(in, obji)
@@ -274,11 +274,11 @@ func TestFsPutError(t *testing.T) {
in := io.MultiReader(buf, er)
obji := fs.NewStaticObjectInfo(file2.Path, file2.ModTime, 100, true, nil, nil)
- obj, err := remote.Put(in, obji)
+ _, err := remote.Put(in, obji)
// assert.Nil(t, obj) - FIXME some remotes return the object even on nil
assert.NotNil(t, err)
- obj, err = remote.NewObject(file2.Path)
+ obj, err := remote.NewObject(file2.Path)
assert.Nil(t, obj)
assert.Equal(t, fs.ErrorObjectNotFound, err)
}
diff --git a/yandex/yandex.go b/yandex/yandex.go
index 2a5b8bc9b..861749125 100644
--- a/yandex/yandex.go
+++ b/yandex/yandex.go
@@ -157,7 +157,7 @@ func (f *Fs) setRoot(root string) {
f.root = strings.Trim(root, "/")
//Set disk root path.
//Adding "disk:" to root path as all paths on disk start with it
- var diskRoot = ""
+ var diskRoot string
if f.root == "" {
diskRoot = "disk:/"
} else {