fs: unexport Local and expose via NewLocal

This commit is contained in:
Michael Eischer committed 2026-06-13 19:50:49 +02:00
1 parent 1acc19dac5
commit e1e7fc8fb2
20 files changed
+72 -67

No files matched your search

+23 -23
View File
@@ -136,7 +136,7 @@ func TestArchiverSaveFile(t *testing.T) {
defer cancel()
tempdir, repo := prepareTempdirRepoSrc(t, TestDir{"file": testfile})
node, stats := saveFile(t, repo, filepath.Join(tempdir, "file"), fs.Track{FS: fs.Local{}})
node, stats := saveFile(t, repo, filepath.Join(tempdir, "file"), fs.Track{FS: fs.NewLocal()})
TestEnsureFileContent(ctx, t, repo, "file", node, testfile)
if stats.DataSize != uint64(len(testfile.Content)) {
@@ -211,7 +211,7 @@ func TestArchiverSave(t *testing.T) {
tempdir, repo := prepareTempdirRepoSrc(t, TestDir{"file": testfile})
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
arch := New(repo, fs.Track{FS: fs.NewLocal()}, Options{})
arch.Error = func(item string, err error) error {
t.Errorf("archiver error for %v: %v", item, err)
return err
@@ -357,7 +357,7 @@ func BenchmarkArchiverSaveFileSmall(b *testing.B) {
tempdir, repo := prepareTempdirRepoSrc(b, d)
b.StartTimer()
_, stats := saveFile(b, repo, filepath.Join(tempdir, "file"), fs.Track{FS: fs.Local{}})
_, stats := saveFile(b, repo, filepath.Join(tempdir, "file"), fs.Track{FS: fs.NewLocal()})
b.StopTimer()
if stats.DataSize != fileSize {
@@ -389,7 +389,7 @@ func BenchmarkArchiverSaveFileLarge(b *testing.B) {
tempdir, repo := prepareTempdirRepoSrc(b, d)
b.StartTimer()
_, stats := saveFile(b, repo, filepath.Join(tempdir, "file"), fs.Track{FS: fs.Local{}})
_, stats := saveFile(b, repo, filepath.Join(tempdir, "file"), fs.Track{FS: fs.NewLocal()})
b.StopTimer()
if stats.DataSize != fileSize {
@@ -479,7 +479,7 @@ func TestArchiverSaveFileIncremental(t *testing.T) {
for i := 0; i < 3; i++ {
appendToFile(t, testfile, data)
node, _ := saveFile(t, repo, testfile, fs.Track{FS: fs.Local{}})
node, _ := saveFile(t, repo, testfile, fs.Track{FS: fs.NewLocal()})
t.Logf("node blobs: %v", node.Content)
@@ -691,7 +691,7 @@ func TestFileChanged(t *testing.T) {
}
save(t, filename, content)
fs := &fs.Local{}
fs := fs.NewLocal()
fiBefore, err := fs.Lstat(filename)
rtest.OK(t, err)
node := nodeFromFile(t, fs, filename)
@@ -735,7 +735,7 @@ func TestFilChangedSpecialCases(t *testing.T) {
t.Run("type-change", func(t *testing.T) {
fi := lstat(t, filename)
node := nodeFromFile(t, &fs.Local{}, filename)
node := nodeFromFile(t, fs.NewLocal(), filename)
node.Type = data.NodeTypeSymlink
if !fileChanged(fi, node, 0) {
t.Fatal("node with changed type detected as unchanged")
@@ -837,7 +837,7 @@ func TestArchiverSaveDir(t *testing.T) {
t.Run("", func(t *testing.T) {
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
testFS := fs.Track{FS: fs.Local{}}
testFS := fs.Track{FS: fs.NewLocal()}
arch := New(repo, testFS, Options{})
arch.summary = &Summary{}
@@ -907,7 +907,7 @@ func TestArchiverSaveDirIncremental(t *testing.T) {
// save the empty directory several times in a row, then have a look if the
// archiver did save the same tree several times
for i := 0; i < 5; i++ {
testFS := fs.Track{FS: fs.Local{}}
testFS := fs.Track{FS: fs.NewLocal()}
arch := New(repo, testFS, Options{})
arch.summary = &Summary{}
@@ -1089,7 +1089,7 @@ func TestArchiverSaveTree(t *testing.T) {
t.Run("", func(t *testing.T) {
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
testFS := fs.Track{FS: fs.Local{}}
testFS := fs.Track{FS: fs.NewLocal()}
arch := New(repo, testFS, Options{})
arch.summary = &Summary{}
@@ -1388,7 +1388,7 @@ func TestArchiverSnapshot(t *testing.T) {
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
arch := New(repo, fs.Track{FS: fs.NewLocal()}, Options{})
chdir := tempdir
if test.chdir != "" {
@@ -1487,7 +1487,7 @@ func TestResolveRelativeTargetsSpecial(t *testing.T) {
t.Skip("skip test on unix")
}
targets, err := resolveRelativeTargets(&fs.Local{}, test.targets)
targets, err := resolveRelativeTargets(fs.NewLocal(), test.targets)
rtest.OK(t, err)
paths := make([]string, len(targets))
for i, tgt := range targets {
@@ -1609,7 +1609,7 @@ func TestArchiverSnapshotSelect(t *testing.T) {
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
arch := New(repo, fs.Track{FS: fs.NewLocal()}, Options{})
arch.Select = test.selFn
back := rtest.Chdir(t, tempdir)
@@ -1717,7 +1717,7 @@ func TestArchiverExplicitBackupTarget(t *testing.T) {
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
arch := New(repo, fs.Track{FS: fs.NewLocal()}, Options{})
arch.Select = test.selFn
back := rtest.Chdir(t, tempdir)
@@ -1884,7 +1884,7 @@ func TestArchiverParent(t *testing.T) {
tempdir, repo := prepareTempdirRepoSrc(t, test.src)
testFS := &MockFS{
FS: fs.Track{FS: fs.Local{}},
FS: fs.Track{FS: fs.NewLocal()},
bytesRead: make(map[string]int),
}
@@ -2078,7 +2078,7 @@ func TestArchiverErrorReporting(t *testing.T) {
test.prepare(t)
}
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
arch := New(repo, fs.Track{FS: fs.NewLocal()}, Options{})
arch.Error = test.errFn
target := test.targets
@@ -2159,7 +2159,7 @@ func TestArchiverContextCanceled(t *testing.T) {
back := rtest.Chdir(t, tempdir)
defer back()
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
arch := New(repo, fs.Track{FS: fs.NewLocal()}, Options{})
_, snapshotID, _, err := arch.Snapshot(ctx, []string{"."}, SnapshotOptions{Time: time.Now()})
@@ -2301,7 +2301,7 @@ func TestArchiverAbortEarlyOnError(t *testing.T) {
defer back()
testFS := &TrackFS{
FS: fs.Track{FS: fs.Local{}},
FS: fs.Track{FS: fs.NewLocal()},
opened: make(map[string]uint),
}
@@ -2434,7 +2434,7 @@ func TestMetadataChanged(t *testing.T) {
// get metadata
fi := lstat(t, "testfile")
localFS := &fs.Local{}
localFS := fs.NewLocal()
meta, err := localFS.OpenFile("testfile", fs.O_NOFOLLOW, true)
rtest.OK(t, err)
want, err := meta.ToNode(false, t.Logf)
@@ -2535,7 +2535,7 @@ func TestRacyFileTypeSwap(t *testing.T) {
tempfile := filepath.Join(tempdir, realName)
statfs := &overrideFS{
FS: fs.Local{},
FS: fs.NewLocal(),
overrideFI: fakeFI,
resetFIOnRead: true,
}
@@ -2582,7 +2582,7 @@ func TestMetadataBackupErrorFiltering(t *testing.T) {
filename := filepath.Join(tempdir, "file")
repo := repository.TestRepository(t)
arch := New(repo, fs.Local{}, Options{})
arch := New(repo, fs.NewLocal(), Options{})
var filteredErr error
replacementErr := fmt.Errorf("replacement")
@@ -2631,7 +2631,7 @@ func TestIrregularFile(t *testing.T) {
fi.Mode = (fi.Mode &^ os.ModeType) | os.ModeIrregular
override := &overrideFS{
FS: fs.Local{},
FS: fs.NewLocal(),
overrideFI: fi,
overrideNode: &data.Node{
Type: data.NodeTypeIrregular,
@@ -2692,7 +2692,7 @@ func TestDisappearedFile(t *testing.T) {
// depending on the underlying FS implementation a missing file may be detected by OpenFile or
// the subsequent file.Stat() call. Thus test both cases.
for _, errorOnOpen := range []bool{false, true} {
arch := New(repo, fs.Track{FS: &missingFS{FS: &fs.Local{}, errorOnOpen: errorOnOpen}}, Options{})
arch := New(repo, fs.Track{FS: &missingFS{FS: fs.NewLocal(), errorOnOpen: errorOnOpen}}, Options{})
_, excluded, err := arch.save(ctx, "/", filepath.Join(tempdir, "testdir"), nil, false)
rtest.OK(t, err)
rtest.Assert(t, excluded, "testfile should have been excluded")
+2 -2
View File
@@ -12,8 +12,8 @@ import (
)
func statAndSnapshot(t *testing.T, repo archiverRepo, name string) (*data.Node, *data.Node) {
want := nodeFromFile(t, &fs.Local{}, name)
_, node := snapshot(t, repo, &fs.Local{}, nil, name)
want := nodeFromFile(t, fs.NewLocal(), name)
_, node := snapshot(t, repo, fs.NewLocal(), nil, name)
return want, node
}
+4 -4
View File
@@ -49,7 +49,7 @@ func TestIsExcludedByFile(t *testing.T) {
if tc.content == "" {
h = ""
}
if got := isExcludedByFile(foo, tagFilename, h, newRejectionCache(), &fs.Local{}, func(msg string, args ...interface{}) { t.Logf(msg, args...) }); tc.want != got {
if got := isExcludedByFile(foo, tagFilename, h, newRejectionCache(), fs.NewLocal(), func(msg string, args ...interface{}) { t.Logf(msg, args...) }); tc.want != got {
t.Fatalf("expected %v, got %v", tc.want, got)
}
})
@@ -111,8 +111,8 @@ func TestMultipleIsExcludedByFile(t *testing.T) {
if err != nil {
return err
}
excludedByFoo := fooExclude(p, nil, &fs.Local{})
excludedByBar := barExclude(p, nil, &fs.Local{})
excludedByFoo := fooExclude(p, nil, fs.NewLocal())
excludedByBar := barExclude(p, nil, fs.NewLocal())
excluded := excludedByFoo || excludedByBar
// the log message helps debugging in case the test fails
t.Logf("%q: %v || %v = %v", p, excludedByFoo, excludedByBar, excluded)
@@ -243,7 +243,7 @@ func TestDeviceMap(t *testing.T) {
for _, test := range tests {
t.Run("", func(t *testing.T) {
res, err := deviceMap.IsAllowed(filepath.FromSlash(test.item), test.deviceID, &fs.Local{})
res, err := deviceMap.IsAllowed(filepath.FromSlash(test.item), test.deviceID, fs.NewLocal())
if err != nil {
t.Fatal(err)
}
+1 -1
View File
@@ -57,7 +57,7 @@ func TestFileSaver(t *testing.T) {
completeFn := func(*data.Node, ItemStats) {}
files := createTestFiles(t, 15)
testFs := fs.Local{}
testFs := fs.NewLocal()
s, saver, ctx, wg := startFileSaver(ctx, t, testFs)
var results []futureNode
+3 -3
View File
@@ -92,7 +92,7 @@ func TestScanner(t *testing.T) {
t.Fatal(err)
}
sc := NewScanner(fs.Track{FS: fs.Local{}})
sc := NewScanner(fs.Track{FS: fs.NewLocal()})
if test.selFn != nil {
sc.Select = test.selFn
}
@@ -231,7 +231,7 @@ func TestScannerError(t *testing.T) {
test.prepare(t)
}
sc := NewScanner(fs.Track{FS: fs.Local{}})
sc := NewScanner(fs.Track{FS: fs.NewLocal()})
if test.selFn != nil {
sc.Select = test.selFn
}
@@ -299,7 +299,7 @@ func TestScannerCancel(t *testing.T) {
t.Fatal(err)
}
sc := NewScanner(fs.Track{FS: fs.Local{}})
sc := NewScanner(fs.Track{FS: fs.NewLocal()})
var lastStats ScanStats
sc.Result = func(item string, s ScanStats) {
lastStats = s
+1 -1
View File
@@ -20,7 +20,7 @@ import (
// TestSnapshot creates a new snapshot of path.
func TestSnapshot(t testing.TB, repo restic.Repository, path string, parent *restic.ID) *data.Snapshot {
arch := New(repo, fs.Local{}, Options{})
arch := New(repo, fs.NewLocal(), Options{})
opts := SnapshotOptions{
Time: time.Now(),
Hostname: "localhost",
+1 -1
View File
@@ -467,7 +467,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
repo := repository.TestRepository(t)
arch := New(repo, fs.Local{}, Options{})
arch := New(repo, fs.NewLocal(), Options{})
opts := SnapshotOptions{
Time: time.Now(),
Hostname: "localhost",
+3 -3
View File
@@ -98,7 +98,7 @@ func TestPathComponents(t *testing.T) {
t.Skip("skip test on unix")
}
c, v := pathComponents(fs.Local{}, filepath.FromSlash(test.p), test.rel)
c, v := pathComponents(fs.NewLocal(), filepath.FromSlash(test.p), test.rel)
if !cmp.Equal(test.c, c) {
t.Error(test.c, c)
}
@@ -137,7 +137,7 @@ func TestRootDirectory(t *testing.T) {
t.Skip("skip test on unix")
}
root := rootDirectory(fs.Local{}, filepath.FromSlash(test.target))
root := rootDirectory(fs.NewLocal(), filepath.FromSlash(test.target))
want := filepath.FromSlash(test.root)
if root != want {
t.Fatalf("wrong root directory, want %v, got %v", want, root)
@@ -455,7 +455,7 @@ func TestTree(t *testing.T) {
back := rtest.Chdir(t, tempdir)
defer back()
tree, err := newTree(fs.Local{}, testBackupTargets(test.targets))
tree, err := newTree(fs.NewLocal(), testBackupTargets(test.targets))
if test.mustError {
if err == nil {
t.Fatal("expected error, got nil")