fs: clean up helper functions
This commit is contained in:
parent
fc549c9462
commit
0ddb4441d7
5 changed files with 5 additions and 38 deletions
|
@ -446,7 +446,7 @@ func (arch *Archiver) save(ctx context.Context, snPath, target string, previous
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case fs.IsRegularFile(fi):
|
case fi.Mode().IsRegular():
|
||||||
debug.Log(" %v regular file", target)
|
debug.Log(" %v regular file", target)
|
||||||
|
|
||||||
// check if the file has not changed before performing a fopen operation (more expensive, specially
|
// 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
|
// 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())
|
err = errors.Errorf("file %v changed type, refusing to archive", fi.Name())
|
||||||
_ = file.Close()
|
_ = file.Close()
|
||||||
err = arch.error(abstarget, err)
|
err = arch.error(abstarget, err)
|
||||||
|
|
|
@ -169,7 +169,7 @@ func TestEnsureFiles(t testing.TB, target string, dir TestDir) {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
case TestFile:
|
case TestFile:
|
||||||
if !fs.IsRegularFile(fi) {
|
if !fi.Mode().IsRegular() {
|
||||||
t.Errorf("is not a regular file: %v", path)
|
t.Errorf("is not a regular file: %v", path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ func TestEnsureFiles(t testing.TB, target string, dir TestDir) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// then, traverse the directory again, looking for additional files
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ func TestTestCreateFiles(t *testing.T) {
|
||||||
|
|
||||||
switch node := item.(type) {
|
switch node := item.(type) {
|
||||||
case TestFile:
|
case TestFile:
|
||||||
if !fs.IsRegularFile(fi) {
|
if !fi.Mode().IsRegular() {
|
||||||
t.Errorf("is not regular file: %v", name)
|
t.Errorf("is not regular file: %v", name)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package fs
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -75,15 +74,6 @@ func Lstat(name string) (os.FileInfo, error) {
|
||||||
return os.Lstat(fixpath(name))
|
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.
|
// Open opens a file for reading.
|
||||||
func Open(name string) (File, error) {
|
func Open(name string) (File, error) {
|
||||||
return os.Open(fixpath(name))
|
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)
|
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.
|
// RemoveIfExists removes a file, returning no error if it does not exist.
|
||||||
func RemoveIfExists(filename string) error {
|
func RemoveIfExists(filename string) error {
|
||||||
err := os.Remove(filename)
|
err := os.Remove(filename)
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
Loading…
Reference in a new issue