Skip to content

Commit 853fa6a

Browse files
kaovilaiclaude
andcommitted
Refactor xattr error handler to be a simple function
Changed ignoreSELinuxXAttrErrorHandler from a function that returns a function to a direct error handler function. This simplifies the code while maintaining the same functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Tiger Kaovilai <[email protected]>
1 parent 42aefa6 commit 853fa6a

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

solver/llbsolver/ops/exec_binfmt.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (m *staticEmulatorMount) Mount() ([]mount.Mount, func() error, error) {
6565
if err := copy.Copy(context.TODO(), filepath.Dir(m.path), filepath.Base(m.path), tmpdir, qemuMountName, func(ci *copy.CopyInfo) {
6666
m := 0555
6767
ci.Mode = &m
68-
}, copy.WithChown(uid, gid), copy.WithXAttrErrorHandler(createSELinuxXAttrErrorHandler())); err != nil {
68+
}, copy.WithChown(uid, gid), copy.WithXAttrErrorHandler(ignoreSELinuxXAttrErrorHandler)); err != nil {
6969
return nil, nil, err
7070
}
7171

@@ -125,21 +125,19 @@ func getEmulator(ctx context.Context, p *pb.Platform) (*emulator, error) {
125125
return &emulator{path: fn}, nil
126126
}
127127

128-
// createSELinuxXAttrErrorHandler creates an error handler for xattr copy operations
128+
// ignoreSELinuxXAttrErrorHandler is an error handler for xattr copy operations
129129
// that specifically ignores ENOTSUP errors for security.selinux extended attributes.
130130
// This addresses SELinux compatibility issues where copying files to filesystems that
131131
// don't support SELinux xattrs (like tmpfs) would fail with ENOTSUP, preventing
132132
// qemu emulator setup on SELinux-enabled systems. Since the security.selinux xattr
133133
// is not critical for the emulator functionality, we safely ignore these errors
134134
// while preserving other xattr error handling.
135-
func createSELinuxXAttrErrorHandler() func(dst, src, xattrKey string, err error) error {
136-
return func(dst, src, xattrKey string, err error) error {
137-
// Ignore ENOTSUP errors specifically for security.selinux xattr
138-
// This allows qemu emulator setup to succeed on SELinux systems
139-
// when copying to filesystems that don't support SELinux xattrs
140-
if errors.Is(err, syscall.ENOTSUP) && xattrKey == "security.selinux" {
141-
return nil
142-
}
143-
return err
135+
func ignoreSELinuxXAttrErrorHandler(dst, src, xattrKey string, err error) error {
136+
// Ignore ENOTSUP errors specifically for security.selinux xattr
137+
// This allows qemu emulator setup to succeed on SELinux systems
138+
// when copying to filesystems that don't support SELinux xattrs
139+
if errors.Is(err, syscall.ENOTSUP) && xattrKey == "security.selinux" {
140+
return nil
144141
}
142+
return err
145143
}

solver/llbsolver/ops/exec_binfmt_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
)
1010

1111
func TestBinfmtXAttrErrorHandler(t *testing.T) {
12-
handler := createSELinuxXAttrErrorHandler()
13-
1412
tests := []struct {
1513
name string
1614
dst string
@@ -80,7 +78,7 @@ func TestBinfmtXAttrErrorHandler(t *testing.T) {
8078
t.Run(tt.name, func(t *testing.T) {
8179
t.Parallel()
8280

83-
result := handler(tt.dst, tt.src, tt.xattrKey, tt.inputErr)
81+
result := ignoreSELinuxXAttrErrorHandler(tt.dst, tt.src, tt.xattrKey, tt.inputErr)
8482

8583
if tt.expectErr {
8684
require.Error(t, result, tt.description)

0 commit comments

Comments
 (0)