mirror of
https://github.com/restic/restic.git
synced 2025-03-16 00:00:05 +01:00
Use connection pointer directly in putConnection
Setting *pc back to nil is too easily defeated to be useful. This is more concise and prevents pointer from getting heap-allocated.
This commit is contained in:
parent
a3e9be1656
commit
c9dba2cdd7
2 changed files with 9 additions and 14 deletions
|
@ -188,12 +188,7 @@ func (b *Backend) getConnection(ctx context.Context, share string) (c *conn, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a SMB connection to the pool
|
// Return a SMB connection to the pool
|
||||||
//
|
func (b *Backend) putConnection(c *conn) {
|
||||||
// It nils the pointed to connection out so it can't be reused
|
|
||||||
func (b *Backend) putConnection(pc **conn) {
|
|
||||||
c := *pc
|
|
||||||
*pc = nil
|
|
||||||
|
|
||||||
var nopErr error
|
var nopErr error
|
||||||
if c.smbShare != nil {
|
if c.smbShare != nil {
|
||||||
// stat the current directory
|
// stat the current directory
|
||||||
|
|
|
@ -93,7 +93,7 @@ func open(ctx context.Context, cfg Config) (*Backend, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer b.putConnection(&cn)
|
defer b.putConnection(cn)
|
||||||
|
|
||||||
stat, err := cn.smbShare.Stat(l.Filename(restic.Handle{Type: restic.ConfigFile}))
|
stat, err := cn.smbShare.Stat(l.Filename(restic.Handle{Type: restic.ConfigFile}))
|
||||||
m := backend.DeriveModesFromFileInfo(stat, err)
|
m := backend.DeriveModesFromFileInfo(stat, err)
|
||||||
|
@ -124,7 +124,7 @@ func Create(ctx context.Context, cfg Config) (*Backend, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return b, err
|
return b, err
|
||||||
}
|
}
|
||||||
defer b.putConnection(&cn)
|
defer b.putConnection(cn)
|
||||||
|
|
||||||
// test if config file already exists
|
// test if config file already exists
|
||||||
_, err = cn.smbShare.Lstat(b.Filename(restic.Handle{Type: restic.ConfigFile}))
|
_, err = cn.smbShare.Lstat(b.Filename(restic.Handle{Type: restic.ConfigFile}))
|
||||||
|
@ -200,7 +200,7 @@ func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRea
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer b.putConnection(&cn)
|
defer b.putConnection(cn)
|
||||||
|
|
||||||
// create new file
|
// create new file
|
||||||
f, err := cn.smbShare.OpenFile(tmpFilename, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
|
f, err := cn.smbShare.OpenFile(tmpFilename, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
|
||||||
|
@ -297,7 +297,7 @@ func (b *Backend) openReader(ctx context.Context, h restic.Handle, length int, o
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer b.putConnection(&cn)
|
defer b.putConnection(cn)
|
||||||
|
|
||||||
b.sem.GetToken()
|
b.sem.GetToken()
|
||||||
f, err := cn.smbShare.Open(b.Filename(h))
|
f, err := cn.smbShare.Open(b.Filename(h))
|
||||||
|
@ -338,7 +338,7 @@ func (b *Backend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, e
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return restic.FileInfo{}, err
|
return restic.FileInfo{}, err
|
||||||
}
|
}
|
||||||
defer b.putConnection(&cn)
|
defer b.putConnection(cn)
|
||||||
|
|
||||||
fi, err := cn.smbShare.Stat(b.Filename(h))
|
fi, err := cn.smbShare.Stat(b.Filename(h))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -360,7 +360,7 @@ func (b *Backend) Remove(ctx context.Context, h restic.Handle) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer b.putConnection(&cn)
|
defer b.putConnection(cn)
|
||||||
|
|
||||||
// reset read-only flag
|
// reset read-only flag
|
||||||
err = cn.smbShare.Chmod(fn, 0666)
|
err = cn.smbShare.Chmod(fn, 0666)
|
||||||
|
@ -380,7 +380,7 @@ func (b *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.Fi
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer b.putConnection(&cn)
|
defer b.putConnection(cn)
|
||||||
|
|
||||||
basedir, subdirs := b.Basedir(t)
|
basedir, subdirs := b.Basedir(t)
|
||||||
if subdirs {
|
if subdirs {
|
||||||
|
@ -480,7 +480,7 @@ func (b *Backend) Delete(ctx context.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer b.putConnection(&cn)
|
defer b.putConnection(cn)
|
||||||
return cn.smbShare.RemoveAll(b.Location())
|
return cn.smbShare.RemoveAll(b.Location())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue