From bcdebfb84e249738d6573fd678f8ff480f09e610 Mon Sep 17 00:00:00 2001 From: George Armhold Date: Wed, 25 Oct 2017 12:03:55 -0400 Subject: [PATCH] small cleanup: - be explicit when discarding returned errors from .Close(), etc. - remove named return values from funcs when naked return not used - fix some "err" shadowing when redeclaration not needed --- internal/backend/b2/b2.go | 4 ++-- internal/backend/local/local.go | 2 +- internal/cache/cache.go | 2 +- internal/cache/file.go | 2 +- internal/checker/checker.go | 4 ++-- internal/pipe/pipe.go | 2 +- internal/restic/lock.go | 2 +- internal/restic/restorer.go | 5 +++-- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/internal/backend/b2/b2.go b/internal/backend/b2/b2.go index 4c68953b4..4bca95653 100644 --- a/internal/backend/b2/b2.go +++ b/internal/backend/b2/b2.go @@ -218,7 +218,7 @@ func (be *b2Backend) Load(ctx context.Context, h restic.Handle, length int, offs } // Save stores data in the backend at the handle. -func (be *b2Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err error) { +func (be *b2Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (error) { ctx, cancel := context.WithCancel(ctx) defer cancel() @@ -233,7 +233,7 @@ func (be *b2Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (e debug.Log("Save %v, name %v", h, name) obj := be.bucket.Object(name) - _, err = obj.Attrs(ctx) + _, err := obj.Attrs(ctx) if err == nil { debug.Log(" %v already exists", h) return errors.New("key already exists") diff --git a/internal/backend/local/local.go b/internal/backend/local/local.go index b738bff13..e5012771c 100644 --- a/internal/backend/local/local.go +++ b/internal/backend/local/local.go @@ -118,7 +118,7 @@ func (b *Local) IsNotExist(err error) bool { } // Save stores data in the backend at the handle. -func (b *Local) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err error) { +func (b *Local) Save(ctx context.Context, h restic.Handle, rd io.Reader) (error) { debug.Log("Save %v", h) if err := h.Valid(); err != nil { return err diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 0268b242d..f83142e19 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -70,7 +70,7 @@ func writeCachedirTag(dir string) error { debug.Log("Create CACHEDIR.TAG at %v", dir) if _, err := f.Write([]byte(cachedirTagSignature)); err != nil { - f.Close() + _ = f.Close() return errors.Wrap(err, "Write") } diff --git a/internal/cache/file.go b/internal/cache/file.go index 5041ad965..f232bc7c1 100644 --- a/internal/cache/file.go +++ b/internal/cache/file.go @@ -65,7 +65,7 @@ func (c *Cache) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, if offset > 0 { if _, err = f.Seek(offset, io.SeekStart); err != nil { - f.Close() + _ = f.Close() return nil, err } } diff --git a/internal/checker/checker.go b/internal/checker/checker.go index e995634ed..c557ab475 100644 --- a/internal/checker/checker.go +++ b/internal/checker/checker.go @@ -674,8 +674,8 @@ func checkPack(ctx context.Context, r restic.Repository, id restic.ID) error { } defer func() { - packfile.Close() - os.Remove(packfile.Name()) + _ = packfile.Close() + _ = os.Remove(packfile.Name()) }() hrd := hashing.NewReader(rd, sha256.New()) diff --git a/internal/pipe/pipe.go b/internal/pipe/pipe.go index dfa140c0c..1cf7ff6bd 100644 --- a/internal/pipe/pipe.go +++ b/internal/pipe/pipe.go @@ -67,7 +67,7 @@ func readDirNames(dirname string) ([]string, error) { return nil, errors.Wrap(err, "Open") } names, err := f.Readdirnames(-1) - f.Close() + _ = f.Close() if err != nil { return nil, errors.Wrap(err, "Readdirnames") } diff --git a/internal/restic/lock.go b/internal/restic/lock.go index 0a4146174..177b0d707 100644 --- a/internal/restic/lock.go +++ b/internal/restic/lock.go @@ -109,7 +109,7 @@ func newLock(ctx context.Context, repo Repository, excl bool) (*Lock, error) { time.Sleep(waitBeforeLockCheck) if err = lock.checkForOtherLocks(ctx); err != nil { - lock.Unlock() + _ = lock.Unlock() return nil, err } diff --git a/internal/restic/restorer.go b/internal/restic/restorer.go index 9aafd5063..e3c4f4e36 100644 --- a/internal/restic/restorer.go +++ b/internal/restic/restorer.go @@ -51,7 +51,7 @@ func (res *Restorer) restoreTo(ctx context.Context, dst string, dir string, tree debug.Log("SelectFilter returned %v %v", selectedForRestore, childMayBeSelected) if selectedForRestore { - err := res.restoreNodeTo(ctx, node, dir, dst, idx) + err = res.restoreNodeTo(ctx, node, dir, dst, idx) if err != nil { return err } @@ -74,7 +74,8 @@ func (res *Restorer) restoreTo(ctx context.Context, dst string, dir string, tree if selectedForRestore { // Restore directory timestamp at the end. If we would do it earlier, restoring files within // the directory would overwrite the timestamp of the directory they are in. - if err := node.RestoreTimestamps(filepath.Join(dst, dir, node.Name)); err != nil { + err = node.RestoreTimestamps(filepath.Join(dst, dir, node.Name)) + if err != nil { return err } }