mirror of
https://github.com/restic/restic.git
synced 2026-08-03 20:52:16 +00:00
fs: unexport Local and expose via NewLocal
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user