forked from TrueCloudLab/restic
Merge pull request #4620 from MichaelEischer/improve-irregular-file-handling
Improve irregular file handling
This commit is contained in:
commit
f8b4e932ef
3 changed files with 29 additions and 3 deletions
14
changelog/unreleased/issue-4560
Normal file
14
changelog/unreleased/issue-4560
Normal file
|
@ -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
|
|
@ -2,10 +2,12 @@ package archiver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
|
@ -168,6 +170,11 @@ func (arch *Archiver) error(item string, err error) error {
|
||||||
return err
|
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)
|
errf := arch.Error(item, err)
|
||||||
if err != errf {
|
if err != errf {
|
||||||
debug.Log("item %v: error was filtered by handler, before: %q, after: %v", item, err, errf)
|
debug.Log("item %v: error was filtered by handler, before: %q, after: %v", item, err, errf)
|
||||||
|
@ -183,7 +190,10 @@ func (arch *Archiver) nodeFromFileInfo(snPath, filename string, fi os.FileInfo)
|
||||||
}
|
}
|
||||||
// overwrite name to match that within the snapshot
|
// overwrite name to match that within the snapshot
|
||||||
node.Name = path.Base(snPath)
|
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.
|
// loadSubtree tries to load the subtree referenced by node. In case of an error, nil is returned.
|
||||||
|
|
|
@ -109,7 +109,7 @@ func NodeFromFileInfo(path string, fi os.FileInfo) (*Node, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func nodeTypeFromFileInfo(fi os.FileInfo) string {
|
func nodeTypeFromFileInfo(fi os.FileInfo) string {
|
||||||
switch fi.Mode() & (os.ModeType | os.ModeCharDevice) {
|
switch fi.Mode() & os.ModeType {
|
||||||
case 0:
|
case 0:
|
||||||
return "file"
|
return "file"
|
||||||
case os.ModeDir:
|
case os.ModeDir:
|
||||||
|
@ -124,6 +124,8 @@ func nodeTypeFromFileInfo(fi os.FileInfo) string {
|
||||||
return "fifo"
|
return "fifo"
|
||||||
case os.ModeSocket:
|
case os.ModeSocket:
|
||||||
return "socket"
|
return "socket"
|
||||||
|
case os.ModeIrregular:
|
||||||
|
return "irregular"
|
||||||
}
|
}
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
@ -622,7 +624,7 @@ func (node *Node) fillExtra(path string, fi os.FileInfo) error {
|
||||||
case "fifo":
|
case "fifo":
|
||||||
case "socket":
|
case "socket":
|
||||||
default:
|
default:
|
||||||
return errors.Errorf("invalid node type %q", node.Type)
|
return errors.Errorf("unsupported file type %q", node.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.fillExtendedAttributes(path)
|
return node.fillExtendedAttributes(path)
|
||||||
|
|
Loading…
Reference in a new issue