mirror of
https://github.com/restic/restic.git
synced 2025-03-09 00:00:02 +01:00
Fix lint and remove function
This commit is contained in:
parent
97b77eec77
commit
b6123d3080
3 changed files with 11 additions and 10 deletions
|
@ -101,7 +101,7 @@ func (b *Local) Save(_ context.Context, h backend.Handle, rd backend.RewindReade
|
|||
Rename: os.Rename,
|
||||
FsyncDir: fsyncDir,
|
||||
SetFileReadonly: func(name string) error {
|
||||
return os.Chmod(name, b.Modes.File)
|
||||
return setFileReadonly(name, b.Modes.File)
|
||||
},
|
||||
DirMode: b.Modes.Dir,
|
||||
FileMode: b.Modes.File,
|
||||
|
@ -132,7 +132,7 @@ func (b *Local) Stat(_ context.Context, h backend.Handle) (backend.FileInfo, err
|
|||
|
||||
// Remove removes the blob with the given name and type.
|
||||
func (b *Local) Remove(_ context.Context, h backend.Handle) error {
|
||||
return util.Remove(b.Filename(h), os.Chmod)
|
||||
return util.Remove(b.Filename(h), setFileReadonly, os.Remove)
|
||||
}
|
||||
|
||||
// List runs fn for each file in the backend which has the type t. When an
|
||||
|
@ -142,7 +142,7 @@ func (b *Local) List(ctx context.Context, t backend.FileType, fn func(backend.Fi
|
|||
return os.Open(name)
|
||||
}
|
||||
basedir, subdirs := b.Basedir(t)
|
||||
return util.List(ctx, basedir, subdirs, openFunc, t, fn)
|
||||
return util.List(ctx, basedir, subdirs, openFunc, fn)
|
||||
}
|
||||
|
||||
// Delete removes the repository and all files.
|
||||
|
|
|
@ -147,10 +147,11 @@ func (b *SMB) Save(_ context.Context, h backend.Handle, rd backend.RewindReader)
|
|||
defer b.putConnection(cn)
|
||||
|
||||
fileName := b.Filename(h)
|
||||
// For SMB, we use full path to the file for the temp file name
|
||||
tmpFilename := fileName + "-restic-temp-" + tempSuffix()
|
||||
|
||||
saveOptions := util.SaveOptions{
|
||||
OpenTempFile: func(dir, name string) (util.File, error) {
|
||||
OpenTempFile: func(_, name string) (util.File, error) {
|
||||
return cn.smbShare.OpenFile(name, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
|
||||
},
|
||||
MkDir: func(dir string) error {
|
||||
|
@ -161,7 +162,7 @@ func (b *SMB) Save(_ context.Context, h backend.Handle, rd backend.RewindReader)
|
|||
return false
|
||||
},
|
||||
Rename: cn.smbShare.Rename,
|
||||
FsyncDir: func(dir string) error {
|
||||
FsyncDir: func(_ string) error {
|
||||
return nil
|
||||
},
|
||||
SetFileReadonly: func(name string) error {
|
||||
|
@ -216,7 +217,7 @@ func (b *SMB) Remove(_ context.Context, h backend.Handle) error {
|
|||
return err
|
||||
}
|
||||
defer b.putConnection(cn)
|
||||
return util.Remove(b.Filename(h), cn.smbShare.Chmod)
|
||||
return util.Remove(b.Filename(h), cn.smbShare.Chmod, cn.smbShare.Remove)
|
||||
}
|
||||
|
||||
// List runs fn for each file in the backend which has the type t. When an
|
||||
|
@ -231,7 +232,7 @@ func (b *SMB) List(ctx context.Context, t backend.FileType, fn func(backend.File
|
|||
return cn.smbShare.Open(name)
|
||||
}
|
||||
basedir, subdirs := b.Basedir(t)
|
||||
return util.List(ctx, basedir, subdirs, openFunc, t, fn)
|
||||
return util.List(ctx, basedir, subdirs, openFunc, fn)
|
||||
}
|
||||
|
||||
// Delete removes the repository and all files.
|
||||
|
|
|
@ -205,19 +205,19 @@ func Stat(statFn func(string) (os.FileInfo, error), fileName, handleName string)
|
|||
}
|
||||
|
||||
// Remove removes the blob with the given name and type.
|
||||
func Remove(filename string, chmodfn func(string, os.FileMode) error) error {
|
||||
func Remove(filename string, chmodfn func(string, os.FileMode) error, removeFn func(string) error) error {
|
||||
// reset read-only flag
|
||||
err := chmodfn(filename, 0666)
|
||||
if err != nil && !os.IsPermission(err) {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return os.Remove(filename)
|
||||
return removeFn(filename)
|
||||
}
|
||||
|
||||
// List runs fn for each file in the backend which has the type t. When an
|
||||
// error occurs (or fn returns an error), List stops and returns it.
|
||||
func List(ctx context.Context, basedir string, subdirs bool, openFunc func(name string) (File, error), t backend.FileType, fn func(backend.FileInfo) error) (err error) {
|
||||
func List(ctx context.Context, basedir string, subdirs bool, openFunc func(name string) (File, error), fn func(backend.FileInfo) error) (err error) {
|
||||
if subdirs {
|
||||
err = visitDirs(ctx, openFunc, basedir, fn)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Reference in a new issue