minimize usage of internal/fs in tests

This commit is contained in:
Michael Eischer
2024-07-21 15:58:41 +02:00
parent 65a7157383
commit cc7f99125a
11 changed files with 23 additions and 57 deletions

View File

@@ -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,

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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)
}