minimize usage of internal/fs in tests
This commit is contained in:
parent
65a7157383
commit
cc7f99125a
11 changed files with 23 additions and 57 deletions
|
@ -846,7 +846,7 @@ func TestArchiverSaveDir(t *testing.T) {
|
|||
back := rtest.Chdir(t, chdir)
|
||||
defer back()
|
||||
|
||||
fi, err := fs.Lstat(test.target)
|
||||
fi, err := os.Lstat(test.target)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -920,7 +920,7 @@ func TestArchiverSaveDirIncremental(t *testing.T) {
|
|||
arch.runWorkers(ctx, wg)
|
||||
arch.summary = &Summary{}
|
||||
|
||||
fi, err := fs.Lstat(tempdir)
|
||||
fi, err := os.Lstat(tempdir)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -95,17 +95,17 @@ func TestCreateFiles(t testing.TB, target string, dir TestDir) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
case TestSymlink:
|
||||
err := fs.Symlink(filepath.FromSlash(it.Target), targetPath)
|
||||
err := os.Symlink(filepath.FromSlash(it.Target), targetPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case TestHardlink:
|
||||
err := fs.Link(filepath.Join(target, filepath.FromSlash(it.Target)), targetPath)
|
||||
err := os.Link(filepath.Join(target, filepath.FromSlash(it.Target)), targetPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
case TestDir:
|
||||
err := fs.Mkdir(targetPath, 0755)
|
||||
err := os.Mkdir(targetPath, 0755)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ func TestEnsureFiles(t testing.TB, target string, dir TestDir) {
|
|||
|
||||
// first, test that all items are there
|
||||
TestWalkFiles(t, target, dir, func(path string, item interface{}) error {
|
||||
fi, err := fs.Lstat(path)
|
||||
fi, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -188,7 +188,7 @@ func TestEnsureFiles(t testing.TB, target string, dir TestDir) {
|
|||
return nil
|
||||
}
|
||||
|
||||
target, err := fs.Readlink(path)
|
||||
target, err := os.Readlink(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func (t *MockT) Errorf(msg string, args ...interface{}) {
|
|||
func createFilesAt(t testing.TB, targetdir string, files map[string]interface{}) {
|
||||
for name, item := range files {
|
||||
target := filepath.Join(targetdir, filepath.FromSlash(name))
|
||||
err := fs.MkdirAll(filepath.Dir(target), 0700)
|
||||
err := os.MkdirAll(filepath.Dir(target), 0700)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func createFilesAt(t testing.TB, targetdir string, files map[string]interface{})
|
|||
t.Fatal(err)
|
||||
}
|
||||
case TestSymlink:
|
||||
err := fs.Symlink(filepath.FromSlash(it.Target), target)
|
||||
err := os.Symlink(filepath.FromSlash(it.Target), target)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func TestTestCreateFiles(t *testing.T) {
|
|||
|
||||
t.Run("", func(t *testing.T) {
|
||||
tempdir := filepath.Join(tempdir, fmt.Sprintf("test-%d", i))
|
||||
err := fs.MkdirAll(tempdir, 0700)
|
||||
err := os.MkdirAll(tempdir, 0700)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ func TestTestCreateFiles(t *testing.T) {
|
|||
|
||||
for name, item := range test.files {
|
||||
targetPath := filepath.Join(tempdir, filepath.FromSlash(name))
|
||||
fi, err := fs.Lstat(targetPath)
|
||||
fi, err := os.Lstat(targetPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
|
@ -142,7 +142,7 @@ func TestTestCreateFiles(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
|
||||
target, err := fs.Readlink(targetPath)
|
||||
target, err := os.Readlink(targetPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
continue
|
||||
|
@ -455,7 +455,7 @@ func TestTestEnsureSnapshot(t *testing.T) {
|
|||
tempdir := rtest.TempDir(t)
|
||||
|
||||
targetDir := filepath.Join(tempdir, "target")
|
||||
err := fs.Mkdir(targetDir, 0700)
|
||||
err := os.Mkdir(targetDir, 0700)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/fs"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
@ -83,7 +82,7 @@ func checkTar(t *testing.T, testDir string, srcTar *bytes.Buffer) error {
|
|||
return fmt.Errorf("foldernames must end with separator got %v", hdr.Name)
|
||||
}
|
||||
case tar.TypeSymlink:
|
||||
target, err := fs.Readlink(matchPath)
|
||||
target, err := os.Readlink(matchPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/fs"
|
||||
)
|
||||
|
||||
func TestWriteZip(t *testing.T) {
|
||||
|
@ -91,7 +89,7 @@ func checkZip(t *testing.T, testDir string, srcZip *bytes.Buffer) error {
|
|||
return fmt.Errorf("foldernames must end with separator got %v", f.Name)
|
||||
}
|
||||
case f.Mode()&os.ModeSymlink != 0:
|
||||
target, err := fs.Readlink(matchPath)
|
||||
target, err := os.Readlink(matchPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -3,15 +3,8 @@ package fs
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Mkdir creates a new directory with the specified name and permission bits.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Mkdir(name string, perm os.FileMode) error {
|
||||
return os.Mkdir(fixpath(name), perm)
|
||||
}
|
||||
|
||||
// MkdirAll creates a directory named path, along with any necessary parents,
|
||||
// and returns nil, or else returns an error. The permission bits perm are used
|
||||
// for all directories that MkdirAll creates. If path is already a directory,
|
||||
|
@ -20,12 +13,6 @@ func MkdirAll(path string, perm os.FileMode) error {
|
|||
return os.MkdirAll(fixpath(path), perm)
|
||||
}
|
||||
|
||||
// Readlink returns the destination of the named symbolic link.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Readlink(name string) (string, error) {
|
||||
return os.Readlink(fixpath(name))
|
||||
}
|
||||
|
||||
// Remove removes the named file or directory.
|
||||
// If there is an error, it will be of type *PathError.
|
||||
func Remove(name string) error {
|
||||
|
@ -40,20 +27,6 @@ func RemoveAll(path string) error {
|
|||
return os.RemoveAll(fixpath(path))
|
||||
}
|
||||
|
||||
// Rename renames (moves) oldpath to newpath.
|
||||
// If newpath already exists, Rename replaces it.
|
||||
// OS-specific restrictions may apply when oldpath and newpath are in different directories.
|
||||
// If there is an error, it will be of type *LinkError.
|
||||
func Rename(oldpath, newpath string) error {
|
||||
return os.Rename(fixpath(oldpath), fixpath(newpath))
|
||||
}
|
||||
|
||||
// Symlink creates newname as a symbolic link to oldname.
|
||||
// If there is an error, it will be of type *LinkError.
|
||||
func Symlink(oldname, newname string) error {
|
||||
return os.Symlink(oldname, fixpath(newname))
|
||||
}
|
||||
|
||||
// Link creates newname as a hard link to oldname.
|
||||
// If there is an error, it will be of type *LinkError.
|
||||
func Link(oldname, newname string) error {
|
||||
|
@ -68,11 +41,6 @@ func Lstat(name string) (os.FileInfo, error) {
|
|||
return os.Lstat(fixpath(name))
|
||||
}
|
||||
|
||||
// Open opens a file for reading.
|
||||
func Open(name string) (File, error) {
|
||||
return os.Open(fixpath(name))
|
||||
}
|
||||
|
||||
// OpenFile is the generalized open call; most users will use Open
|
||||
// or Create instead. It opens the named file with specified flag
|
||||
// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
|
||||
|
|
|
@ -80,7 +80,7 @@ func nodeFillExtra(node *restic.Node, path string, fi os.FileInfo, ignoreXattrLi
|
|||
case restic.NodeTypeDir:
|
||||
case restic.NodeTypeSymlink:
|
||||
var err error
|
||||
node.LinkTarget, err = Readlink(path)
|
||||
node.LinkTarget, err = os.Readlink(fixpath(path))
|
||||
node.Links = uint64(stat.nlink())
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
|
@ -212,7 +212,7 @@ func NodeCreateAt(node *restic.Node, path string) error {
|
|||
}
|
||||
|
||||
func nodeCreateDirAt(node *restic.Node, path string) error {
|
||||
err := Mkdir(path, node.Mode)
|
||||
err := os.Mkdir(fixpath(path), node.Mode)
|
||||
if err != nil && !os.IsExist(err) {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ func nodeCreateFileAt(path string) error {
|
|||
}
|
||||
|
||||
func nodeCreateSymlinkAt(node *restic.Node, path string) error {
|
||||
if err := Symlink(node.LinkTarget, path); err != nil {
|
||||
if err := os.Symlink(node.LinkTarget, fixpath(path)); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package fs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
|
@ -10,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func nodeRestoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error {
|
||||
dir, err := Open(filepath.Dir(path))
|
||||
dir, err := os.Open(fixpath(filepath.Dir(path)))
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ func lchown(_ string, _ int, _ int) (err error) {
|
|||
// restoreSymlinkTimestamps restores timestamps for symlinks
|
||||
func nodeRestoreSymlinkTimestamps(path string, utimes [2]syscall.Timespec) error {
|
||||
// tweaked version of UtimesNano from go/src/syscall/syscall_windows.go
|
||||
pathp, e := syscall.UTF16PtrFromString(path)
|
||||
pathp, e := syscall.UTF16PtrFromString(fixpath(path))
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestNoatime(t *testing.T) {
|
|||
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
err = Remove(f.Name())
|
||||
err = os.Remove(f.Name())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -1223,7 +1223,7 @@ func TestRestorerOverwriteSpecial(t *testing.T) {
|
|||
}
|
||||
}
|
||||
for filename, target := range links {
|
||||
link, err := fs.Readlink(filepath.Join(tempdir, filepath.FromSlash(filename)))
|
||||
link, err := os.Readlink(filepath.Join(tempdir, filepath.FromSlash(filename)))
|
||||
rtest.OK(t, err)
|
||||
rtest.Equals(t, link, target, "wrong symlink target")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue