mirror of
https://github.com/restic/restic.git
synced 2025-08-26 09:28:01 +00:00
fs: move NodeFromFileInfo into FS interface
This commit is contained in:
@@ -256,7 +256,7 @@ func (arch *Archiver) trackItem(item string, previous, current *restic.Node, s I
|
||||
|
||||
// nodeFromFileInfo returns the restic node from an os.FileInfo.
|
||||
func (arch *Archiver) nodeFromFileInfo(snPath, filename string, fi os.FileInfo, ignoreXattrListError bool) (*restic.Node, error) {
|
||||
node, err := fs.NodeFromFileInfo(filename, fi, ignoreXattrListError)
|
||||
node, err := arch.FS.NodeFromFileInfo(filename, fi, ignoreXattrListError)
|
||||
if !arch.WithAtime {
|
||||
node.AccessTime = node.ModTime
|
||||
}
|
||||
|
@@ -556,7 +556,7 @@ func rename(t testing.TB, oldname, newname string) {
|
||||
}
|
||||
}
|
||||
|
||||
func nodeFromFI(t testing.TB, filename string, fi os.FileInfo) *restic.Node {
|
||||
func nodeFromFI(t testing.TB, fs fs.FS, filename string, fi os.FileInfo) *restic.Node {
|
||||
node, err := fs.NodeFromFileInfo(filename, fi, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -688,7 +688,7 @@ func TestFileChanged(t *testing.T) {
|
||||
|
||||
fs := &fs.Local{}
|
||||
fiBefore := lstat(t, filename)
|
||||
node := nodeFromFI(t, filename, fiBefore)
|
||||
node := nodeFromFI(t, fs, filename, fiBefore)
|
||||
|
||||
if fileChanged(fs, fiBefore, node, 0) {
|
||||
t.Fatalf("unchanged file detected as changed")
|
||||
@@ -729,7 +729,7 @@ func TestFilChangedSpecialCases(t *testing.T) {
|
||||
|
||||
t.Run("type-change", func(t *testing.T) {
|
||||
fi := lstat(t, filename)
|
||||
node := nodeFromFI(t, filename, fi)
|
||||
node := nodeFromFI(t, &fs.Local{}, filename, fi)
|
||||
node.Type = "restic.NodeTypeSymlink"
|
||||
if !fileChanged(&fs.Local{}, fi, node, 0) {
|
||||
t.Fatal("node with changed type detected as unchanged")
|
||||
@@ -2275,13 +2275,14 @@ func TestMetadataChanged(t *testing.T) {
|
||||
|
||||
// get metadata
|
||||
fi := lstat(t, "testfile")
|
||||
want, err := fs.NodeFromFileInfo("testfile", fi, false)
|
||||
localFS := &fs.Local{}
|
||||
want, err := localFS.NodeFromFileInfo("testfile", fi, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fs := &StatFS{
|
||||
FS: fs.Local{},
|
||||
FS: localFS,
|
||||
OverrideLstat: map[string]os.FileInfo{
|
||||
"testfile": fi,
|
||||
},
|
||||
|
@@ -58,10 +58,11 @@ func wrapIrregularFileInfo(fi os.FileInfo) os.FileInfo {
|
||||
|
||||
func statAndSnapshot(t *testing.T, repo archiverRepo, name string) (*restic.Node, *restic.Node) {
|
||||
fi := lstat(t, name)
|
||||
fs := &fs.Local{}
|
||||
want, err := fs.NodeFromFileInfo(name, fi, false)
|
||||
rtest.OK(t, err)
|
||||
|
||||
_, node := snapshot(t, repo, fs.Local{}, nil, name)
|
||||
_, node := snapshot(t, repo, fs, nil, name)
|
||||
return want, node
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,7 @@ func createTestFiles(t testing.TB, num int) (files []string) {
|
||||
return files
|
||||
}
|
||||
|
||||
func startFileSaver(ctx context.Context, t testing.TB) (*fileSaver, context.Context, *errgroup.Group) {
|
||||
func startFileSaver(ctx context.Context, t testing.TB, fs fs.FS) (*fileSaver, context.Context, *errgroup.Group) {
|
||||
wg, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
saveBlob := func(ctx context.Context, tpe restic.BlobType, buf *buffer, _ string, cb func(saveBlobResponse)) {
|
||||
@@ -67,7 +67,7 @@ func TestFileSaver(t *testing.T) {
|
||||
completeFn := func(*restic.Node, ItemStats) {}
|
||||
|
||||
testFs := fs.Local{}
|
||||
s, ctx, wg := startFileSaver(ctx, t)
|
||||
s, ctx, wg := startFileSaver(ctx, t, testFs)
|
||||
|
||||
var results []futureNode
|
||||
|
||||
|
Reference in New Issue
Block a user