diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index c576d047c..4f0990843 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -446,7 +446,7 @@ func (arch *Archiver) save(ctx context.Context, snPath, target string, previous } switch { - case fs.IsRegularFile(fi): + case fi.Mode().IsRegular(): debug.Log(" %v regular file", target) // check if the file has not changed before performing a fopen operation (more expensive, specially @@ -505,7 +505,7 @@ func (arch *Archiver) save(ctx context.Context, snPath, target string, previous } // make sure it's still a file - if !fs.IsRegularFile(fi) { + if !fi.Mode().IsRegular() { err = errors.Errorf("file %v changed type, refusing to archive", fi.Name()) _ = file.Close() err = arch.error(abstarget, err) diff --git a/internal/archiver/testing.go b/internal/archiver/testing.go index 106e68445..8bd854904 100644 --- a/internal/archiver/testing.go +++ b/internal/archiver/testing.go @@ -169,7 +169,7 @@ func TestEnsureFiles(t testing.TB, target string, dir TestDir) { } return nil case TestFile: - if !fs.IsRegularFile(fi) { + if !fi.Mode().IsRegular() { t.Errorf("is not a regular file: %v", path) return nil } @@ -208,7 +208,7 @@ func TestEnsureFiles(t testing.TB, target string, dir TestDir) { }) // then, traverse the directory again, looking for additional files - err := fs.Walk(target, func(path string, fi os.FileInfo, err error) error { + err := filepath.Walk(target, func(path string, fi os.FileInfo, err error) error { if err != nil { return err } diff --git a/internal/archiver/testing_test.go b/internal/archiver/testing_test.go index ff3bd3668..bb4b63a82 100644 --- a/internal/archiver/testing_test.go +++ b/internal/archiver/testing_test.go @@ -122,7 +122,7 @@ func TestTestCreateFiles(t *testing.T) { switch node := item.(type) { case TestFile: - if !fs.IsRegularFile(fi) { + if !fi.Mode().IsRegular() { t.Errorf("is not regular file: %v", name) continue } diff --git a/internal/fs/file.go b/internal/fs/file.go index 85b202dc8..1071f4e87 100644 --- a/internal/fs/file.go +++ b/internal/fs/file.go @@ -3,7 +3,6 @@ package fs import ( "fmt" "os" - "path/filepath" "time" ) @@ -75,15 +74,6 @@ func Lstat(name string) (os.FileInfo, error) { return os.Lstat(fixpath(name)) } -// Create creates the named file with mode 0666 (before umask), truncating -// it if it already exists. If successful, methods on the returned -// File can be used for I/O; the associated file descriptor has mode -// O_RDWR. -// If there is an error, it will be of type *PathError. -func Create(name string) (*os.File, error) { - return os.Create(fixpath(name)) -} - // Open opens a file for reading. func Open(name string) (File, error) { return os.Open(fixpath(name)) @@ -98,16 +88,6 @@ func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) { return os.OpenFile(fixpath(name), flag, perm) } -// Walk walks the file tree rooted at root, calling walkFn for each file or -// directory in the tree, including root. All errors that arise visiting files -// and directories are filtered by walkFn. The files are walked in lexical -// order, which makes the output deterministic but means that for very -// large directories Walk can be inefficient. -// Walk does not follow symbolic links. -func Walk(root string, walkFn filepath.WalkFunc) error { - return filepath.Walk(fixpath(root), walkFn) -} - // RemoveIfExists removes a file, returning no error if it does not exist. func RemoveIfExists(filename string) error { err := os.Remove(filename) diff --git a/internal/fs/helpers.go b/internal/fs/helpers.go deleted file mode 100644 index 4dd1e0e73..000000000 --- a/internal/fs/helpers.go +++ /dev/null @@ -1,13 +0,0 @@ -package fs - -import "os" - -// IsRegularFile returns true if fi belongs to a normal file. If fi is nil, -// false is returned. -func IsRegularFile(fi os.FileInfo) bool { - if fi == nil { - return false - } - - return fi.Mode()&os.ModeType == 0 -}