restic/internal/fs/helpers.go

37 lines
643 B
Go
Raw Normal View History

2017-12-23 11:12:36 +00:00
package fs
2017-12-15 23:01:28 +00:00
import (
2018-05-01 12:38:41 +00:00
"io/ioutil"
2017-12-15 23:01:28 +00:00
"os"
"testing"
)
2017-12-23 11:12:36 +00:00
// 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|os.ModeCharDevice) == 0
}
2017-12-15 23:01:28 +00:00
2018-05-01 12:38:41 +00:00
// TestTempFile returns a new temporary file, which is removed when cleanup()
// is called.
func TestTempFile(t testing.TB, prefix string) (File, func()) {
f, err := ioutil.TempFile("", prefix)
if err != nil {
t.Fatal(err)
}
cleanup := func() {
_ = f.Close()
err = Remove(f.Name())
if err != nil {
t.Fatal(err)
}
}
return f, cleanup
}