diff --git a/fileinfo_go1.15.go b/fileinfo_go1.15.go deleted file mode 100644 index c0708ea..0000000 --- a/fileinfo_go1.15.go +++ /dev/null @@ -1,17 +0,0 @@ -//go:build !go1.16 -// +build !go1.16 - -package copy - -import "os" - -// This is a cloned definition of os.FileInfo (go1.15) or fs.FileInfo (go1.16~) -// A FileInfo describes a file and is returned by Stat. -type fileInfo interface { - // Name() string // base name of the file - // Size() int64 // length in bytes for regular files; system-dependent for others - Mode() os.FileMode // file mode bits - // ModTime() time.Time // modification time - IsDir() bool // abbreviation for Mode().IsDir() - Sys() interface{} // underlying data source (can return nil) -} diff --git a/fileinfo_go1.16.go b/fileinfo_go1.16.go deleted file mode 100644 index 01b3fd2..0000000 --- a/fileinfo_go1.16.go +++ /dev/null @@ -1,17 +0,0 @@ -//go:build go1.16 -// +build go1.16 - -package copy - -import "io/fs" - -// This is a cloned definition of os.FileInfo (go1.15) or fs.FileInfo (go1.16~) -// A FileInfo describes a file and is returned by Stat. -type fileInfo interface { - // Name() string // base name of the file - // Size() int64 // length in bytes for regular files; system-dependent for others - Mode() fs.FileMode // file mode bits - // ModTime() time.Time // modification time - IsDir() bool // abbreviation for Mode().IsDir() - Sys() interface{} // underlying data source (can return nil) -} diff --git a/patherror_go1.15_test.go b/patherror_go1.15_test.go deleted file mode 100644 index 2566f3b..0000000 --- a/patherror_go1.15_test.go +++ /dev/null @@ -1,41 +0,0 @@ -//go:build !go1.16 -// +build !go1.16 - -package copy - -import ( - "os" - "path/filepath" - "runtime" - "testing" - - . "github.com/otiai10/mint" -) - -func TestCopy_PathError(t *testing.T) { - - When(t, "too long name is given", func(t *testing.T) { - dest := "foobar" - for i := 0; i < 8; i++ { - dest = dest + dest - } - err := Copy("test/data/case00", filepath.Join("test/data/case00", dest)) - Expect(t, err).Not().ToBe(nil) - Expect(t, err).TypeOf("*os.PathError") - }) - - When(t, "try to create not permitted location", func(t *testing.T) { - if runtime.GOOS == "windows" || runtime.GOOS == "freebsd" || os.Getenv("TESTCASE") != "" { - t.Skipf("FIXME: error IS nil here in Windows and FreeBSD") - } - err := Copy("test/data/case00", "/case00") - Expect(t, err).Not().ToBe(nil) - Expect(t, err).TypeOf("*os.PathError") - }) - - When(t, "try to create a directory on existing file name", func(t *testing.T) { - err := Copy("test/data/case02", "test/data.copy/case00/README.md") - Expect(t, err).Not().ToBe(nil) - Expect(t, err).TypeOf("*os.PathError") - }) -} diff --git a/patherror_go1.16_test.go b/patherror_test.go similarity index 96% rename from patherror_go1.16_test.go rename to patherror_test.go index 2852e6c..40c03f6 100644 --- a/patherror_go1.16_test.go +++ b/patherror_test.go @@ -1,6 +1,3 @@ -//go:build go1.16 -// +build go1.16 - package copy import ( diff --git a/permission_control.go b/permission_control.go index 97ae12d..cb4777c 100644 --- a/permission_control.go +++ b/permission_control.go @@ -1,6 +1,7 @@ package copy import ( + "io/fs" "os" ) @@ -11,11 +12,11 @@ const ( tmpPermissionForDirectory = os.FileMode(0755) ) -type PermissionControlFunc func(srcinfo fileInfo, dest string) (chmodfunc func(*error), err error) +type PermissionControlFunc func(srcinfo fs.FileInfo, dest string) (chmodfunc func(*error), err error) var ( AddPermission = func(perm os.FileMode) PermissionControlFunc { - return func(srcinfo fileInfo, dest string) (func(*error), error) { + return func(srcinfo fs.FileInfo, dest string) (func(*error), error) { orig := srcinfo.Mode() if srcinfo.IsDir() { if err := os.MkdirAll(dest, tmpPermissionForDirectory); err != nil { @@ -28,7 +29,7 @@ var ( } } PerservePermission PermissionControlFunc = AddPermission(0) - DoNothing PermissionControlFunc = func(srcinfo fileInfo, dest string) (func(*error), error) { + DoNothing PermissionControlFunc = func(srcinfo fs.FileInfo, dest string) (func(*error), error) { if srcinfo.IsDir() { if err := os.MkdirAll(dest, srcinfo.Mode()); err != nil { return func(*error) {}, err diff --git a/preserve_owner.go b/preserve_owner.go index 13ec4f5..ca71132 100644 --- a/preserve_owner.go +++ b/preserve_owner.go @@ -4,11 +4,12 @@ package copy import ( + "io/fs" "os" "syscall" ) -func preserveOwner(src, dest string, info fileInfo) (err error) { +func preserveOwner(src, dest string, info fs.FileInfo) (err error) { if info == nil { if info, err = os.Stat(src); err != nil { return err diff --git a/preserve_owner_x.go b/preserve_owner_x.go index 9d82574..d6a6148 100644 --- a/preserve_owner_x.go +++ b/preserve_owner_x.go @@ -3,6 +3,8 @@ package copy -func preserveOwner(src, dest string, info fileInfo) (err error) { +import "io/fs" + +func preserveOwner(src, dest string, info fs.FileInfo) (err error) { return nil }