mirror of
https://github.com/restic/restic.git
synced 2026-06-17 14:14:19 +00:00
fs: unexport Local and expose via NewLocal
This commit is contained in:
@@ -567,7 +567,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts global.Options, te
|
||||
return err
|
||||
}
|
||||
|
||||
var targetFS fs.FS = fs.Local{}
|
||||
targetFS := fs.NewLocal()
|
||||
if runtime.GOOS == "windows" && opts.UseFsSnapshot {
|
||||
if err = fs.HasSufficientPrivilegesForVSS(); err != nil {
|
||||
return err
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -88,7 +88,7 @@ func TestNodeMarshal(t *testing.T) {
|
||||
}
|
||||
|
||||
func nodeForFile(t *testing.T, name string) *data.Node {
|
||||
f, err := (&fs.Local{}).OpenFile(name, fs.O_NOFOLLOW, true)
|
||||
f, err := fs.NewLocal().OpenFile(name, fs.O_NOFOLLOW, true)
|
||||
rtest.OK(t, err)
|
||||
node, err := f.ToNode(false, t.Logf)
|
||||
rtest.OK(t, err)
|
||||
|
||||
@@ -84,7 +84,7 @@ func WriteTest(t *testing.T, format string, cd CheckDump) {
|
||||
defer cancel()
|
||||
|
||||
tmpdir, repo, be := prepareTempdirRepoSrc(t, tt.args)
|
||||
arch := archiver.New(repo, fs.Track{FS: fs.Local{}}, archiver.Options{})
|
||||
arch := archiver.New(repo, fs.Track{FS: fs.NewLocal()}, archiver.Options{})
|
||||
|
||||
back := rtest.Chdir(t, tmpdir)
|
||||
defer back()
|
||||
|
||||
@@ -17,6 +17,6 @@ func TestReaddirnamesFifo(t *testing.T) {
|
||||
fifoFn := filepath.Join(tempdir, "fifo")
|
||||
rtest.OK(t, mkfifo(fifoFn, 0o600))
|
||||
|
||||
_, err := Readdirnames(&Local{}, fifoFn, 0)
|
||||
_, err := Readdirnames(NewLocal(), fifoFn, 0)
|
||||
rtest.Assert(t, errors.Is(err, syscall.ENOTDIR), "unexpected error %v", err)
|
||||
}
|
||||
|
||||
+19
-14
@@ -14,16 +14,21 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// Local is the local file system. Most methods are just passed on to the stdlib.
|
||||
type Local struct{}
|
||||
// local is the local file system. Most methods are just passed on to the stdlib.
|
||||
type local struct{}
|
||||
|
||||
// statically ensure that Local implements FS.
|
||||
var _ FS = &Local{}
|
||||
// NewLocal returns an FS for the local file system. Most methods are just passed on to the stdlib.
|
||||
func NewLocal() FS {
|
||||
return local{}
|
||||
}
|
||||
|
||||
// statically ensure that local implements FS.
|
||||
var _ FS = &local{}
|
||||
|
||||
// VolumeName returns leading volume name. Given "C:\foo\bar" it returns "C:"
|
||||
// on Windows. Given "\\host\share\foo" it returns "\\host\share". On other
|
||||
// platforms it returns "".
|
||||
func (fs Local) VolumeName(path string) string {
|
||||
func (fs local) VolumeName(path string) string {
|
||||
return filepath.VolumeName(path)
|
||||
}
|
||||
|
||||
@@ -35,7 +40,7 @@ func (fs Local) VolumeName(path string) string {
|
||||
// delay actually accessing the underlying filesystem.
|
||||
//
|
||||
// Only the O_NOFOLLOW and O_DIRECTORY flags are supported.
|
||||
func (fs Local) OpenFile(name string, flag int, metadataOnly bool) (File, error) {
|
||||
func (fs local) OpenFile(name string, flag int, metadataOnly bool) (File, error) {
|
||||
return newLocalFile(name, flag, metadataOnly)
|
||||
}
|
||||
|
||||
@@ -43,7 +48,7 @@ func (fs Local) OpenFile(name string, flag int, metadataOnly bool) (File, error)
|
||||
// If the file is a symbolic link, the returned FileInfo
|
||||
// describes the symbolic link. Lstat makes no attempt to follow the link.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func (fs Local) Lstat(name string) (*ExtendedFileInfo, error) {
|
||||
func (fs local) Lstat(name string) (*ExtendedFileInfo, error) {
|
||||
fi, err := os.Lstat(fixpath(name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -55,17 +60,17 @@ func (fs Local) Lstat(name string) (*ExtendedFileInfo, error) {
|
||||
// Separator if necessary. Join calls Clean on the result; in particular, all
|
||||
// empty strings are ignored. On Windows, the result is a UNC path if and only
|
||||
// if the first path element is a UNC path.
|
||||
func (fs Local) Join(elem ...string) string {
|
||||
func (fs local) Join(elem ...string) string {
|
||||
return filepath.Join(elem...)
|
||||
}
|
||||
|
||||
// Separator returns the OS and FS dependent separator for dirs/subdirs/files.
|
||||
func (fs Local) Separator() string {
|
||||
func (fs local) Separator() string {
|
||||
return string(filepath.Separator)
|
||||
}
|
||||
|
||||
// IsAbs reports whether the path is absolute.
|
||||
func (fs Local) IsAbs(path string) bool {
|
||||
func (fs local) IsAbs(path string) bool {
|
||||
return filepath.IsAbs(path)
|
||||
}
|
||||
|
||||
@@ -73,22 +78,22 @@ func (fs Local) IsAbs(path string) bool {
|
||||
// it will be joined with the current working directory to turn it into an
|
||||
// absolute path. The absolute path name for a given file is not guaranteed to
|
||||
// be unique. Abs calls Clean on the result.
|
||||
func (fs Local) Abs(path string) (string, error) {
|
||||
func (fs local) Abs(path string) (string, error) {
|
||||
return filepath.Abs(path)
|
||||
}
|
||||
|
||||
// Clean returns the cleaned path. For details, see filepath.Clean.
|
||||
func (fs Local) Clean(p string) string {
|
||||
func (fs local) Clean(p string) string {
|
||||
return filepath.Clean(p)
|
||||
}
|
||||
|
||||
// Base returns the last element of path.
|
||||
func (fs Local) Base(path string) string {
|
||||
func (fs local) Base(path string) string {
|
||||
return filepath.Base(path)
|
||||
}
|
||||
|
||||
// Dir returns path without the last element.
|
||||
func (fs Local) Dir(path string) string {
|
||||
func (fs local) Dir(path string) string {
|
||||
return filepath.Dir(path)
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ func runFSLocalTestcase(t *testing.T, test fsLocalMetadataTestcase) {
|
||||
path := filepath.Join(tmp, "item")
|
||||
test.setup(t, path)
|
||||
|
||||
testFs := &Local{}
|
||||
testFs := NewLocal()
|
||||
flags := 0
|
||||
if !test.follow {
|
||||
flags |= O_NOFOLLOW
|
||||
@@ -124,7 +124,7 @@ func testFSLocalRead(t *testing.T, makeReadable bool) {
|
||||
}
|
||||
|
||||
func openReadable(t *testing.T, path string, useMakeReadable bool) File {
|
||||
testFs := &Local{}
|
||||
testFs := NewLocal()
|
||||
f, err := testFs.OpenFile(path, O_NOFOLLOW, useMakeReadable)
|
||||
rtest.OK(t, err)
|
||||
if useMakeReadable {
|
||||
@@ -163,7 +163,7 @@ func TestFSLocalReadableRace(t *testing.T) {
|
||||
testdata := "example"
|
||||
rtest.OK(t, os.WriteFile(path, []byte(testdata), 0o600))
|
||||
|
||||
testFs := &Local{}
|
||||
testFs := NewLocal()
|
||||
f, err := testFs.OpenFile(path, O_NOFOLLOW, true)
|
||||
rtest.OK(t, err)
|
||||
|
||||
@@ -189,7 +189,7 @@ func TestFSLocalTypeChange(t *testing.T) {
|
||||
testdata := "example"
|
||||
rtest.OK(t, os.WriteFile(path, []byte(testdata), 0o600))
|
||||
|
||||
testFs := &Local{}
|
||||
testFs := NewLocal()
|
||||
f, err := testFs.OpenFile(path, O_NOFOLLOW, true)
|
||||
rtest.OK(t, err)
|
||||
// cache metadata
|
||||
|
||||
@@ -95,7 +95,7 @@ func parseMountPoints(list string, msgError ErrorHandler) (volumes map[string]st
|
||||
// shadow copy service to access locked files.
|
||||
func NewLocalVss(msgError ErrorHandler, msgMessage MessageHandler, cfg VSSConfig) *LocalVss {
|
||||
return &LocalVss{
|
||||
FS: Local{},
|
||||
FS: NewLocal(),
|
||||
snapshots: make(map[string]VssSnapshot),
|
||||
failedSnapshots: make(map[string]struct{}),
|
||||
msgError: msgError,
|
||||
|
||||
@@ -23,7 +23,7 @@ func BenchmarkNodeFromFileInfo(t *testing.B) {
|
||||
path := tempfile.Name()
|
||||
rtest.OK(t, tempfile.Close())
|
||||
|
||||
fs := Local{}
|
||||
fs := NewLocal()
|
||||
f, err := fs.OpenFile(path, O_NOFOLLOW, true)
|
||||
rtest.OK(t, err)
|
||||
_, err = f.Stat()
|
||||
@@ -222,7 +222,7 @@ func TestNodeRestoreAt(t *testing.T) {
|
||||
rtest.OK(t, NodeRestoreMetadata(&test, nodePath, func(msg string) { rtest.OK(t, fmt.Errorf("Warning triggered for path: %s: %s", nodePath, msg)) },
|
||||
func(_ string) bool { return true }, ownershipByName))
|
||||
|
||||
fs := &Local{}
|
||||
fs := NewLocal()
|
||||
meta, err := fs.OpenFile(nodePath, O_NOFOLLOW, true)
|
||||
rtest.OK(t, err)
|
||||
n2, err := meta.ToNode(false, t.Logf)
|
||||
|
||||
@@ -115,7 +115,7 @@ func TestNodeFromFileInfo(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
fs := &Local{}
|
||||
fs := NewLocal()
|
||||
meta, err := fs.OpenFile(test.filename, O_NOFOLLOW, true)
|
||||
rtest.OK(t, err)
|
||||
node, err := meta.ToNode(false, t.Logf)
|
||||
|
||||
@@ -390,7 +390,7 @@ func restoreAndGetNode(t *testing.T, tempDir string, testNode *data.Node, warnin
|
||||
}, func(_ string) bool { return true }, false)
|
||||
test.OK(t, errors.Wrapf(err, "Failed to restore metadata for: %s", testPath))
|
||||
|
||||
fs := &Local{}
|
||||
fs := NewLocal()
|
||||
meta, err := fs.OpenFile(testPath, O_NOFOLLOW, true)
|
||||
test.OK(t, err)
|
||||
nodeFromFileInfo, err := meta.ToNode(false, t.Logf)
|
||||
|
||||
@@ -489,7 +489,7 @@ func (res *Restorer) removeUnexpectedFiles(ctx context.Context, target, location
|
||||
panic("internal error")
|
||||
}
|
||||
|
||||
entries, err := fs.Readdirnames(fs.Local{}, target, fs.O_NOFOLLOW)
|
||||
entries, err := fs.Readdirnames(fs.NewLocal(), target, fs.O_NOFOLLOW)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
|
||||
@@ -1537,7 +1537,7 @@ func TestRestorerLongPath(t *testing.T) {
|
||||
|
||||
repo := repository.TestRepository(t)
|
||||
|
||||
local := &fs.Local{}
|
||||
local := fs.NewLocal()
|
||||
sc := archiver.NewScanner(local)
|
||||
rtest.OK(t, sc.Scan(context.TODO(), []string{tmp}))
|
||||
arch := archiver.New(repo, local, archiver.Options{})
|
||||
|
||||
Reference in New Issue
Block a user