mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 18:04:55 +01:00
build: fix errors spotted by ineffassign linter
These were mostly caused by shadowing err and a good fraction of them will have caused errors not to be propagated properly.
This commit is contained in:
parent
790a8a9aed
commit
cb5bd47e61
@ -357,7 +357,8 @@ outer:
|
|||||||
buf := up.f.getUploadBlock()
|
buf := up.f.getUploadBlock()
|
||||||
|
|
||||||
// Read the chunk
|
// Read the chunk
|
||||||
n, err := io.ReadFull(up.in, buf)
|
var n int
|
||||||
|
n, err = io.ReadFull(up.in, buf)
|
||||||
if err == io.ErrUnexpectedEOF {
|
if err == io.ErrUnexpectedEOF {
|
||||||
fs.Debugf(up.o, "Read less than a full chunk, making this the last one.")
|
fs.Debugf(up.o, "Read less than a full chunk, making this the last one.")
|
||||||
buf = buf[:n]
|
buf = buf[:n]
|
||||||
@ -366,7 +367,6 @@ outer:
|
|||||||
} else if err == io.EOF {
|
} else if err == io.EOF {
|
||||||
fs.Debugf(up.o, "Could not read any more bytes, previous chunk was the last.")
|
fs.Debugf(up.o, "Could not read any more bytes, previous chunk was the last.")
|
||||||
up.f.putUploadBlock(buf)
|
up.f.putUploadBlock(buf)
|
||||||
hasMoreParts = false
|
|
||||||
err = nil
|
err = nil
|
||||||
break outer
|
break outer
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
1
backend/cache/cache.go
vendored
1
backend/cache/cache.go
vendored
@ -647,7 +647,6 @@ func (f *Fs) NewObject(remote string) (fs.Object, error) {
|
|||||||
|
|
||||||
// search for entry in source or temp fs
|
// search for entry in source or temp fs
|
||||||
var obj fs.Object
|
var obj fs.Object
|
||||||
err = nil
|
|
||||||
if f.tempWritePath != "" {
|
if f.tempWritePath != "" {
|
||||||
obj, err = f.tempFs.NewObject(remote)
|
obj, err = f.tempFs.NewObject(remote)
|
||||||
// not found in temp fs
|
// not found in temp fs
|
||||||
|
3
backend/cache/cache_internal_test.go
vendored
3
backend/cache/cache_internal_test.go
vendored
@ -988,8 +988,9 @@ func TestInternalUploadTempFileOperations(t *testing.T) {
|
|||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
_, err = os.Stat(path.Join(runInstance.tmpUploadDir, id, runInstance.encryptRemoteIfNeeded(t, "second/one")))
|
_, err = os.Stat(path.Join(runInstance.tmpUploadDir, id, runInstance.encryptRemoteIfNeeded(t, "second/one")))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
started, err := boltDb.SearchPendingUpload(runInstance.encryptRemoteIfNeeded(t, path.Join(id, "test/one")))
|
_, err = boltDb.SearchPendingUpload(runInstance.encryptRemoteIfNeeded(t, path.Join(id, "test/one")))
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
var started bool
|
||||||
started, err = boltDb.SearchPendingUpload(runInstance.encryptRemoteIfNeeded(t, path.Join(id, "second/one")))
|
started, err = boltDb.SearchPendingUpload(runInstance.encryptRemoteIfNeeded(t, path.Join(id, "second/one")))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, started)
|
require.False(t, started)
|
||||||
|
3
backend/cache/handle.go
vendored
3
backend/cache/handle.go
vendored
@ -446,7 +446,6 @@ func (w *worker) run() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = nil
|
|
||||||
} else {
|
} else {
|
||||||
if w.r.storage().HasChunk(w.r.cachedObject, chunkStart) {
|
if w.r.storage().HasChunk(w.r.cachedObject, chunkStart) {
|
||||||
continue
|
continue
|
||||||
@ -493,7 +492,7 @@ func (w *worker) download(chunkStart, chunkEnd int64, retry int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data = make([]byte, chunkEnd-chunkStart)
|
data = make([]byte, chunkEnd-chunkStart)
|
||||||
sourceRead := 0
|
var sourceRead int
|
||||||
sourceRead, err = io.ReadFull(w.rc, data)
|
sourceRead, err = io.ReadFull(w.rc, data)
|
||||||
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
|
if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF {
|
||||||
fs.Errorf(w, "failed to read chunk %v: %v", chunkStart, err)
|
fs.Errorf(w, "failed to read chunk %v: %v", chunkStart, err)
|
||||||
|
@ -151,6 +151,7 @@ func TestOpen(t *testing.T) {
|
|||||||
fd, err := o.Open()
|
fd, err := o.Open()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
data, err := ioutil.ReadAll(fd)
|
data, err := ioutil.ReadAll(fd)
|
||||||
|
require.NoError(t, err)
|
||||||
require.NoError(t, fd.Close())
|
require.NoError(t, fd.Close())
|
||||||
assert.Equal(t, "beetroot\n", string(data))
|
assert.Equal(t, "beetroot\n", string(data))
|
||||||
|
|
||||||
@ -158,6 +159,7 @@ func TestOpen(t *testing.T) {
|
|||||||
fd, err = o.Open(&fs.RangeOption{Start: 1, End: 5})
|
fd, err = o.Open(&fs.RangeOption{Start: 1, End: 5})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
data, err = ioutil.ReadAll(fd)
|
data, err = ioutil.ReadAll(fd)
|
||||||
|
require.NoError(t, err)
|
||||||
require.NoError(t, fd.Close())
|
require.NoError(t, fd.Close())
|
||||||
assert.Equal(t, "eetro", string(data))
|
assert.Equal(t, "eetro", string(data))
|
||||||
}
|
}
|
||||||
|
@ -593,7 +593,6 @@ func (o *Object) Hash(r hash.Type) (string, error) {
|
|||||||
o.fs.objectHashesMu.Unlock()
|
o.fs.objectHashesMu.Unlock()
|
||||||
|
|
||||||
if !o.modTime.Equal(oldtime) || oldsize != o.size || hashes == nil {
|
if !o.modTime.Equal(oldtime) || oldsize != o.size || hashes == nil {
|
||||||
hashes = make(map[hash.Type]string)
|
|
||||||
in, err := os.Open(o.path)
|
in, err := os.Open(o.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrap(err, "hash: failed to open")
|
return "", errors.Wrap(err, "hash: failed to open")
|
||||||
|
@ -44,9 +44,11 @@ func TestUpdatingCheck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fi, err := fd.Stat()
|
fi, err := fd.Stat()
|
||||||
|
require.NoError(t, err)
|
||||||
o := &Object{size: fi.Size(), modTime: fi.ModTime()}
|
o := &Object{size: fi.Size(), modTime: fi.ModTime()}
|
||||||
wrappedFd := readers.NewLimitedReadCloser(fd, -1)
|
wrappedFd := readers.NewLimitedReadCloser(fd, -1)
|
||||||
hash, err := hash.NewMultiHasherTypes(hash.Supported)
|
hash, err := hash.NewMultiHasherTypes(hash.Supported)
|
||||||
|
require.NoError(t, err)
|
||||||
in := localOpenFile{
|
in := localOpenFile{
|
||||||
o: o,
|
o: o,
|
||||||
in: wrappedFd,
|
in: wrappedFd,
|
||||||
|
@ -391,7 +391,8 @@ func (f *Fs) list(dir string, recurse bool, fn addEntryFn) error {
|
|||||||
err = fn(d)
|
err = fn(d)
|
||||||
} else {
|
} else {
|
||||||
// newObjectWithInfo does a full metadata read on 0 size objects which might be dynamic large objects
|
// newObjectWithInfo does a full metadata read on 0 size objects which might be dynamic large objects
|
||||||
o, err := f.newObjectWithInfo(remote, object)
|
var o fs.Object
|
||||||
|
o, err = f.newObjectWithInfo(remote, object)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -847,7 +848,7 @@ func urlEncode(str string) string {
|
|||||||
// container. It returns a string which prefixes current segments.
|
// container. It returns a string which prefixes current segments.
|
||||||
func (o *Object) updateChunks(in0 io.Reader, headers swift.Headers, size int64, contentType string) (string, error) {
|
func (o *Object) updateChunks(in0 io.Reader, headers swift.Headers, size int64, contentType string) (string, error) {
|
||||||
// Create the segmentsContainer if it doesn't exist
|
// Create the segmentsContainer if it doesn't exist
|
||||||
var err error = swift.ContainerNotFound
|
var err error
|
||||||
_, _, err = o.fs.c.Container(o.fs.segmentsContainer)
|
_, _, err = o.fs.c.Container(o.fs.segmentsContainer)
|
||||||
if err == swift.ContainerNotFound {
|
if err == swift.ContainerNotFound {
|
||||||
err = o.fs.c.ContainerCreate(o.fs.segmentsContainer, nil)
|
err = o.fs.c.ContainerCreate(o.fs.segmentsContainer, nil)
|
||||||
|
@ -149,6 +149,9 @@ func getAsset(project string, matchName *regexp.Regexp) (string, string) {
|
|||||||
log.Printf("Fetching asset info for %q from %q", project, url)
|
log.Printf("Fetching asset info for %q from %q", project, url)
|
||||||
user, pass := os.Getenv("GITHUB_USER"), os.Getenv("GITHUB_TOKEN")
|
user, pass := os.Getenv("GITHUB_USER"), os.Getenv("GITHUB_TOKEN")
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to make http request %q: %v", url, err)
|
||||||
|
}
|
||||||
if user != "" && pass != "" {
|
if user != "" && pass != "" {
|
||||||
log.Printf("Fetching using GITHUB_USER and GITHUB_TOKEN")
|
log.Printf("Fetching using GITHUB_USER and GITHUB_TOKEN")
|
||||||
req.SetBasicAuth(user, pass)
|
req.SetBasicAuth(user, pass)
|
||||||
|
@ -52,6 +52,9 @@ Print cache stats for a remote in JSON format
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m, err := fsCache.Stats()
|
m, err := fsCache.Stats()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
raw, err := json.MarshalIndent(m, "", " ")
|
raw, err := json.MarshalIndent(m, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -350,7 +350,6 @@ func (fsys *FS) Read(path string, buff []byte, ofst int64, fh uint64) (n int) {
|
|||||||
}
|
}
|
||||||
n, err := handle.ReadAt(buff, ofst)
|
n, err := handle.ReadAt(buff, ofst)
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
err = nil
|
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return translateError(err)
|
return translateError(err)
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func TestMemoryFs(t *testing.T) {
|
|||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
err = f.Rmdir("dir")
|
err = f.Rmdir("dir")
|
||||||
assert.Error(t, fs.ErrorDirNotFound)
|
assert.Equal(t, fs.ErrorDirNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMemoryObject(t *testing.T) {
|
func TestMemoryObject(t *testing.T) {
|
||||||
|
@ -288,9 +288,9 @@ func Deduplicate(f fs.Fs, mode DeduplicateMode) error {
|
|||||||
case DeduplicateRename:
|
case DeduplicateRename:
|
||||||
dedupeRename(remote, objs)
|
dedupeRename(remote, objs)
|
||||||
case DeduplicateLargest:
|
case DeduplicateLargest:
|
||||||
size, largest, largestIndex := int64(0), int64(-1), -1
|
largest, largestIndex := int64(-1), -1
|
||||||
for i, obj := range objs {
|
for i, obj := range objs {
|
||||||
size = obj.Size()
|
size := obj.Size()
|
||||||
if size > largest {
|
if size > largest {
|
||||||
largest, largestIndex = size, i
|
largest, largestIndex = size, i
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func test(fileName string, flags int, mode string) {
|
|||||||
_, readExistingErr = f.Read(buf)
|
_, readExistingErr = f.Read(buf)
|
||||||
|
|
||||||
// write some bytes
|
// write some bytes
|
||||||
n, writeExistingErr = f.Write([]byte("HEL"))
|
_, writeExistingErr = f.Write([]byte("HEL"))
|
||||||
|
|
||||||
// close
|
// close
|
||||||
err = f.Close()
|
err = f.Close()
|
||||||
|
@ -105,7 +105,7 @@ func TestReadFileHandleSeek(t *testing.T) {
|
|||||||
assert.Equal(t, "d", readString(t, fh, 1))
|
assert.Equal(t, "d", readString(t, fh, 1))
|
||||||
|
|
||||||
// Seek off the end
|
// Seek off the end
|
||||||
n, err = fh.Seek(100, io.SeekStart)
|
_, err = fh.Seek(100, io.SeekStart)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Get the error on read
|
// Get the error on read
|
||||||
@ -168,7 +168,7 @@ func TestReadFileHandleReadAt(t *testing.T) {
|
|||||||
|
|
||||||
// check noSeek gives an error
|
// check noSeek gives an error
|
||||||
fh.noSeek = true
|
fh.noSeek = true
|
||||||
n, err = fh.ReadAt(buf, 100)
|
_, err = fh.ReadAt(buf, 100)
|
||||||
assert.Equal(t, ESPIPE, err)
|
assert.Equal(t, ESPIPE, err)
|
||||||
|
|
||||||
// Properly close the file
|
// Properly close the file
|
||||||
@ -176,7 +176,7 @@ func TestReadFileHandleReadAt(t *testing.T) {
|
|||||||
|
|
||||||
// check reading on closed file
|
// check reading on closed file
|
||||||
fh.noSeek = true
|
fh.noSeek = true
|
||||||
n, err = fh.ReadAt(buf, 100)
|
_, err = fh.ReadAt(buf, 100)
|
||||||
assert.Equal(t, ECLOSED, err)
|
assert.Equal(t, ECLOSED, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ func (fh *RWFileHandle) openPending(truncate bool) (err error) {
|
|||||||
if o != nil && fh.file.rwOpens() == 0 {
|
if o != nil && fh.file.rwOpens() == 0 {
|
||||||
cacheObj, err := fh.d.vfs.cache.f.NewObject(fh.remote)
|
cacheObj, err := fh.d.vfs.cache.f.NewObject(fh.remote)
|
||||||
if err == nil && cacheObj != nil {
|
if err == nil && cacheObj != nil {
|
||||||
cacheObj, err = copyObj(fh.d.vfs.cache.f, cacheObj, fh.remote, o)
|
_, err = copyObj(fh.d.vfs.cache.f, cacheObj, fh.remote, o)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "open RW handle failed to update cached file")
|
return errors.Wrap(err, "open RW handle failed to update cached file")
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ func TestRWFileHandleSeek(t *testing.T) {
|
|||||||
assert.Equal(t, "d", rwReadString(t, fh, 1))
|
assert.Equal(t, "d", rwReadString(t, fh, 1))
|
||||||
|
|
||||||
// Seek off the end
|
// Seek off the end
|
||||||
n, err = fh.Seek(100, io.SeekStart)
|
_, err = fh.Seek(100, io.SeekStart)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Get the error on read
|
// Get the error on read
|
||||||
@ -215,7 +215,7 @@ func TestRWFileHandleReadAt(t *testing.T) {
|
|||||||
assert.NoError(t, fh.Close())
|
assert.NoError(t, fh.Close())
|
||||||
|
|
||||||
// check reading on closed file
|
// check reading on closed file
|
||||||
n, err = fh.ReadAt(buf, 100)
|
_, err = fh.ReadAt(buf, 100)
|
||||||
assert.Equal(t, ECLOSED, err)
|
assert.Equal(t, ECLOSED, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,6 +351,7 @@ func TestRWFileHandleMethodsWrite(t *testing.T) {
|
|||||||
|
|
||||||
// check vfs
|
// check vfs
|
||||||
root, err := vfs.Root()
|
root, err := vfs.Root()
|
||||||
|
require.NoError(t, err)
|
||||||
checkListing(t, root, []string{"file1,11,false"})
|
checkListing(t, root, []string{"file1,11,false"})
|
||||||
|
|
||||||
// check the underlying r.Fremote but not the modtime
|
// check the underlying r.Fremote but not the modtime
|
||||||
@ -399,6 +400,7 @@ func TestRWFileHandleWriteAt(t *testing.T) {
|
|||||||
|
|
||||||
// check vfs
|
// check vfs
|
||||||
root, err := vfs.Root()
|
root, err := vfs.Root()
|
||||||
|
require.NoError(t, err)
|
||||||
checkListing(t, root, []string{"file1,11,false"})
|
checkListing(t, root, []string{"file1,11,false"})
|
||||||
|
|
||||||
// check the underlying r.Fremote but not the modtime
|
// check the underlying r.Fremote but not the modtime
|
||||||
@ -427,6 +429,7 @@ func TestRWFileHandleWriteNoWrite(t *testing.T) {
|
|||||||
|
|
||||||
// check vfs
|
// check vfs
|
||||||
root, err := vfs.Root()
|
root, err := vfs.Root()
|
||||||
|
require.NoError(t, err)
|
||||||
checkListing(t, root, []string{"file1,0,false", "file2,0,false"})
|
checkListing(t, root, []string{"file1,0,false", "file2,0,false"})
|
||||||
|
|
||||||
// check the underlying r.Fremote but not the modtime
|
// check the underlying r.Fremote but not the modtime
|
||||||
|
@ -187,10 +187,10 @@ func TestVFSStatParent(t *testing.T) {
|
|||||||
assert.Equal(t, "/", node.Name())
|
assert.Equal(t, "/", node.Name())
|
||||||
assert.Equal(t, "not found", leaf)
|
assert.Equal(t, "not found", leaf)
|
||||||
|
|
||||||
node, leaf, err = vfs.StatParent("not found dir/not found")
|
_, _, err = vfs.StatParent("not found dir/not found")
|
||||||
assert.Equal(t, os.ErrNotExist, err)
|
assert.Equal(t, os.ErrNotExist, err)
|
||||||
|
|
||||||
node, leaf, err = vfs.StatParent("file1/under a file")
|
_, _, err = vfs.StatParent("file1/under a file")
|
||||||
assert.Equal(t, os.ErrExist, err)
|
assert.Equal(t, os.ErrExist, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,7 @@ func TestWriteFileHandleMethods(t *testing.T) {
|
|||||||
|
|
||||||
// check vfs
|
// check vfs
|
||||||
root, err := vfs.Root()
|
root, err := vfs.Root()
|
||||||
|
require.NoError(t, err)
|
||||||
checkListing(t, root, []string{"file1,5,false"})
|
checkListing(t, root, []string{"file1,5,false"})
|
||||||
|
|
||||||
// check the underlying r.Fremote but not the modtime
|
// check the underlying r.Fremote but not the modtime
|
||||||
@ -101,6 +102,7 @@ func TestWriteFileHandleMethods(t *testing.T) {
|
|||||||
// Check trying to open the file and writing it now it exists
|
// Check trying to open the file and writing it now it exists
|
||||||
// returns an error
|
// returns an error
|
||||||
h, err = vfs.OpenFile("file1", os.O_WRONLY|os.O_CREATE, 0777)
|
h, err = vfs.OpenFile("file1", os.O_WRONLY|os.O_CREATE, 0777)
|
||||||
|
require.NoError(t, err)
|
||||||
_, err = h.Write([]byte("hello1"))
|
_, err = h.Write([]byte("hello1"))
|
||||||
require.Equal(t, EPERM, err)
|
require.Equal(t, EPERM, err)
|
||||||
assert.NoError(t, h.Close())
|
assert.NoError(t, h.Close())
|
||||||
@ -115,6 +117,7 @@ func TestWriteFileHandleMethods(t *testing.T) {
|
|||||||
|
|
||||||
// Check opening the file with O_TRUNC and writing does work
|
// Check opening the file with O_TRUNC and writing does work
|
||||||
h, err = vfs.OpenFile("file1", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777)
|
h, err = vfs.OpenFile("file1", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777)
|
||||||
|
require.NoError(t, err)
|
||||||
_, err = h.WriteString("hello12")
|
_, err = h.WriteString("hello12")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.NoError(t, h.Close())
|
assert.NoError(t, h.Close())
|
||||||
@ -159,6 +162,7 @@ func TestWriteFileHandleWriteAt(t *testing.T) {
|
|||||||
|
|
||||||
// check vfs
|
// check vfs
|
||||||
root, err := vfs.Root()
|
root, err := vfs.Root()
|
||||||
|
require.NoError(t, err)
|
||||||
checkListing(t, root, []string{"file1,11,false"})
|
checkListing(t, root, []string{"file1,11,false"})
|
||||||
|
|
||||||
// check the underlying r.Fremote but not the modtime
|
// check the underlying r.Fremote but not the modtime
|
||||||
|
Loading…
Reference in New Issue
Block a user