Merge pull request #1390 from armhold/lint

small cleanup
This commit is contained in:
Alexander Neumann 2017-10-28 09:54:35 +02:00
commit 8ce5d35543
9 changed files with 31 additions and 16 deletions

View file

@ -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. // 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) ctx, cancel := context.WithCancel(ctx)
defer cancel() 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) debug.Log("Save %v, name %v", h, name)
obj := be.bucket.Object(name) obj := be.bucket.Object(name)
_, err = obj.Attrs(ctx) _, err := obj.Attrs(ctx)
if err == nil { if err == nil {
debug.Log(" %v already exists", h) debug.Log(" %v already exists", h)
return errors.New("key already exists") return errors.New("key already exists")

View file

@ -118,7 +118,7 @@ func (b *Local) IsNotExist(err error) bool {
} }
// Save stores data in the backend at the handle. // 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) debug.Log("Save %v", h)
if err := h.Valid(); err != nil { if err := h.Valid(); err != nil {
return err return err

View file

@ -70,7 +70,7 @@ func writeCachedirTag(dir string) error {
debug.Log("Create CACHEDIR.TAG at %v", dir) debug.Log("Create CACHEDIR.TAG at %v", dir)
if _, err := f.Write([]byte(cachedirTagSignature)); err != nil { if _, err := f.Write([]byte(cachedirTagSignature)); err != nil {
f.Close() _ = f.Close()
return errors.Wrap(err, "Write") return errors.Wrap(err, "Write")
} }

View file

@ -65,7 +65,7 @@ func (c *Cache) Load(h restic.Handle, length int, offset int64) (io.ReadCloser,
if offset > 0 { if offset > 0 {
if _, err = f.Seek(offset, io.SeekStart); err != nil { if _, err = f.Seek(offset, io.SeekStart); err != nil {
f.Close() _ = f.Close()
return nil, err return nil, err
} }
} }

View file

@ -674,8 +674,8 @@ func checkPack(ctx context.Context, r restic.Repository, id restic.ID) error {
} }
defer func() { defer func() {
packfile.Close() _ = packfile.Close()
os.Remove(packfile.Name()) _ = os.Remove(packfile.Name())
}() }()
hrd := hashing.NewReader(rd, sha256.New()) hrd := hashing.NewReader(rd, sha256.New())

View file

@ -67,7 +67,7 @@ func readDirNames(dirname string) ([]string, error) {
return nil, errors.Wrap(err, "Open") return nil, errors.Wrap(err, "Open")
} }
names, err := f.Readdirnames(-1) names, err := f.Readdirnames(-1)
f.Close() _ = f.Close()
if err != nil { if err != nil {
return nil, errors.Wrap(err, "Readdirnames") return nil, errors.Wrap(err, "Readdirnames")
} }

View file

@ -109,7 +109,7 @@ func newLock(ctx context.Context, repo Repository, excl bool) (*Lock, error) {
time.Sleep(waitBeforeLockCheck) time.Sleep(waitBeforeLockCheck)
if err = lock.checkForOtherLocks(ctx); err != nil { if err = lock.checkForOtherLocks(ctx); err != nil {
lock.Unlock() _ = lock.Unlock()
return nil, err return nil, err
} }

View file

@ -253,8 +253,26 @@ func (node Node) createFileAt(ctx context.Context, path string, repo Repository,
if err != nil { if err != nil {
return errors.Wrap(err, "OpenFile") return errors.Wrap(err, "OpenFile")
} }
defer f.Close()
err = node.writeNodeContent(ctx, repo, f)
closeErr := f.Close()
if err != nil {
return err
}
if closeErr != nil {
return errors.Wrap(closeErr, "Close")
}
if node.Links > 1 {
idx.Add(node.Inode, node.DeviceID, path)
}
return nil
}
func (node Node) writeNodeContent(ctx context.Context, repo Repository, f *os.File) error {
var buf []byte var buf []byte
for _, id := range node.Content { for _, id := range node.Content {
size, err := repo.LookupBlobSize(id, DataBlob) size, err := repo.LookupBlobSize(id, DataBlob)
@ -279,10 +297,6 @@ func (node Node) createFileAt(ctx context.Context, path string, repo Repository,
} }
} }
if node.Links > 1 {
idx.Add(node.Inode, node.DeviceID, path)
}
return nil return nil
} }

View file

@ -51,7 +51,7 @@ func (res *Restorer) restoreTo(ctx context.Context, dst string, dir string, tree
debug.Log("SelectFilter returned %v %v", selectedForRestore, childMayBeSelected) debug.Log("SelectFilter returned %v %v", selectedForRestore, childMayBeSelected)
if selectedForRestore { if selectedForRestore {
err := res.restoreNodeTo(ctx, node, dir, dst, idx) err = res.restoreNodeTo(ctx, node, dir, dst, idx)
if err != nil { if err != nil {
return err return err
} }
@ -74,7 +74,8 @@ func (res *Restorer) restoreTo(ctx context.Context, dst string, dir string, tree
if selectedForRestore { if selectedForRestore {
// Restore directory timestamp at the end. If we would do it earlier, restoring files within // 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. // 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 return err
} }
} }