Skip to content

Commit

Permalink
Let Access Denied during read be a minor error that does not terminat…
Browse files Browse the repository at this point in the history
…e the whole backup
  • Loading branch information
fredli74 committed Jul 27, 2024
1 parent a918c7b commit 0d43dfd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
8 changes: 8 additions & 0 deletions hashback/hashback_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ func isOfflineFile(fileInfo os.FileInfo) bool {
sys := fileInfo.Sys().(*syscall.Stat_t)
return sys != nil && sys.Size > 0 && sys.Blocks == 0
}

func minorPathError(r interface{}) error {
e, ok := r.(*os.PathError)
if ok && e.Err == syscall.EBADF { // "bad file descriptor" while reading some files on OSX
return e
}
return nil
}
10 changes: 10 additions & 0 deletions hashback/hashback_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ func isOfflineFile(fileInfo os.FileInfo) bool {
sys := fileInfo.Sys().(*syscall.Win32FileAttributeData)
return sys != nil && sys.FileAttributes&FILE_ATTRIBUTE_OFFLINE == FILE_ATTRIBUTE_OFFLINE
}

func minorPathError(r interface{}) error {
e, ok := r.(*os.PathError)
if ok && (e.Err == syscall.Errno(32) || // ERROR_SHARING_VIOLATION
e.Err == syscall.Errno(33) || // ERROR_LOCK_VIOLATION
e.Err == syscall.Errno(5)) { // ERROR_ACCESS_DENIED
return e
}
return nil
}
16 changes: 2 additions & 14 deletions hashback/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"sort"
"sync"
"syscall"
"time"
)

Expand All @@ -52,16 +50,6 @@ func (session *BackupSession) PrintRecoverProgress(progress float64, interval ti
}
}

func minorError(r interface{}) error {
e, ok := r.(*os.PathError)
if ok && ((runtime.GOOS == "windows" && (e.Err == syscall.Errno(32) || // ERROR_SHARING_VIOLATION
e.Err == syscall.Errno(33))) || // ERROR_LOCK_VIOLATION
e.Err == syscall.EBADF) { // "bad file descriptor" while reading some files on OSX
return e
}
return nil
}

func compareEntries(fileInfo os.FileInfo, new *FileEntry, old *FileEntry) bool {
if old.FileName != new.FileName {
core.Log(core.LogTrace, "FileName is different: %s != %s", new.FileName, old.FileName)
Expand Down Expand Up @@ -94,7 +82,7 @@ func (session *BackupSession) storeFile(path string, entry *FileEntry) (err erro
defer func() {
// Panic error handling
if r := recover(); r != nil {
if e := minorError(r); e != nil {
if e := minorPathError(r); e != nil {
err = e
} else {
panic(r) // Any other error while reading is not normal and should panic
Expand Down Expand Up @@ -358,7 +346,7 @@ func (session *BackupSession) storePath(path string, toplevel bool) (entry *File
if entry.FileSize > 0 {
session.LogVerbose("%s", path)
if err = session.storeFile(path, entry); err != nil {
if e := minorError(err); e != nil {
if e := minorPathError(err); e != nil {
return refEntry, e // Returning refEntry here in case this file existed and could be opened in a previous backup
}
return nil, err
Expand Down

0 comments on commit 0d43dfd

Please sign in to comment.