Skip to content

Commit

Permalink
Merge pull request #4620 from MichaelEischer/improve-irregular-file-h…
Browse files Browse the repository at this point in the history
…andling

Improve irregular file handling
  • Loading branch information
MichaelEischer committed Jan 7, 2024
2 parents 76f507c + 3e29f8d commit f8b4e93
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
14 changes: 14 additions & 0 deletions changelog/unreleased/issue-4560
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Bugfix: Improve errors for irregular files on Windows

Since Go 1.21, most filesystem reparse points on Windows are considered to be
irregular files. This caused restic to show an `error: invalid node type ""`
error message for those files.

We have improved the error message to include the file path for those files:
`error: nodeFromFileInfo path/to/file: unsupported file type "irregular"`.
As irregular files are not required to behave like regular files, it is not
possible to provide a generic way to back up those files.

https://github.com/restic/restic/issues/4560
https://github.com/restic/restic/pull/4620
https://forum.restic.net/t/windows-backup-error-invalid-node-type/6875
12 changes: 11 additions & 1 deletion internal/archiver/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package archiver

import (
"context"
"fmt"
"os"
"path"
"runtime"
"sort"
"strings"
"time"

"github.com/restic/restic/internal/debug"
Expand Down Expand Up @@ -168,6 +170,11 @@ func (arch *Archiver) error(item string, err error) error {
return err
}

// not all errors include the filepath, thus add it if it is missing
if !strings.Contains(err.Error(), item) {
err = fmt.Errorf("%v: %w", item, err)
}

errf := arch.Error(item, err)
if err != errf {
debug.Log("item %v: error was filtered by handler, before: %q, after: %v", item, err, errf)
Expand All @@ -183,7 +190,10 @@ func (arch *Archiver) nodeFromFileInfo(snPath, filename string, fi os.FileInfo)
}
// overwrite name to match that within the snapshot
node.Name = path.Base(snPath)
return node, errors.WithStack(err)
if err != nil {
return node, fmt.Errorf("nodeFromFileInfo %v: %w", filename, err)
}
return node, err
}

// loadSubtree tries to load the subtree referenced by node. In case of an error, nil is returned.
Expand Down
6 changes: 4 additions & 2 deletions internal/restic/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) {
}

func nodeTypeFromFileInfo(fi os.FileInfo) string {
switch fi.Mode() & (os.ModeType | os.ModeCharDevice) {
switch fi.Mode() & os.ModeType {
case 0:
return "file"
case os.ModeDir:
Expand All @@ -124,6 +124,8 @@ func nodeTypeFromFileInfo(fi os.FileInfo) string {
return "fifo"
case os.ModeSocket:
return "socket"
case os.ModeIrregular:
return "irregular"
}

return ""
Expand Down Expand Up @@ -622,7 +624,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
case "fifo":
case "socket":
default:
return errors.Errorf("invalid node type %q", node.Type)
return errors.Errorf("unsupported file type %q", node.Type)
}

return node.fillExtendedAttributes(path)
Expand Down

0 comments on commit f8b4e93

Please sign in to comment.