1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-03-16 00:00:05 +01:00

Fix lint issues

This commit is contained in:
Aneesh Nireshwalia 2023-01-30 21:03:27 -07:00
parent 11d1b95f4d
commit 3f1673d6aa
3 changed files with 19 additions and 27 deletions

View file

@ -27,14 +27,14 @@ type Config struct {
IdleTimeout time.Duration `option:"idle-timeout" help:"Max time in seconds before closing idle connections. If no connections have been returned to the connection pool in the time given, the connection pool will be emptied. Set to 0 to keep connections indefinitely.(default: 60)"` IdleTimeout time.Duration `option:"idle-timeout" help:"Max time in seconds before closing idle connections. If no connections have been returned to the connection pool in the time given, the connection pool will be emptied. Set to 0 to keep connections indefinitely.(default: 60)"`
RequireMessageSigning bool `option:"require-message-signing" help:"Mandates message signing otherwise does not allow the connection. If this is false, messaging signing is just enabled and not enforced. (default: false)"` RequireMessageSigning bool `option:"require-message-signing" help:"Mandates message signing otherwise does not allow the connection. If this is false, messaging signing is just enabled and not enforced. (default: false)"`
Dialect uint16 `option:"dialect" help:"Force a specific dialect to be used. For SMB311 use '785', for SMB302 use '770', for SMB300 use '768', for SMB210 use '528', for SMB202 use '514', for SMB2 use '767'. If unspecfied (0), following dialects are tried in order - SMB311, SMB302, SMB300, SMB210, SMB202 (default: 0)"` Dialect uint16 `option:"dialect" help:"Force a specific dialect to be used. For SMB311 use '785', for SMB302 use '770', for SMB300 use '768', for SMB210 use '528', for SMB202 use '514', for SMB2 use '767'. If unspecfied (0), following dialects are tried in order - SMB311, SMB302, SMB300, SMB210, SMB202 (default: 0)"`
ClientGuid string `option:"client-guid" help:"A 16-byte GUID to uniquely identify a client. If not specific a random GUID is used. (default: \"\")"` ClientGUID string `option:"client-guid" help:"A 16-byte GUID to uniquely identify a client. If not specific a random GUID is used. (default: \"\")"`
} }
const ( const (
DefaultSmbPort int = 445 DefaultSmbPort int = 445 // DefaultSmbPort returns the default port for SMB
DefaultDomain string = "WORKGROUP" DefaultDomain string = "WORKGROUP" // DefaultDomain returns the default domain for SMB
DefaultConnections uint = 2 DefaultConnections uint = 2 // DefaultConnections returns the number of concurrent connections for SMB.
DefaultIdleTimeout time.Duration = 60 * time.Second DefaultIdleTimeout time.Duration = 60 * time.Second // DefaultIdleTimeout returns the default max time before closing idle connections for SMB.
) )
// NewConfig returns a new Config with the default values filled in. // NewConfig returns a new Config with the default values filled in.

View file

