Skip to content

Commit eb05879

Browse files
committed
Fix Darwin tests
Signed-off-by: Derek McGowan <[email protected]>
1 parent 9cd17be commit eb05879

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

fs/copy_unix.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"io"
2525
"os"
26+
"runtime"
2627
"syscall"
2728

2829
"github.com/containerd/continuity/sysx"
@@ -71,6 +72,10 @@ func copyFileContent(dst, src *os.File) error {
7172
func copyXAttrs(dst, src string, excludes map[string]struct{}, errorHandler XAttrErrorHandler) error {
7273
xattrKeys, err := sysx.LListxattr(src)
7374
if err != nil {
75+
if os.IsPermission(err) && runtime.GOOS == "darwin" {
76+
// On darwin, character devices do not permit listing xattrs
77+
return nil
78+
}
7479
e := fmt.Errorf("failed to list xattrs on %s: %w", src, err)
7580
if errorHandler != nil {
7681
e = errorHandler(dst, src, "", e)

fs/copy_unix_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package fs
2222
import (
2323
"os"
2424
"path/filepath"
25+
"runtime"
2526
"syscall"
2627
"testing"
2728

@@ -89,11 +90,13 @@ func TestCopyIrregular(t *testing.T) {
8990
t.Fatal(err)
9091
}
9192
prepared++
92-
f2Socket := filepath.Join(src, "f2.sock")
93-
if err := unix.Mknod(f2Socket, 0o600|unix.S_IFSOCK, 0); err != nil {
94-
t.Fatal(err)
93+
if runtime.GOOS != "darwin" {
94+
f2Socket := filepath.Join(src, "f2.sock")
95+
if err := unix.Mknod(f2Socket, 0o600|unix.S_IFSOCK, 0); err != nil {
96+
t.Fatal(err)
97+
}
98+
prepared++
9599
}
96-
prepared++
97100
f3Dev := filepath.Join(src, "f3.dev")
98101
if err := unix.Mknod(f3Dev, 0o600|unix.S_IFCHR, 42); err != nil {
99102
t.Logf("skipping testing S_IFCHR: %v", err)

fs/du_test.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,6 @@ func TestUsage(t *testing.T) {
7373
}
7474
if runtime.GOOS != "windows" {
7575
testCases = append(testCases, []testCase{
76-
{
77-
name: "SparseFiles",
78-
fs: fstest.Apply(
79-
fstest.CreateDir("/dir", 0o755),
80-
fstest.CreateRandomFile("/dir/file1", 7, 5, 0o644),
81-
createSparseFile("/dir/sparse1", 8, 0o644, 5, 1024*1024, 5),
82-
createSparseFile("/dir/sparse2", 9, 0o644, 0, 1024*1024),
83-
createSparseFile("/dir/sparse2", 10, 0o644, 0, 1024*1024*1024, 1024),
84-
),
85-
size: dirs(2) + align(5)*3 + align(1024),
86-
},
8776
{
8877
name: "Hardlinks",
8978
fs: fstest.Apply(
@@ -104,6 +93,21 @@ func TestUsage(t *testing.T) {
10493
},
10594
}...)
10695
}
96+
if runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
97+
testCases = append(testCases, []testCase{
98+
{
99+
name: "SparseFiles",
100+
fs: fstest.Apply(
101+
fstest.CreateDir("/dir", 0o755),
102+
fstest.CreateRandomFile("/dir/file1", 7, 5, 0o644),
103+
createSparseFile("/dir/sparse1", 8, 0o644, 5, 1024*1024, 5),
104+
createSparseFile("/dir/sparse2", 9, 0o644, 0, 1024*1024),
105+
createSparseFile("/dir/sparse2", 10, 0o644, 0, 1024*1024*1024, 1024),
106+
),
107+
size: dirs(2) + align(5)*3 + align(1024),
108+
},
109+
}...)
110+
}
107111

108112
for i := range testCases {
109113
tc := testCases[i]

0 commit comments

Comments
 (0)