From ca41c8fd11e18cc82f3c280e3573433c40fa62fa Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 13 Jun 2024 22:40:35 +0200 Subject: [PATCH] restore: use fs function wrappers This ensures proper path handling on Windows. --- internal/restorer/fileswriter.go | 10 +++++----- internal/restorer/restorer.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/restorer/fileswriter.go b/internal/restorer/fileswriter.go index 9e9b6b01c..034ed2725 100644 --- a/internal/restorer/fileswriter.go +++ b/internal/restorer/fileswriter.go @@ -44,7 +44,7 @@ func newFilesWriter(count int) *filesWriter { } func openFile(path string) (*os.File, error) { - f, err := os.OpenFile(path, os.O_WRONLY|fs.O_NOFOLLOW, 0600) + f, err := fs.OpenFile(path, fs.O_WRONLY|fs.O_NOFOLLOW, 0600) if err != nil { return nil, err } @@ -61,7 +61,7 @@ func openFile(path string) (*os.File, error) { } func createFile(path string, createSize int64, sparse bool) (*os.File, error) { - f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|fs.O_NOFOLLOW, 0600) + f, err := fs.OpenFile(path, fs.O_CREATE|fs.O_WRONLY|fs.O_NOFOLLOW, 0600) if err != nil && fs.IsAccessDenied(err) { // If file is readonly, clear the readonly flag by resetting the // permissions of the file and try again @@ -70,7 +70,7 @@ func createFile(path string, createSize int64, sparse bool) (*os.File, error) { if err = fs.ResetPermissions(path); err != nil { return nil, err } - if f, err = os.OpenFile(path, os.O_WRONLY|fs.O_NOFOLLOW, 0600); err != nil { + if f, err = fs.OpenFile(path, fs.O_WRONLY|fs.O_NOFOLLOW, 0600); err != nil { return nil, err } } else if err != nil && (errors.Is(err, syscall.ELOOP) || errors.Is(err, syscall.EISDIR)) { @@ -109,11 +109,11 @@ func createFile(path string, createSize int64, sparse bool) (*os.File, error) { } // not what we expected, try to get rid of it - if err := os.Remove(path); err != nil { + if err := fs.Remove(path); err != nil { return nil, err } // create a new file, pass O_EXCL to make sure there are no surprises - f, err = os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_EXCL|fs.O_NOFOLLOW, 0600) + f, err = fs.OpenFile(path, fs.O_CREATE|fs.O_WRONLY|fs.O_EXCL|fs.O_NOFOLLOW, 0600) if err != nil { return nil, err } diff --git a/internal/restorer/restorer.go b/internal/restorer/restorer.go index 19555afb8..85132c8b4 100644 --- a/internal/restorer/restorer.go +++ b/internal/restorer/restorer.go @@ -541,7 +541,7 @@ func (s *fileState) HasMatchingBlob(i int) bool { // Reusing buffers prevents the verifier goroutines allocating all of RAM and // flushing the filesystem cache (at least on Linux). func (res *Restorer) verifyFile(target string, node *restic.Node, failFast bool, trustMtime bool, buf []byte) (*fileState, []byte, error) { - f, err := os.OpenFile(target, fs.O_RDONLY|fs.O_NOFOLLOW, 0) + f, err := fs.OpenFile(target, fs.O_RDONLY|fs.O_NOFOLLOW, 0) if err != nil { return nil, buf, err }