From c23c0f7c1458cee72ea4ba0967f264739579d533 Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Thu, 31 Mar 2022 22:30:45 +0200 Subject: [PATCH] Cast unix.Statfs_t.Type to int64 when checking for btrfs Fixes #3687. Uses the cast suggested by @MichaelEischer, except that the contant isn't cast along, because it's untyped and will be converted by the compiler as necessary. --- internal/fs/setflags_linux_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/fs/setflags_linux_test.go b/internal/fs/setflags_linux_test.go index 7818146ac..089b7c615 100644 --- a/internal/fs/setflags_linux_test.go +++ b/internal/fs/setflags_linux_test.go @@ -59,9 +59,13 @@ func supportsNoatime(t *testing.T, f *os.File) bool { err := unix.Fstatfs(int(f.Fd()), &fsinfo) rtest.OK(t, err) - return fsinfo.Type == unix.BTRFS_SUPER_MAGIC || - fsinfo.Type == unix.EXT2_SUPER_MAGIC || - fsinfo.Type == unix.EXT3_SUPER_MAGIC || - fsinfo.Type == unix.EXT4_SUPER_MAGIC || - fsinfo.Type == unix.TMPFS_MAGIC + // The funky cast works around a compiler error on 32-bit archs: + // "unix.BTRFS_SUPER_MAGIC (untyped int constant 2435016766) overflows int32". + // https://github.com/golang/go/issues/52061 + typ := int64(uint(fsinfo.Type)) + return typ == unix.BTRFS_SUPER_MAGIC || + typ == unix.EXT2_SUPER_MAGIC || + typ == unix.EXT3_SUPER_MAGIC || + typ == unix.EXT4_SUPER_MAGIC || + typ == unix.TMPFS_MAGIC }