Exit non-zero when snapshot create --skip-errors skips anything it cannot read (closes #310)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
A backup under --skip-errors printed its skip errors and failed count, then "Finished successfully.", and exited 0, so a cron wrapper could not tell it from a complete backup. A directory the walk could not list was not counted at all. Each entry the walk skips is now counted as examined and failed. When --skip-errors skipped anything it could not read or list, the run keeps its snapshots, runs the post-backup prune as before, and then returns an error the command reports as "Backup completed, but N file(s) could not be read". A file removed during the run is still counted as failed in the summary but leaves the exit status at 0, with or without the flag. Model: opus-5-5
This commit is contained in:
@@ -141,10 +141,11 @@ type ScannerConfig struct {
|
||||
// ScanResult contains the results of a scan operation. Files and bytes
|
||||
// are counted per file: BytesScanned is the size of the new and changed
|
||||
// files, BytesSkipped that of the unchanged ones. FilesFailed counts the
|
||||
// new and changed files that phase 2 could not store; FilesScanned
|
||||
// includes them and BytesScanned does not. ChunksCreated counts the
|
||||
// chunks that were not already stored, and NewChunkSize is their total
|
||||
// size.
|
||||
// new and changed files that phase 2 could not store and, under
|
||||
// --skip-errors, each entry the walk could not read, such as a directory
|
||||
// it could not list; FilesScanned includes them and BytesScanned does
|
||||
// not. ChunksCreated counts the chunks that were not already stored, and
|
||||
// NewChunkSize is their total size.
|
||||
type ScanResult struct {
|
||||
FilesScanned int
|
||||
FilesSkipped int
|
||||
@@ -161,6 +162,11 @@ type ScanResult struct {
|
||||
UploadDuration time.Duration
|
||||
StartTime time.Time
|
||||
EndTime time.Time
|
||||
|
||||
// FilesUnreadable is the part of FilesFailed that --skip-errors
|
||||
// skipped because it could not be read or listed; the rest are files
|
||||
// removed after the walk listed them.
|
||||
FilesUnreadable int
|
||||
}
|
||||
|
||||
// NewScanner creates a new scanner instance
|
||||
@@ -883,7 +889,7 @@ func (s *Scanner) scanPhase(
|
||||
|
||||
walkFn := func(filePath string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return s.handleWalkError(filePath, err)
|
||||
return s.handleWalkError(filePath, err, result)
|
||||
}
|
||||
|
||||
// Check context cancellation
|
||||
@@ -959,7 +965,7 @@ func (s *Scanner) recordSpecialEntry(
|
||||
if info.Mode()&os.ModeSymlink != 0 {
|
||||
file, err := s.buildSymlinkEntry(filePath, info)
|
||||
if err != nil {
|
||||
return true, s.handleWalkError(filePath, err)
|
||||
return true, s.handleWalkError(filePath, err, result)
|
||||
}
|
||||
|
||||
existingFiles[filePath] = struct{}{}
|
||||
@@ -983,14 +989,21 @@ func (s *Scanner) recordSpecialEntry(
|
||||
}
|
||||
|
||||
// handleWalkError deals with a filesystem error surfaced by the walk:
|
||||
// skipped (with a UI notice) under --skip-errors, fatal otherwise.
|
||||
func (s *Scanner) handleWalkError(filePath string, err error) error {
|
||||
// under --skip-errors the entry is skipped with a UI notice and counted
|
||||
// as examined, failed and unreadable, otherwise the error is fatal.
|
||||
func (s *Scanner) handleWalkError(
|
||||
filePath string, err error, result *ScanResult,
|
||||
) error {
|
||||
if s.skipErrors {
|
||||
log.Error("Failed to access file (skipping due to --skip-errors)",
|
||||
"path", filePath, "error", err)
|
||||
s.ui.Errorf("Failed to access %s: %v. Skipping (--skip-errors).",
|
||||
s.ui.Path(filePath), err)
|
||||
|
||||
result.FilesScanned++
|
||||
result.FilesFailed++
|
||||
result.FilesUnreadable++
|
||||
|
||||
return nil // Continue scanning
|
||||
}
|
||||
|
||||
@@ -1422,6 +1435,7 @@ func (s *Scanner) processFileWithErrorHandling(
|
||||
s.ui.Path(fileToProcess.Path), err)
|
||||
|
||||
countFailedFile(fileToProcess, result)
|
||||
result.FilesUnreadable++
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user