From eb058795cb5ebba43e2a0a33f540bbc2c37945c4 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 20 Apr 2023 11:19:04 -0700 Subject: [PATCH] Fix Darwin tests Signed-off-by: Derek McGowan --- fs/copy_unix.go | 5 +++++ fs/copy_unix_test.go | 11 +++++++---- fs/du_test.go | 26 +++++++++++++++----------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/fs/copy_unix.go b/fs/copy_unix.go index 0e68ba9e..dd957872 100644 --- a/fs/copy_unix.go +++ b/fs/copy_unix.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "os" + "runtime" "syscall" "github.com/containerd/continuity/sysx" @@ -71,6 +72,10 @@ func copyFileContent(dst, src *os.File) error { func copyXAttrs(dst, src string, excludes map[string]struct{}, errorHandler XAttrErrorHandler) error { xattrKeys, err := sysx.LListxattr(src) if err != nil { + if os.IsPermission(err) && runtime.GOOS == "darwin" { + // On darwin, character devices do not permit listing xattrs + return nil + } e := fmt.Errorf("failed to list xattrs on %s: %w", src, err) if errorHandler != nil { e = errorHandler(dst, src, "", e) diff --git a/fs/copy_unix_test.go b/fs/copy_unix_test.go index d4a02038..69eb2d52 100644 --- a/fs/copy_unix_test.go +++ b/fs/copy_unix_test.go @@ -22,6 +22,7 @@ package fs import ( "os" "path/filepath" + "runtime" "syscall" "testing" @@ -89,11 +90,13 @@ func TestCopyIrregular(t *testing.T) { t.Fatal(err) } prepared++ - f2Socket := filepath.Join(src, "f2.sock") - if err := unix.Mknod(f2Socket, 0o600|unix.S_IFSOCK, 0); err != nil { - t.Fatal(err) + if runtime.GOOS != "darwin" { + f2Socket := filepath.Join(src, "f2.sock") + if err := unix.Mknod(f2Socket, 0o600|unix.S_IFSOCK, 0); err != nil { + t.Fatal(err) + } + prepared++ } - prepared++ f3Dev := filepath.Join(src, "f3.dev") if err := unix.Mknod(f3Dev, 0o600|unix.S_IFCHR, 42); err != nil { t.Logf("skipping testing S_IFCHR: %v", err) diff --git a/fs/du_test.go b/fs/du_test.go index 4744df01..9839a577 100644 --- a/fs/du_test.go +++ b/fs/du_test.go @@ -73,17 +73,6 @@ func TestUsage(t *testing.T) { } if runtime.GOOS != "windows" { testCases = append(testCases, []testCase{ - { - name: "SparseFiles", - fs: fstest.Apply( - fstest.CreateDir("/dir", 0o755), - fstest.CreateRandomFile("/dir/file1", 7, 5, 0o644), - createSparseFile("/dir/sparse1", 8, 0o644, 5, 1024*1024, 5), - createSparseFile("/dir/sparse2", 9, 0o644, 0, 1024*1024), - createSparseFile("/dir/sparse2", 10, 0o644, 0, 1024*1024*1024, 1024), - ), - size: dirs(2) + align(5)*3 + align(1024), - }, { name: "Hardlinks", fs: fstest.Apply( @@ -104,6 +93,21 @@ func TestUsage(t *testing.T) { }, }...) } + if runtime.GOOS != "windows" && runtime.GOOS != "darwin" { + testCases = append(testCases, []testCase{ + { + name: "SparseFiles", + fs: fstest.Apply( + fstest.CreateDir("/dir", 0o755), + fstest.CreateRandomFile("/dir/file1", 7, 5, 0o644), + createSparseFile("/dir/sparse1", 8, 0o644, 5, 1024*1024, 5), + createSparseFile("/dir/sparse2", 9, 0o644, 0, 1024*1024), + createSparseFile("/dir/sparse2", 10, 0o644, 0, 1024*1024*1024, 1024), + ), + size: dirs(2) + align(5)*3 + align(1024), + }, + }...) + } for i := range testCases { tc := testCases[i]