treewide: replace error assertions with errors.As
Change-Id: I369cc1dd8f745203f6f24093049d60d971acdf11
Reviewed-on: https://review.monogon.dev/c/monogon/+/3038
Reviewed-by: Serge Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/pkg/loop/loop.go b/metropolis/pkg/loop/loop.go
index a4974a8..a8be907 100644
--- a/metropolis/pkg/loop/loop.go
+++ b/metropolis/pkg/loop/loop.go
@@ -150,11 +150,10 @@
return nil, fmt.Errorf("failed to allocate loop device: %w", os.NewSyscallError("ioctl(LOOP_CTL_GET_FREE)", errno))
}
dev, err := os.OpenFile(fmt.Sprintf("/dev/loop%v", devNum), os.O_RDWR|os.O_EXCL, 0)
- if pe, ok := err.(*os.PathError); ok {
- if pe.Err == unix.EBUSY {
- // We have lost the race, get a new device
- continue
- }
+ var pe *os.PathError
+ if errors.As(err, &pe) && errors.Is(pe.Err, unix.EBUSY) {
+ // We have lost the race, get a new device
+ continue
}
if err != nil {
return nil, fmt.Errorf("failed to open newly-allocated loop device: %w", err)