@ -70,16 +70,16 @@ func (b *Backend) dial(ctx context.Context, network, addr string) (*conn, error)
if err != nil { if err != nil {
return nil, err return nil, err
} }
var clientId [16]byte var clientID [16]byte
if b.ClientGuid != "" { if b.ClientGUID != "" {
copy(clientId[:], []byte(b.ClientGuid)) copy(clientID[:], []byte(b.ClientGUID))
} }
d := &smb2.Dialer{ d := &smb2.Dialer{
Negotiator: smb2.Negotiator{ Negotiator: smb2.Negotiator{
RequireMessageSigning: b.RequireMessageSigning, RequireMessageSigning: b.RequireMessageSigning,
SpecifiedDialect: b.Dialect, SpecifiedDialect: b.Dialect,
ClientGuid: clientId, ClientGuid: clientID,
}, },
Initiator: &smb2.NTLMInitiator{ Initiator: &smb2.NTLMInitiator{
User: b.User, User: b.User,

View file

@ -149,7 +149,7 @@ func (b *Backend) IsNotExist(err error) bool {
} }
// Join combines path components with slashes. // Join combines path components with slashes.
func (be *Backend) Join(p ...string) string { func (b *Backend) Join(p ...string) string {
return path.Join(p...) return path.Join(p...)
} }
@ -366,9 +366,9 @@ func (b *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.Fi
basedir, subdirs := b.Basedir(t) basedir, subdirs := b.Basedir(t)
if subdirs { if subdirs {
err = b.visitDirs(cn, ctx, basedir, fn) err = b.visitDirs(ctx, cn, basedir, fn)
} else { } else {
err = b.visitFiles(cn, ctx, basedir, fn, false) err = b.visitFiles(ctx, cn, basedir, fn, false)
} }
if b.IsNotExist(err) { if b.IsNotExist(err) {
@ -383,7 +383,7 @@ func (b *Backend) List(ctx context.Context, t restic.FileType, fn func(restic.Fi
// two levels of directory structure (including dir itself as the first level). // two levels of directory structure (including dir itself as the first level).
// Also, visitDirs assumes it sees a directory full of directories, while // Also, visitDirs assumes it sees a directory full of directories, while
// visitFiles wants a directory full or regular files. // visitFiles wants a directory full or regular files.
func (b *Backend) visitDirs(cn *conn, ctx context.Context, dir string, fn func(restic.FileInfo) error) error { func (b *Backend) visitDirs(ctx context.Context, cn *conn, dir string, fn func(restic.FileInfo) error) error {
d, err := cn.smbShare.Open(dir) d, err := cn.smbShare.Open(dir)
if err != nil { if err != nil {
return err return err
@ -402,7 +402,7 @@ func (b *Backend) visitDirs(cn *conn, ctx context.Context, dir string, fn func(r
} }
for _, f := range sub { for _, f := range sub {
err = b.visitFiles(cn, ctx, filepath.Join(dir, f), fn, true) err = b.visitFiles(ctx, cn, filepath.Join(dir, f), fn, true)
if err != nil { if err != nil {
return err return err
} }
@ -410,7 +410,7 @@ func (b *Backend) visitDirs(cn *conn, ctx context.Context, dir string, fn func(r
return ctx.Err() return ctx.Err()
} }
func (b *Backend) visitFiles(cn *conn, ctx context.Context, dir string, fn func(restic.FileInfo) error, ignoreNotADirectory bool) error { func (b *Backend) visitFiles(ctx context.Context, cn *conn, dir string, fn func(restic.FileInfo) error, ignoreNotADirectory bool) error {
d, err := cn.smbShare.Open(dir) d, err := cn.smbShare.Open(dir)
if err != nil { if err != nil {
return err return err
@ -473,16 +473,8 @@ func (b *Backend) Close() error {
return err return err
} }
var (
ErrExist = fs.ErrExist // "file already exists"
)
// PathError records an error and the operation and file path that caused it.
type PathError = fs.PathError
const ( const (
PathSeparator = '/' // OS-specific path separator pathSeparator = '/' // Always using '/' for SMB
PathListSeparator = ';' // OS-specific path list separator
) )
// CreateTemp creates a new temporary file in the directory dir, // CreateTemp creates a new temporary file in the directory dir,
@ -500,7 +492,7 @@ func (b *Backend) CreateTemp(cn *conn, dir, pattern string) (*smb2.File, error)
prefix, suffix, err := prefixAndSuffix(pattern) prefix, suffix, err := prefixAndSuffix(pattern)
if err != nil { if err != nil {
return nil, &PathError{Op: "createtemp", Path: pattern, Err: err} return nil, &fs.PathError{Op: "createtemp", Path: pattern, Err: err}
} }
prefix = joinPath(dir, prefix) prefix = joinPath(dir, prefix)
@ -513,7 +505,7 @@ func (b *Backend) CreateTemp(cn *conn, dir, pattern string) (*smb2.File, error)
if try++; try < 10000 { if try++; try < 10000 {
continue continue
} }
return nil, &PathError{Op: "createtemp", Path: prefix + "*" + suffix, Err: ErrExist} return nil, &fs.PathError{Op: "createtemp", Path: prefix + "*" + suffix, Err: fs.ErrExist}
} }
return f, err return f, err
} }
@ -555,7 +547,7 @@ func joinPath(dir, name string) string {
if len(dir) > 0 && IsPathSeparator(dir[len(dir)-1]) { if len(dir) > 0 && IsPathSeparator(dir[len(dir)-1]) {
return dir + name return dir + name
} }
return dir + string(PathSeparator) + name return dir + string(pathSeparator) + name
} }
// IsPathSeparator reports whether c is a directory separator character. // IsPathSeparator reports whether c is a directory separator character.