1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 00:07:25 +00:00

restore: use fs function wrappers

This ensures proper path handling on Windows.
This commit is contained in:
Michael Eischer 2024-06-13 22:40:35 +02:00
parent 3d73ae9988
commit ca41c8fd11
2 changed files with 6 additions and 6 deletions

View file

@ -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
}

View file

@ -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
}