From b6123d3080dd0f02d19c342da333e3ca14971245 Mon Sep 17 00:00:00 2001 From: aneesh-n <99904+aneesh-n@users.noreply.github.com> Date: Mon, 2 Sep 2024 03:46:26 -0600 Subject: [PATCH] Fix lint and remove function --- internal/backend/local/local.go | 6 +++--- internal/backend/smb/smb.go | 9 +++++---- internal/backend/util/file_helper.go | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/backend/local/local.go b/internal/backend/local/local.go index 8640e2a1d..a953dcae0 100644 --- a/internal/backend/local/local.go +++ b/internal/backend/local/local.go @@ -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. diff --git a/internal/backend/smb/smb.go b/internal/backend/smb/smb.go index 87a7332f0..517941dfb 100644 --- a/internal/backend/smb/smb.go +++ b/internal/backend/smb/smb.go @@ -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. diff --git a/internal/backend/util/file_helper.go b/internal/backend/util/file_helper.go index 37e307e62..60c72eca4 100644 --- a/internal/backend/util/file_helper.go +++ b/internal/backend/util/file_helper.go @@ -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 {