mirror of
https://github.com/rclone/rclone
synced 2025-01-10 13:06:26 +01:00
Fix problems found with ineffassign
This commit is contained in:
parent
28fcc53e45
commit
740b3f6ae2
@ -67,6 +67,7 @@ func TestReadChecksum(t *testing.T) {
|
|||||||
_, err = fd.Seek(int64(len(b)-len(buf)), 0)
|
_, err = fd.Seek(int64(len(b)-len(buf)), 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = io.ReadFull(fd, buf)
|
_, err = io.ReadFull(fd, buf)
|
||||||
|
assert.NoError(t, err)
|
||||||
// ensure we don't compare hashes
|
// ensure we don't compare hashes
|
||||||
err = fd.Close()
|
err = fd.Close()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -39,7 +39,7 @@ func TestWriteFileDoubleClose(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// write to the other dup - should produce an error
|
// 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")
|
assert.Error(t, err, "input/output error")
|
||||||
|
|
||||||
// close the dup - should produce an error
|
// close the dup - should produce an error
|
||||||
|
@ -139,7 +139,6 @@ func (fh *ReadFileHandle) Read(reqSize, reqOffset int64) (respData []byte, err e
|
|||||||
// file in an unchanged state.
|
// file in an unchanged state.
|
||||||
if reqOffset >= fh.o.Size() {
|
if reqOffset >= fh.o.Size() {
|
||||||
fs.Debugf(fh.o, "ReadFileHandle.Read attempt to read beyond end of file: %d > %d", 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
|
return nil, nil
|
||||||
}
|
}
|
||||||
// Otherwise do the seek
|
// Otherwise do the seek
|
||||||
|
@ -689,7 +689,7 @@ func TestRandomSource(t *testing.T) {
|
|||||||
buf := make([]byte, 16)
|
buf := make([]byte, 16)
|
||||||
_, _ = source.Read(buf)
|
_, _ = source.Read(buf)
|
||||||
sink = newRandomSource(1E8)
|
sink = newRandomSource(1E8)
|
||||||
n, err = io.Copy(sink, source)
|
_, err = io.Copy(sink, source)
|
||||||
assert.Error(t, err, "Error in stream")
|
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
|
// Now try decoding it with a single open and lots of seeks
|
||||||
rc, err := c.DecryptDataSeek(open, 0)
|
rc, err := c.DecryptDataSeek(open, 0)
|
||||||
|
assert.NoError(t, err)
|
||||||
for _, offset := range trials {
|
for _, offset := range trials {
|
||||||
_, err := rc.Seek(int64(offset), 0)
|
_, err := rc.Seek(int64(offset), 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -1050,6 +1051,7 @@ func TestDecrypterClose(t *testing.T) {
|
|||||||
// close before reading
|
// close before reading
|
||||||
assert.Equal(t, nil, fh.err)
|
assert.Equal(t, nil, fh.err)
|
||||||
err = fh.Close()
|
err = fh.Close()
|
||||||
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, ErrorFileClosed, fh.err)
|
assert.Equal(t, ErrorFileClosed, fh.err)
|
||||||
assert.Equal(t, 1, cd.closed)
|
assert.Equal(t, 1, cd.closed)
|
||||||
|
|
||||||
@ -1070,6 +1072,7 @@ func TestDecrypterClose(t *testing.T) {
|
|||||||
assert.Equal(t, []byte{1}, out)
|
assert.Equal(t, []byte{1}, out)
|
||||||
assert.Equal(t, io.EOF, fh.err)
|
assert.Equal(t, io.EOF, fh.err)
|
||||||
err = fh.Close()
|
err = fh.Close()
|
||||||
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, ErrorFileClosed, fh.err)
|
assert.Equal(t, ErrorFileClosed, fh.err)
|
||||||
assert.Equal(t, 1, cd.closed)
|
assert.Equal(t, 1, cd.closed)
|
||||||
}
|
}
|
||||||
|
@ -474,11 +474,9 @@ func (acc *Account) Progress() (bytes, size int64) {
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
acc.statmu.Lock()
|
acc.statmu.Lock()
|
||||||
if bytes > size {
|
bytes, size = acc.bytes, acc.size
|
||||||
size = 0
|
acc.statmu.Unlock()
|
||||||
}
|
return bytes, size
|
||||||
defer acc.statmu.Unlock()
|
|
||||||
return acc.bytes, acc.size
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Speed returns the speed of the current file transfer
|
// 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
|
// String produces stats for this file
|
||||||
func (acc *Account) String() string {
|
func (acc *Account) String() string {
|
||||||
a, b := acc.Progress()
|
a, b := acc.Progress()
|
||||||
avg, cur := acc.Speed()
|
_, cur := acc.Speed()
|
||||||
eta, etaok := acc.ETA()
|
eta, etaok := acc.ETA()
|
||||||
etas := "-"
|
etas := "-"
|
||||||
if etaok {
|
if etaok {
|
||||||
@ -545,7 +543,7 @@ func (acc *Account) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if Config.DataRateUnit == "bits" {
|
if Config.DataRateUnit == "bits" {
|
||||||
cur, avg = cur*8, avg*8
|
cur = cur * 8
|
||||||
}
|
}
|
||||||
|
|
||||||
done := ""
|
done := ""
|
||||||
|
@ -472,7 +472,6 @@ func loadConfigFile() (*goconfig.ConfigFile, error) {
|
|||||||
err := setConfigPassword(envpw)
|
err := setConfigPassword(envpw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Using RCLONE_CONFIG_PASS returned:", err)
|
fmt.Println("Using RCLONE_CONFIG_PASS returned:", err)
|
||||||
envpw = ""
|
|
||||||
} else {
|
} else {
|
||||||
Debugf(nil, "Using RCLONE_CONFIG_PASS password.")
|
Debugf(nil, "Using RCLONE_CONFIG_PASS password.")
|
||||||
}
|
}
|
||||||
|
@ -139,6 +139,9 @@ func (t *test) cleanFs() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
dirs, err := fs.NewLister().SetLevel(1).Start(f, "").GetDirs()
|
dirs, err := fs.NewLister().SetLevel(1).Start(f, "").GetDirs()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for _, dir := range dirs {
|
for _, dir := range dirs {
|
||||||
if fstest.MatchTestRemote.MatchString(dir.Name) {
|
if fstest.MatchTestRemote.MatchString(dir.Name) {
|
||||||
log.Printf("Purging %s%s", t.remote, dir.Name)
|
log.Printf("Purging %s%s", t.remote, dir.Name)
|
||||||
|
@ -216,14 +216,14 @@ func findObject(t *testing.T, Name string) fs.Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testPut(t *testing.T, file *fstest.Item) string {
|
func testPut(t *testing.T, file *fstest.Item) string {
|
||||||
|
tries := 1
|
||||||
|
const maxTries = 10
|
||||||
again:
|
again:
|
||||||
contents := fstest.RandomString(100)
|
contents := fstest.RandomString(100)
|
||||||
buf := bytes.NewBufferString(contents)
|
buf := bytes.NewBufferString(contents)
|
||||||
hash := fs.NewMultiHasher()
|
hash := fs.NewMultiHasher()
|
||||||
in := io.TeeReader(buf, hash)
|
in := io.TeeReader(buf, hash)
|
||||||
|
|
||||||
tries := 1
|
|
||||||
const maxTries = 10
|
|
||||||
file.Size = int64(buf.Len())
|
file.Size = int64(buf.Len())
|
||||||
obji := fs.NewStaticObjectInfo(file.Path, file.ModTime, file.Size, true, nil, nil)
|
obji := fs.NewStaticObjectInfo(file.Path, file.ModTime, file.Size, true, nil, nil)
|
||||||
obj, err := remote.Put(in, obji)
|
obj, err := remote.Put(in, obji)
|
||||||
@ -274,11 +274,11 @@ func TestFsPutError(t *testing.T) {
|
|||||||
in := io.MultiReader(buf, er)
|
in := io.MultiReader(buf, er)
|
||||||
|
|
||||||
obji := fs.NewStaticObjectInfo(file2.Path, file2.ModTime, 100, true, nil, nil)
|
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.Nil(t, obj) - FIXME some remotes return the object even on nil
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
|
||||||
obj, err = remote.NewObject(file2.Path)
|
obj, err := remote.NewObject(file2.Path)
|
||||||
assert.Nil(t, obj)
|
assert.Nil(t, obj)
|
||||||
assert.Equal(t, fs.ErrorObjectNotFound, err)
|
assert.Equal(t, fs.ErrorObjectNotFound, err)
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ func (f *Fs) setRoot(root string) {
|
|||||||
f.root = strings.Trim(root, "/")
|
f.root = strings.Trim(root, "/")
|
||||||
//Set disk root path.
|
//Set disk root path.
|
||||||
//Adding "disk:" to root path as all paths on disk start with it
|
//Adding "disk:" to root path as all paths on disk start with it
|
||||||
var diskRoot = ""
|
var diskRoot string
|
||||||
if f.root == "" {
|
if f.root == "" {
|
||||||
diskRoot = "disk:/"
|
diskRoot = "disk:/"
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user