Skip to content

Commit

Permalink
Fix Darwin tests
Browse files Browse the repository at this point in the history
Signed-off-by: Derek McGowan <[email protected]>
  • Loading branch information
dmcgowan committed Apr 21, 2023
1 parent 9cd17be commit eb05879
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
5 changes: 5 additions & 0 deletions fs/copy_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"io"
"os"
"runtime"
"syscall"

"github.com/containerd/continuity/sysx"
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions fs/copy_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package fs
import (
"os"
"path/filepath"
"runtime"
"syscall"
"testing"

Expand Down Expand Up @@ -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)
Expand Down
26 changes: 15 additions & 11 deletions fs/du_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]
Expand Down

0 comments on commit eb05879

Please sign in to comment.